xxxxxxxxxx
82
// Starter Code for "Embedded Iteration + Randomness"
var boolDoRefresh;
let width = 640;
let color = 20;
let alpha = 5;
function setup() {
createCanvas(width, width);
boolDoRefresh = true;
}
function draw() {
if (boolDoRefresh) {
background(200,200,0);
//base forest
for (i=0; i<width; i+=10) {
drawTrees(random(0,640), i, 450, color, alpha);
drawTrees(random(0,640), i, 100, color+150, alpha);
}
//top forest
for (i=0;i<width;i+=40) {
drawCircles(i,random(0,640), random(200), color, alpha);
}
boolDoRefresh = false;
}
}
function drawCircles(x,y,d, color, alpha) {
noStroke();
fill(color+255,color+(random(255)),color,alpha);
ellipse(x,y,d);
if (d>10) {
drawCircles(x, y+d*.05, d*.5, color, alpha+5);
drawCircles(x, y-d*.05, d*.5, color, alpha+5);
//drawCircles(x-d*0.5, y-5, d*.5, color, alpha);
}
}
function drawTrees(x,y,d, color, alpha) {
noStroke();
fill(color,color+20,color,alpha);
ellipse(x,y,d);
if (d>2) {
drawTrees(x+ d*0.5, y, d*.5, color, alpha+5);
drawTrees(x- d*0.5, y, d*.5, color, alpha+5);
drawCircles(x- d*0.5, y, d*.5, color-255, alpha+5);
}
}
function drawRoad() {
stroke(0,0,0,80);
strokeWeight(10);
noFill();
//line(random(5,10), random(5,10), random(300,600), random(300, 600));
let x = mouseX;
let y = mouseY;
bezier(0,100,250,150,x+random(-10,10),y+random(-10,10),600,700);
translate(x,y);
bezier(300,600,20,90,x,y,600,10);
}
function drawRect() {
noFill();
stroke(255);
strokeWeight(1);
rect(random(540), random(640), random(50,100), random(50,100));
}
function mousePressed() {
boolDoRefresh = true;
}