leaf arrangement by golden ratio
@author
color[] colors = {color(25, 25, 112),
color(199, 21, 133),
color(255, 255, 0),
color(220, 20, 60)};
float[] cStep = {0.0, 0.3, 0.4, 1.0};
void setup(){
size(500, 500);
noStroke();
fill(255);
}
void draw(){
background(0);
translate(width / 2, height / 2);
float angle = 0;
for(float v = 0.001; v < 1.0; v += 0.001){
float r = map(sqrt(v), 0, 1, 0, 220);
angle += TWO_PI * ((sqrt(5) - 1) / 2);
fill(getColor(v));
ellipse(r * cos(angle), r * sin(angle), 7, 7);
}
}
color getColor(float v){
for(int i = 0; i < colors.length - 1; i++){
if(cStep[i] <= v && v <= cStep[i + 1]){
return color(map(v, cStep[i], cStep[i + 1], red(colors[i]), red(colors[i + 1])),
map(v, cStep[i], cStep[i + 1], green(colors[i]), green(colors[i + 1])),
map(v, cStep[i], cStep[i + 1], blue(colors[i]), blue(colors[i + 1])));
}
}
return 0;
}