Created
May 30, 2017 18:37
-
-
Save JCGrant/94d010f4969972df9e371411d3e27f1b to your computer and use it in GitHub Desktop.
Drawing sunflowers with Processing
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
color petalColor = #FFC608; | |
color seedsColor = #2A1B12; | |
color stemColor = #6C7D36; | |
color backgroundColor = #89B4EA; | |
void setup() { | |
size(1920, 1080); | |
frameRate(5); | |
background(backgroundColor); | |
} | |
void draw() { | |
float smallerLength = min(width, height); | |
drawSunflower(random(width), random(height), random(smallerLength / 10, smallerLength / 5)); | |
} | |
void drawPetal(float r, float size) { | |
rotate(r); | |
bezier( | |
0, 0, | |
0 + size, 0 + size / 2, | |
0 + size, 0 - size / 2, | |
0, 0 | |
); | |
} | |
void drawSunflower(float x, float y, float size) { | |
translate(x, y); | |
stroke(0); | |
fill(stemColor); | |
float stemWidth = size / 5; | |
rect(-stemWidth / 2, 0, stemWidth, height); | |
fill(petalColor); | |
float petalLength = size * 1.5; | |
for (float i = 0; i < TWO_PI; i += TWO_PI / 16) { | |
drawPetal(i, petalLength); | |
} | |
fill(seedsColor); | |
float seedsRadius = size; | |
ellipse(0, 0, seedsRadius, seedsRadius); | |
resetMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment