-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
53 lines (40 loc) · 887 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
44
45
46
47
48
49
50
51
52
53
var car, carImage;
var speed, weight;
function preload(){
carImage = ("unnamed.png");
}
function setup() {
createCanvas(1600,400);
speed = random(55,90);
weight = random(400, 1500);
car = createSprite(50, 200, 50, 50);
car.shapeColor = "black";
car.velocityX = speed;
wall = createSprite(1500, 200, 60, height/2);
wall.shapeColor = "black";
deformation = 0.5 * weight * speed * speed / 22500
}
function draw() {
background("lightCyan");
if (car.collide(wall)) {
if (deformation < 100 ){
car.shapeColor = "lime"
fill("lime");
textSize(200);
text("best !!",500, 250);
}
if (deformation > 100 && deformation < 180){
car.shapeColor = "yellow"
fill("yellow");
textSize(200);
text("average",500, 250);
}
if (deformation > 180){
car.shapeColor = "red"
fill("red");
textSize(200);
text("! worst !",500, 250);
}
}
drawSprites();
}