xxxxxxxxxx
97
// Parameter
let coloured = false; // Whether to see my first test (uncoloured) or second test (coloured)
// Global variable (not parameter, don't touch unless you wanna experiment)
let distance = 100;
// Functions
function setup() {
createCanvas(600, 600);
frameRate(20)
}
function draw() {
// My first test
if (!coloured) {
background(64);
noFill();
stroke(255);
translate(width/2, height/2);
line(-width, height, 0, 0)
line(width, height, 0, 0)
scale((100 - distance)/100);
circle(200, 0, 50);
rect(200-8, 20, 16, 100)
rect(-225, 0, 50, 150)
rect(-275, -100, 150, 100)
if (distance == 0) noLoop();
else distance--;
// if (distance > 0) distance--;
// My second test, but didn't finish it and test everything I wanted to, so it's just a coloured version of the first
} else {
background("lightblue");
noFill();
stroke(255);
translate(width/2, height/2);
// line(-width/2+100, height/2, -width/13.5, height/10)
// line(-width/2+100, height/2, 0, 0)
// line(width/2-100, height/2, width/13.5, height/10)
noStroke()
fill("#818a09")
rect(-width/2, height/10, width, height/2) // For cut road (more realistic, except that the ratio isn't right, so the objects don't follow it correctly)
// rect(-width/2, 0, width, height/2) // For pointed road
fill("#a06847")
beginShape(QUADS) // For cut road
vertex(-width/2+100, height/2)
vertex(width/2-100, height/2)
vertex(width/13.5, height/10)
vertex(-width/13.5, height/10)
endShape()
// triangle(-width/2+100, height/2, width/2-100, height/2, 0, 0) // For pointed road
// scale((150 - distance)/100);
scale(map(distance, 100, 0, 0, 0.9));
circle(200, 0, 50);
rect(200-8, 20, 16, 100)
noStroke()
fill(color(133,78,3))
rect(-250, 0, 50, 150)
fill(color(19,98,19))
rect(-300, -100, 150, 100)
if (distance == 0) noLoop();
else distance--;
// if (distance > 0) distance--;
}
}
function keyPressed() {
if (key === "r") distance = 100;
else coloured = !coloured;
loop();
}