xxxxxxxxxx
/* Pierre MARZIN 08/11/2019
Swingin trees simulation
*/
let trees=[];
let ntrees=1;
let maxgeneration=4;
let probbranch=.8;
let nmaxtotalbranches;
let nmaxleaves=20;
let nminleaves=10;
let branches;
let wind=0;
function setup() {
cnv=createCanvas(windowWidth, windowHeight);
init();
}
function init() {
nmaxtotalbranches=pow(maxgeneration,4);
branches=[];
for (let i=0; i<ntrees; i++) {
trees.push(new Tree(new p5.Vector((i+1)*width/(1+ntrees), .9*height-.3*height*(i%2))));
trees[i].display();
}
}
function draw() {
background(255);
let blow=map(mouseX-pmouseX,100,-100,-.3,.3);
wind+=.1*blow;
wind*=.95;
for (let i=0; i<trees.length; i++) {
trees[i].display();
}
}