diff --git a/index.html b/index.html index 097e70f..5de5fbb 100644 --- a/index.html +++ b/index.html @@ -25,14 +25,25 @@ - - + @@ -81,7 +95,7 @@
diff --git a/maze-solver.js b/maze-solver.js index e6c7254..0e84606 100644 --- a/maze-solver.js +++ b/maze-solver.js @@ -2,6 +2,9 @@ class MazeSolver { constructor(startingCell, targetCell, searchedColor = [210, 180, 140], finalPathColor = [173, 216, 230]){ this.frontier = []; this.explored = []; + + this.startingCellColor = [255, 0, 0]; + this.endingCellColor = [0, 0, 255]; this.finalPathColor = finalPathColor; this.targetCell = targetCell; this.startingCell = startingCell; @@ -20,8 +23,16 @@ class MazeSolver { highlightFinalPath(maze){ let tmp = this.explored.pop(); + tmp.color = this.endingCellColor; + + tmp = tmp.parent; + while(tmp != undefined){ tmp.color = this.finalPathColor; + + if(tmp.parent == undefined) + tmp.color = this.startingCellColor; + tmp = tmp.parent; } diff --git a/p5.min.js b/p5.min.js new file mode 100644 index 0000000..d5d9c0c --- /dev/null +++ b/p5.min.js @@ -0,0 +1,3 @@ +/*! p5.js v1.0.0 February 29, 2020 */ + +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).p5=e()}}(function(){return function o(a,s,l){function u(t,e){if(!s[t]){if(!a[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(h)return h(t,!0);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}var n=s[t]={exports:{}};a[t][0].call(n.exports,function(e){return u(a[t][1][e]||e)},n,n.exports,o,a,s,l)}return s[t].exports}for(var h="function"==typeof require&&require,e=0;e>>16,e[r+1]=(65280&t[i])>>>8,e[r+2]=255&t[i],e[r+3]=(4278190080&t[i])>>>24},O._toImageData=function(e){return e instanceof ImageData?e:e.getContext("2d").getImageData(0,0,e.width,e.height)},O._createImageData=function(e,t){return O._tmpCanvas=document.createElement("canvas"),O._tmpCtx=O._tmpCanvas.getContext("2d"),this._tmpCtx.createImageData(e,t)},O.apply=function(e,t,r){var i=e.getContext("2d"),n=i.getImageData(0,0,e.width,e.height),o=t(n,r);o instanceof ImageData?i.putImageData(o,0,0,0,0,e.width,e.height):i.putImageData(n,0,0,0,0,e.width,e.height)},O.threshold=function(e,t){var r=O._toPixels(e);void 0===t&&(t=.5);for(var i=Math.floor(255*t),n=0;n"),"0"!==o[0]){n.print("
"),n.print(""),n.print("");for(var h=0;h ")}for(var f=0;f