xxxxxxxxxx
// noise, noiseSeed, pi, for loop, text, sin, cos
// mouseX, map, degrees, translate, rotate, pushMatrix, popMatrix, float
// Move the cursor gently left/right to change the breeze.
// Constructed using the code from 1 half of a tree.
float incr1;
float incr2;
float limit;
float h;
void setup() {
size(800, 675);
colorMode(HSB, 360, 100, 100, 100);
noiseSeed(98);
smooth();
incr2 = TWO_PI/100;
h = random(360);
}
void draw() {
background(20);
h += .1;
h = h % 360;
limit = map(mouseX, 0, width, PI/12, PI/7);
fill(350);
text(round(degrees(limit)), 15, 15);
incr1 += 0.001;
for (float r = incr2; r < TWO_PI; r += incr2 ) { // r = 0; in Java (rounding issue?)
float ns = noise(incr1+r);
float rads = map(ns, 0, 1, -limit, limit);
float x = width/2 + (60 * cos(r));
float y = height/2 + (60 * sin(r));
float sw = 0;
if (rads <= 0) sw = map(rads, 0, -limit/3, 2, 0.1);
else sw = map(rads, 0, limit/3, 2, 0.1) ;
strokeWeight(abs(sw));
float s = map(ns, 0, 1, 20, 100);
float b = map(ns, 0, 1, 80, 100);
stroke(h, s, b );
pushMatrix();
translate(x, y);
rotate(r + PI/2);
arm(30, rads);
popMatrix();
}
}
// 1 half of a tree
void arm(float len, float rds) {
if (len > 5) {
line(0, 0, 0, -len);
translate(0, -len);
rotate(rds);
arm(len*.9, rds);
}
}