Skip to content

Instantly share code, notes, and snippets.

@Morpholux
Created April 11, 2020 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Morpholux/9cdb1ba4c266318bde8f53939f3e5c8a to your computer and use it in GitHub Desktop.
Save Morpholux/9cdb1ba4c266318bde8f53939f3e5c8a to your computer and use it in GitHub Desktop.
How to manage creation of a curved close figure, without any apparent joint in segments connection
// renaud.jean-francois(arobas)uqam(point)ca
// Syntaxe Processing version 3.5.4
// samedi, 11 avril 2020
int nbSegments = 3; //at least three segments
PVector [] pts = new PVector[nbSegments];
void setup() {
size(600, 600);
background(0);
noFill();
stroke(255);
noLoop();
smooth(8);
for (int i = 0; i< pts.length; i++) {
pts[i] = new PVector(random(100, 500), random(100, 500), 0);
}
}
void draw() {
background(0);
// Drawing the shape with curveVertex()
beginShape();
curveVertex(pts[nbSegments-1].x, pts[nbSegments-1].y); // first handle
curveVertex(pts[0].x, pts[0].y); // first anchor
for (int i = 1; i< pts.length; i++) { // loop start at second point
curveVertex(pts[i].x, pts[i].y);
}
curveVertex(pts[0].x, pts[0].y); // last anchor
curveVertex(pts[1].x, pts[1].y); // last handle
endShape();
// To show curvePoint along path of the whole figure
for (int i = 0; i < nbSegments; i++) {
int nbSteps = 10;
for (int n = 0; n < nbSteps; n++) {
float t = n / float(nbSteps);
float x = curvePoint(pts[i%nbSegments].x, pts[(i+1)%nbSegments].x, pts[(i+2)%nbSegments].x, pts[(i+3)%nbSegments].x, t);
float y = curvePoint(pts[i%nbSegments].y, pts[(i+1)%nbSegments].y, pts[(i+2)%nbSegments].y, pts[(i+3)%nbSegments].y, t);
ellipse(x, y, 5, 5);
}
}
}
void mousePressed() {
for (int i = 0; i< pts.length; i++) {
pts[i] = new PVector(random(100, 500), random(100, 500), 0);
}
redraw();
}
@Morpholux
Copy link
Author

Capture d’écran 2020-04-11 à 15 01 41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment