/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.$F5LeZagyYT/rev.925
*
* authors:
* Joel Drake
*
*
* Gregg Blanchard
*
*
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
size(800,800);
int iterations = ceil(random(10));
int[] startx = new int[iterations];
int[] treex = new int[iterations];
int[] stepsize = new int[iterations];
for (int i=0; i<iterations; i=i+1) {
startx[i] = -150*i;
}
for (int i=0; i<iterations; i=i+1) {
treex[i] = 150*i+300;
}
for (int i=0; i<iterations; i=i+1) {
stepsize[i] = ceil(random(3));
}
function drawcar(x,y) {
pushStyle();
fill(#000000);
ellipse(150+x,150+y,100,100);
ellipse(350+x,150+y,100,100);
carfill = color(floor((x+500)*255/width),floor((width-x)*255/width),0);
fill(carfill);
beginShape();
vertex(x,150+y);
vertex(500+x,150+y);
vertex(400+x,50+y);
vertex(350+x,50+y);
vertex(300+x,0+y);
vertex(200+x,0+y);
vertex(150+x,50+y);
vertex(90+x,50+y);
vertex(x,150+y);
endShape(CLOSE);
fill(#123456);
triangle(300+x,50+y,300+x,10+y,340+x,50+y);
rect(210+x,10+y,80,40);
triangle(160+x,50+y,200+x,10+y,200+x,50+y);
popStyle();
}
function drawtree(x,y) {
yy = y + 50;
yyy = y+100;
yyyy = y + 100;
fill(#bb6600);
rect(x+75,yyyy,50,75);
fill(#00aa00);
triangle(x,yyy,x+100,yyy-150,x+200,yyy);
triangle(x,yy,x+100,yy-150,x+200,yy);
triangle(x,y,x+100,y-150,x+200,y);
}
int bob = 0;
void mouseClicked() {
bob = mouseX;
for(int i=0;i<iterations;i=i+1) {
stepsize[i] = mouseX/(30*i);
}
}
void drawstate(x,y) {
fill(255,255,255);
if(x < width-150) {
text("speed variable:" + bob,x,y);
} else {
text("speed variable:" + bob, width-150,y);
}
}
void draw() {
background(#123456);
text("clicking to the right speeds things up, clicking to the left slows things down.",20,20);
drawstate(bob,40);
for(var i=0;i<iterations;i=i+1) {
drawcar(startx[i], 200+45*i);
startx[i] = startx[i] + stepsize[i];
if(startx[i] > width) {
startx[i] = -600;
}
drawtree(treex[i],200+45*i);
treex[i] = treex[i] - stepsize[i];
if(treex[i]+400 < 0) {
treex[i] = width+150*i;
}
}
}