xxxxxxxxxx
56
var direction = 0;
var length = 0;
var x3;
var y3;
let colors,g,close,left,right;
let lastLeft = 0;
let lastRight = 0;
function tree(x){
colors = [color(56,20,96),color(250,218,94),color(255,0,0),color(51,165,50),color(82,219),color(106,13,173),color(255,127,0),color(0,100,0),color(17,30,108)];
g = createGraphics(windowWidth,windowHeight);
g.push();
g.stroke(0,0,0);
close = random(100);
if(x > 0){
left = random(40,60);
g.translate(left + lastLeft,windowHeight - close);
lastLeft = left * 10;
}else{
right = random(40,60);
g.translate(windowWidth - right- lastRight,windowHeight - close);
lastRight = right * 10;
}
g.scale(1,-1)
angleMode(DEGREES);
drawTree(0,0,90,10);
g.pop();
return g;
}
function drawTree(x1,y1,direction,length) {
if (length !== 0){
var x2 = x1 + (random(0.3,0.75) * length * map(close, 100, 0, 10, 15) * cos(direction));
var y2 = y1 + (random(0.3,0.75) * length * map(close, 100, 0, 10, 15) * sin(direction));
g.stroke(133,94,66);
g.strokeWeight(0.5 * length);
g.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);
g.stroke(0,0,0);
g.strokeWeight(0.5);
g.fill(c);
//g.line(x3,y3,x3,y3-r/2);
g.circle(x3,y3,6);
}
}