xxxxxxxxxx
58
let g;
function setup() {
createCanvas(windowWidth, windowHeight);
g = createGraphics(windowWidth, windowHeight);
background(255,255,255);
tree(50,height);
tree(width-50,height);
}
function draw(){
}
var direction = 0;
var length = 0;
var x3;
var y3;
let colors;
function tree(x,y){
colors = [color(56,20,96),color(250,218,94),color(255,0,0),color(51,165,50),color(82,219,255),color(106,13,173),color(255,127,0),color(0,100,0),color(17,30,108)];
g.push();
g.translate(x,y);
g.scale(1,-1)
angleMode(DEGREES);
drawTree(0,0,90,10);
g.pop();
}
function drawTree(x1,y1,direction,length) {
if(length !== 0){
var x2 = x1 + (0.0005 * windowWidth * length * random(15,20) * cos(direction));
var y2 = y1 + (0.0005 * windowWidth * length * random(15,20) * sin(direction));
stroke(133,94,66);
strokeWeight(0.0006 * windowWidth * length);
line(x1,y1,x2,y2);
x3 = x2;
y3 = y2;
drawTree(x2,y2,direction-random(10,40),length-1);
drawTree(x2,y2,direction+random(10,40),length-1);
} else if(Math.round(random(40)) == 1){
let c = random(colors);
let r = random(5,15);
stroke(0,0,0);
strokeWeight(0.5)
fill(c);
line(x3,y3,x3,y3-r);
circle(x3,y3-r,5);
}
}