-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
44 lines (38 loc) · 956 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
let grid;
let skyline;
let showHide = false;
let paused;
let cols = 100;
let rows = 75;
let flashFrame = 0;
let prob_of_wall = 0.4;
function setup() {
createCanvas(800, 800);
grid = new Grid(cols, rows, width, 600, prob_of_wall);
grid.setStartNode(floor(random(0, cols)), 0);
grid.setEndNode(floor(random(0 + (cols * 0.2), cols - (cols * 0.2))), rows - 1);
grid.initialise();
skyline = new Skyline(width, 200);
skyline.addTallest(grid.endNode.x);
}
function draw() {
backgroundGradient(color(13, 13, 23), color(255, 255, 255));
grid.render(showHide);
skyline.render();
grid.aStarStep();
}
function backgroundGradient(c1, c2) {
noFill();
for (let y = 0; y < height; y++) {
let interp = map(y, 0, height, 0, 1);
let c = lerpColor(c1, c2, interp);
stroke(c);
line(0, y, width, y);
}
}
function flash() {
if (flashFrame == 0 || flashFrame == 2 || flashFrame == 4) {
background(255);
}
flashFrame++;
}