xxxxxxxxxx
47
var x = 0, y = 0;
function setup() {
createCanvas(400, 400);
background('#D9DEE2');
}
function draw() {
for(var i = 0; i < 500; i++){
var px = map(x, -3, +3, 0, width);
var py = map(y, 0, 10, height, 20);
point(px, py);
calculateNext();
}
if(frameCount > 150){
noLoop();
}
}
function calculateNext(){
var xNew, yNew;
var r = random(1);
if (r < 0.01) {
// 1
stroke('#5EBA7D');
xNew = 0;
yNew = 0.16 * y;
} else if (r < 0.86) {
// 2
stroke('#5EBA7D');
xNew = 0.85 * x + 0.04 * y;
yNew = -0.04 * x + 0.85 * y + 1.6;
} else if (r < 0.93) {
// 3
stroke('#44A063');
xNew = 0.1 * x + -0.26 * y;
yNew = 0.23 * x + 0.22 * y + 1.6;
} else {
// 4
stroke('#44A063');
xNew = -0.1 * x + 0.28 * y;
yNew = 0.26 * x + 0.24 * y + 0.44;
}
x = xNew;
y = yNew;
}