-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
43 lines (33 loc) · 881 Bytes
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var car, wall, road;
var speed, weight;
function setup() {
createCanvas(1440,400);
speed = random(55, 90);
weight = random(400, 1500);
car = createSprite(500, 200, 50, 50);
car.velocityX = speed;
wall = createSprite(1380, 200, 60, height/2);
wall.shapeColor = color(0, 0, 255)
road = createSprite(720, 200, 1440, 200);
road.shapeColor = color(0);
}
function draw() {
background(21, 114, 73);
car.depth = road.depth+1;
wall.depth = car.depth;
if (wall.x-car.x < car.width+wall.width) {
car.velocityX = 0;
car.x = wall.x-55.5;
var deformation = 0.5*weight*speed*speed/22509
if (deformation>181) {
car.shapeColor = color(255,0,0);
}
if (deformation<180 && deformation>99) {
car.shapeColor = color(230,230,0);
}
if (deformation<100) {
car.shapeColor= color(0,255,0);
}
}
drawSprites();
}