aboutsummaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
Diffstat (limited to 'public')
-rw-r--r--public/maze.html11
-rw-r--r--public/maze.js88
-rw-r--r--public/maze.mml7
-rw-r--r--public/path.pml20
4 files changed, 126 insertions, 0 deletions
diff --git a/public/maze.html b/public/maze.html
new file mode 100644
index 0000000..d94c70e
--- /dev/null
+++ b/public/maze.html
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Maze</title>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.js"></script>
+ <script src="maze.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/public/maze.js b/public/maze.js
new file mode 100644
index 0000000..97452a5
--- /dev/null
+++ b/public/maze.js
@@ -0,0 +1,88 @@
+const scale = 10;
+let mml = null;
+let pml = null;
+
+function newmaze() {
+ fetch("/api/v0.1/maze", {method: "POST"}).then(function(resp) {
+ resp.text().then(function(text) {
+ let t = text.split("\n");
+ mml = t;
+ pml = null;
+ });
+ });
+}
+
+function newpath() {
+ fetch("/api/v0.1/path", {method: "POST"}).then(function(resp) {
+ fetch("/api/v0.1/path/valid").then(function(resp) {
+ resp.text().then(function(text) {
+ if(text.includes("true")) {
+ fetch("/api/v0.1/path").then(function(resp) {
+ resp.text().then(function(text) {
+ pml = text.split("\n");
+ });
+ });
+ }
+ });
+ });
+ });
+}
+
+function setup() {
+ fetch("/api/v0.1/maze").then(function(resp) {
+ resp.text().then(function(text) {
+ let t = text.split("\n");
+ const wh = t[0].split(" ");
+ createCanvas(wh[0] * scale + 50, wh[1] * scale + 50);
+ createButton("Generate Maze").mousePressed(newmaze);
+ createButton("Find Path").mousePressed(newpath);
+ mml = t;
+ });
+ });
+}
+
+function draw() {
+ if(mml) {
+ background(255);
+
+ stroke(0);
+ strokeWeight(1);
+ noFill();
+
+ let wh = mml[0].split(" ");
+ for(let col = 0; col < wh[0]; col++) {
+ for(let row = 0; row < wh[1]; row++) {
+ rect(col * scale, row * scale, scale, scale);
+ }
+ }
+
+ fill(0, 128, 0);
+ let start = mml[1].split(" ");
+ rect(start[0] * scale, start[1] * scale, scale, scale);
+
+ fill(128, 0, 0);
+ let target = mml[2].split(" ");
+ rect(target[0] * scale, target[1] * scale, scale, scale);
+
+ noStroke();
+ fill(0);
+
+ for(let b = 3; b < mml.length; b++) {
+ let blk = mml[b].split(" ");
+ rect(blk[0] * scale, blk[1] * scale, blk[2] * scale, blk[3] * scale);
+ }
+
+ if(pml) {
+ stroke(0);
+ strokeWeight(1);
+ fill(0, 0, 128);
+
+ for(let b = 0; b < pml.length; b++) {
+ let blk = pml[b].split(" ");
+ rect(blk[0] * scale, blk[1] * scale, scale, scale);
+ }
+ } else {
+ text("No path", 10, wh[1] * scale + 20);
+ }
+ }
+}
diff --git a/public/maze.mml b/public/maze.mml
new file mode 100644
index 0000000..d5399ab
--- /dev/null
+++ b/public/maze.mml
@@ -0,0 +1,7 @@
+40 30 width and height
+5 5 start
+20 20 end
+0 0 40 1 block
+0 0 1 30 block
+39 0 1 30 block
+0 29 40 1 block
diff --git a/public/path.pml b/public/path.pml
new file mode 100644
index 0000000..cb2898c
--- /dev/null
+++ b/public/path.pml
@@ -0,0 +1,20 @@
+6 6
+7 7
+8 8
+9 9
+10 10
+11 11
+12 12
+12 13
+12 14
+12 15
+13 15
+14 15
+15 15
+16 15
+17 15
+18 15
+18 16
+18 17
+18 18
+19 19