-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maze_Renderer.js
45 lines (37 loc) · 2.47 KB
/
Maze_Renderer.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
// 3:24 AM | Drawing Room
// For a simulation for testing for a robotics competition.
// Renders maze generated by a python script in the repo in Processing JS
var code = {0: "0", 1: "L", 2: "T", 3: "R", 4: "B", 5: "LT", 6: "TR", 7: "RB", 8: "LB", 9: "LTR", 10: "TRB", 11: "RBL", 12: "BLT", 13: "LR", 14: "TB", 15: "TRBL"};
var grid = [[5, 10, 5, 14, 2, 14, 14, 6, 9, 5, 14, 14, 2, 6, 12, 6], [8, 14, 7, 5, 7, 9, 5, 7, 13, 13, 9, 5, 7, 8, 6, 13], [5, 14, 14, 7, 5, 7, 13, 12, 4, 4, 7, 13, 5, 6, 13, 13], [1, 6, 5, 6, 1, 6, 8, 14, 14, 14, 14, 7, 13, 11, 8, 3], [11, 13, 13, 8, 7, 1, 14, 14, 6, 5, 14, 14, 7, 5, 14, 7], [5, 7, 8, 14, 6, 8, 14, 6, 8, 7, 5, 14, 14, 7, 5, 6], [13, 5, 14, 6, 8, 14, 6, 8, 14, 2, 7, 5, 2, 14, 7, 13], [13, 8, 6, 8, 14, 14, 4, 2, 6, 13, 12, 7, 8, 6, 12, 3], [8, 6, 13, 5, 6, 5, 6, 8, 7, 13, 5, 14, 6, 8, 6, 13], [5, 7, 13, 13, 13, 13, 8, 6, 5, 7, 13, 9, 13, 5, 7, 11], [13, 12, 3, 13, 13, 13, 9, 13, 8, 14, 7, 8, 4, 7, 5, 6], [1, 6, 11, 13, 13, 13, 13, 13, 5, 14, 14, 14, 14, 14, 7, 13], [13, 13, 5, 7, 8, 7, 13, 8, 4, 10, 5, 14, 14, 6, 5, 3], [13, 8, 4, 14, 14, 6, 1, 14, 6, 5, 7, 5, 6, 8, 7, 13], [1, 14, 14, 6, 12, 4, 7, 12, 7, 13, 5, 7, 8, 2, 10, 13], [11, 12, 14, 4, 14, 14, 14, 14, 14, 7, 8, 14, 10, 8, 14, 7]];
// @brief: This function takes in a code word like "LR" and makes lines according to it at the location x, y. The length of the lines would be as specified in length. Like here the lines would be made Left and Right
// code: string of variable length
// x, y: coordinates of a rectangle that would have its center at the intersection of L and T.
// length: side length of a rectangle or length of any one line
function drawLines(code, x, y, length){
if(code === "0"){
return;
}
for(var i = 0; i < code.length; i++){
if(code[i] === "L"){
line(x, y, x, y + length);
} else if(code[i] === "R"){
line(x + length, y, x + length, y + length);
} else if(code[i] === "T"){
line(x, y, x + length, y);
} else if(code[i] === "B"){
line(x, y + length, x + length, y + length);
}
}
}
// drawLines("", 100, 126, 27);
function renderMaze(grid, gridStartX, gridStartY, unitlength){
for(var i = 0; i < grid.length; i++){
for(var j = 0; j < grid[0].length; j++){
drawLines(code[grid[i][j]], gridStartX + unitlength * j, gridStartY + unitlength * i, unitlength);
}
}
}
smooth();
strokeCap(SQUARE);
strokeWeight(5);
renderMaze(grid, 30, 30, 33);