-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.js
108 lines (95 loc) · 2 KB
/
draw.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
document.getElementById("heading").innerText =
"Use clicks to draw walls. C - Cast/Uncast. Spacebar - Movement Method";
let drawing = false;
let currX, currY;
let casting = false;
let particle;
let xoff = 0;
let yoff = 124141;
let usingMouse = false;
let walls = [];
function setup() {
canv = createCanvas(window.innerWidth - 100, window.innerHeight - 150);
canv.id("myCanvas");
background(0);
walls.push(new Boundary(0, 0, 0, width));
walls.push(new Boundary(0, 0, width, 0));
walls.push(new Boundary(width, 0, width, height));
walls.push(new Boundary(width, height, 0, height));
particle = new Particle();
ray = new Ray(100, 200);
}
function mouseClicked() {
if (!usingMouse) {
if (drawing) {
walls[walls.length - 1] = new Boundary(
mouseX,
mouseY,
currX,
currY,
color(255, 255, 255),
10
);
drawing = false;
} else {
drawing = true;
currX = mouseX;
currY = mouseY;
walls.push(
new Boundary(
currX,
currY,
mouseX,
mouseY,
color(255, 255, 255, 50),
10
)
);
}
}
}
function keyPressed() {
if (keyCode == 67) {
casting = !casting;
}
if (casting) {
if (keyCode == 32) {
usingMouse = !usingMouse;
}
}
}
function draw() {
background(0);
for (wall of walls) {
wall.show();
}
if (casting) {
if (usingMouse) {
particle.update(mouseX, mouseY);
} else {
particle.update(noise(xoff) * width, noise(yoff) * height);
xoff += 0.005;
yoff += 0.005;
}
particle.show();
reqArr = particle.look(walls);
}
if (drawing) {
stroke(0, 0, 255, 100);
strokeWeight(10);
walls[walls.length - 1].b = createVector(mouseX, mouseY);
walls[walls.length - 1].w = 15;
}
usingMouse ? noCursor() : cursor(CROSS);
if (!casting) {
stroke(255, 255, 255, 25);
strokeWeight(1);
line(mouseX, 0, mouseX, height);
line(0, mouseY, width, mouseY);
}
// for (let i = 0; i < ends.length; i++) {
// stroke(255, 255, 255);
// strokeWeight(10);
// line(starts[i][0], starts[i][1], ends[i][0], ends[i][1]);
// }
}