-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsketch.js
More file actions
92 lines (87 loc) · 1.91 KB
/
sketch.js
File metadata and controls
92 lines (87 loc) · 1.91 KB
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
let walls = [];
let ray;
let particle;
let b = true,
c = false,
d = false,
reflect_flag = false;
let b1, b2, b3, b4;
let x1, y1;
function setup() {
createCanvas(windowWidth, windowHeight);
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));
b1 = createButton("Start Casting");
b2 = createButton("Heavy Mode");
b3 = createButton("Reset");
//b4 = createButton("Reflect\n (Beta)");
b1.position(19, 19);
b2.position(windowWidth - 130, windowHeight - 50);
b3.position(19, windowHeight - 50);
//b4.position(1200, 19);
b1.mousePressed(start_ray);
b2.mousePressed(start_heavy);
b3.mousePressed(reset);
//b4.mousePressed(reflect);
}
function reflect() {
reflect_flag = ~reflect_flag;
}
function start_heavy() {
if (c) {
c = ~c;
}
d = ~d;
particle = new Particle();
}
function start_ray() {
c = ~c;
d = false;
particle = new Particle();
}
function reset() {
createCanvas(windowWidth, windowHeight);
//b = true;
c = false;
reflect_flag = false;
//d = false;
walls = [];
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));
}
function draw() {
background(0);
stroke(255);
if (mouseIsPressed && b && !c && !d) {
x1 = mouseX;
y1 = mouseY;
b = false;
}
const x2 = mouseX;
const y2 = mouseY;
//line(x1,y1,x2,y2);
if (!mouseIsPressed && !b && !c && !d) {
b = true;
walls.push(new Boundary(x1, y1, x2, y2));
line(x1, y1, x2, y2);
}
if (mouseIsPressed && d) {
const x1 = mouseX,
y1 = mouseY,
x2 = pmouseX,
y2 = pmouseY;
walls.push(new Boundary(x1, y1, x2, y2));
line((x1, y1, x2, y2));
}
for (let wall of walls) {
wall.show();
}
if (c) {
particle.look(walls, reflect_flag);
particle.update(mouseX, mouseY);
}
}