Last active
June 5, 2018 11:00
-
-
Save fal-works/4cb0b60397465be47fbb3d8aec90cfbe to your computer and use it in GitHub Desktop.
Draws a random soft shape with curveVertex().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See also: | |
// https://forum.processing.org/one/topic/how-to-create-a-closed-spline-curve.html | |
float[] radiusArray; | |
void setup() { | |
size(600, 600); | |
noLoop(); | |
noStroke(); | |
fill(32); | |
final int resolution = 30; | |
radiusArray = new float[resolution]; | |
for (int i = 0; i < resolution; i++) { | |
radiusArray[i] = random(100, 120); | |
} | |
}; | |
void draw() { | |
background(248); | |
translate(width / 2, height / 2); | |
drawShape(radiusArray); | |
} | |
void drawShape(float[] radiusArray) { | |
int resolution = radiusArray.length; | |
beginShape(); | |
// Make the last three points the same as the first three. | |
for (int i = 0; i < resolution + 3; i++) { | |
int index = i % resolution; | |
float angle = ((float)i / resolution) * TWO_PI; | |
curveVertex( | |
radiusArray[index] * cos(angle), | |
radiusArray[index] * sin(angle) | |
); | |
} | |
endShape(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment