xxxxxxxxxx
55
const len = 110;
var angle;
var level = 0;
var stWeight = 4;
function setup(){
createCanvas(400, 400);
angle = 0;
}
function draw(){
background('#007FFC');
stWeight = 4;
level = 0;
strokeWeight(stWeight);
translate(width/2, height);
angle = map(sin(frameCount/20 + HALF_PI), -1, 1, PI/20, PI - PI/4);
branch(len);
}
function branch(len){
translate(0, -len);
stroke(level * 10, level * 20, level * 7);
line(0, 0, 0, len);
if(level < 10){
pushIX();
rotate(angle);
branch(len * 2/3);
popIX();
pushIX();
rotate(-angle);
branch(len * 2/3);
popIX();
}
}
function pushIX(){
push();
level ++;
stWeight -= 0.4;
strokeWeight(max(stWeight, 0.1));
}
function popIX(){
pop();
level --;
stWeight += 0.4;
strokeWeight(max(stWeight, 0.1));
}