-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
63 lines (49 loc) · 1.22 KB
/
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
54
55
56
57
58
59
60
61
let rayDegree = [0, 0.523599, 5.75959]
let rays = []
let lenRay = 50
let walls = []
let sensorLog = {}
function setup() {
createCanvas(800, 800);
// edge wall
walls.push(new Boundary(0,0,width,0))
walls.push(new Boundary(0,0,0,height))
walls.push(new Boundary(width,height,0,height))
walls.push(new Boundary(width,height,width,0))
// random wall
for (let i=0; i < 5;i++){
let ln = 200;
let x1 = random(ln/2,width-(ln/2));
let y1 = random(height-(ln/5));
let x2 = random(x1-ln,x1+ln);
let y2 = sqrt(sq(ln) - sq(x2-x1))+y1;
walls.push(new Boundary(x1,y1,x2,y2))
}
car = new Car(width/2, height/2, 20,2)
for (let i=0; i < rayDegree.length;i++){
rays.push(new Ray(rayDegree[i], lenRay, car, false));
}
}
function draw() {
background(0);
walls.forEach((wall)=>{
wall.show();
})
car.show()
// car.showTrack()
rays.forEach((ray)=>{
ray.show(walls, sensorLog);
})
if(sensorLog){
strokeWeight(3)
stroke(255,0,0)
let values = Object.values(sensorLog)
for(let i=0; i<values.length;i++){
point(values[i].x, values[i].y)
}
}
textSize(32);
strokeWeight(0)
fill(255)
text('Use WASD to control car movement', 10 , 30);
}