-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
45 lines (28 loc) · 707 Bytes
/
sketch.js
File metadata and controls
45 lines (28 loc) · 707 Bytes
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
44
45
var car,wall;
var speed,weight;
function setup() {
createCanvas(800,400);
speed = random(50,90);
weight = random(400,1500);
car = createSprite(50,200,50,50);
car.velocityX = speed;
wall = createSprite(750,300,20,400);
wall.shapecolor = color(80,80,80)
}
function draw() {
background(0,0,0);
if (wall.x-car.x < (car.width+wall.width)/2){
car.velocityX = 0;
var deformation = 0.5 * weight * speed * speed/22509;
if (deformation> 180){
car.shapecolor = "red"
}
if (deformation<180 && deformation>100){
car.shapecolor = "green"
}
if (deformation<100){
car.shapecolor = "yellow"
}
}
drawSprites();
}