-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
44 lines (28 loc) · 733 Bytes
/
sketch.js
File metadata and controls
44 lines (28 loc) · 733 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
var car,wall;
var speed,weight;
function setup() {
createCanvas(800,400);
createSprite(400, 200, 50, 50);
speed = random(55,90);
weight = random(400,1500);
car = createSprite(50,200,50,50);
wall = createSprite(780,400,20,20);
}
function draw() {
background(0,0,0);
car.velocityX = speed;
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 = color (255,0,0);
}
if (deformation<180 && deformation>100){
car.shapecolor = color (230,230,0);
}
if (deformation<100){
car.shapecolor = color (0,255,0);
}
}
drawSprites();
}