@@ -4,6 +4,7 @@ import { dijkstra, aStarManhattan, aStarDiagonal, aStarEuclidean, depthFirstSear
44import { recursiveDivision , randomMaze , randomWeightedMaze , prims , dfsMaze , binaryTreeMaze , terrainMap , fileReaderTerrain } from "./graph_components/mazeAlgorithms" ;
55
66import { useState , useEffect , useRef } from "react" ;
7+ import { Link } from "react-router-dom" ;
78
89import { Node } from './graph_components/Node' ;
910import Webcam from "react-webcam" ;
@@ -27,19 +28,19 @@ let animationSpeed = 50;
2728const pxToNode = px => Math . floor ( px / parseFloat ( getComputedStyle ( document . documentElement ) . fontSize ) / nodeSize ) ;
2829
2930export const GraphPage = ( ) => {
30- // grid states
31+ // grid
3132 const grid = useRef ( [ ] ) . current ;
3233 const gridRef = useRef ( ) ;
3334 const [ dimensions , setDimensions ] = useState ( null ) ;
3435
35- // slider states
36+ // slider
3637 const exampleWeightRef = useRef ( ) ;
3738
38- // webcam states
39+ // webcam
3940 const webCamRef = useRef ( ) ;
4041 const [ webcamEnabled , setWebcamState ] = useState ( false ) ;
4142
42- // tutorial states
43+ // tutorial
4344 const [ tutorialPage , setTutorialPage ] = useState ( 1 ) ;
4445
4546 // INITIALIZATION
@@ -63,10 +64,11 @@ export const GraphPage = () => {
6364 document . removeEventListener ( "mousedown" , handleMouseDown ) ;
6465 document . removeEventListener ( "mousemove" , handleMouseMove ) ;
6566 document . removeEventListener ( "mouseup" , handleMouseUp ) ;
66- gridRef . current . removeEventListener ( "contextmenu" , e => e . preventDefault ( ) ) ;
6767 } ;
6868 } , [ ] ) ;
6969
70+ // READ IMAGES
71+
7072 const readWebcam = ( ) => {
7173 // https://github.com/mozmorris/react-webcam/issues/65#issuecomment-385126201
7274 const dataURLtoBlob = ( dataurl ) => {
@@ -260,7 +262,7 @@ export const GraphPage = () => {
260262 resetGrid ( ) ;
261263 const walls = mazeFunction ( grid ) ;
262264
263- const delay = 3000 / walls . length ;
265+ const delay = 2250 / walls . length ;
264266 const wallsPerIteration = delay > 2 ? 1 : Math . ceil ( 2 / delay ) ;
265267
266268 for ( let i = 0 ; i < walls . length ; i += wallsPerIteration ) {
@@ -317,7 +319,7 @@ export const GraphPage = () => {
317319 }
318320 }
319321
320- const resizeGrid = ( ) => {
322+ const resizeGrid = async ( ) => {
321323 clearAllTimeouts ( ) ;
322324
323325 let rows = pxToNode ( gridRef . current . offsetHeight ) ;
@@ -326,7 +328,7 @@ export const GraphPage = () => {
326328 if ( rows > 1 && rows % 2 === 0 ) rows -- ;
327329 if ( cols > 1 && cols % 2 === 0 ) cols -- ;
328330
329- setDimensions ( {
331+ await setDimensions ( {
330332 rows : rows ,
331333 cols : cols
332334 } ) ;
@@ -427,7 +429,7 @@ export const GraphPage = () => {
427429 { /* SIDEBAR */ }
428430 < div className = "sidebar d-flex flex-column bg-black" >
429431
430- < h5 className = "pb-3 mb-3 border-bottom" > < a href = "/" > < i className = "fas fa-arrow-circle-left fa-lg me-3" > </ i > </ a > Graph Algorithms</ h5 >
432+ < h5 className = "pb-3 mb-3 border-bottom" > < Link to = "/" > < i className = "fas link-info fa-arrow-circle-left fa-lg me-3" > </ i > </ Link > Graph Algorithms</ h5 >
431433
432434 < div className = "mb-3 gap-2 d-flex flex-row justify-content-start flex-wrap" >
433435 < button className = "btn btn-sm btn-warning" onClick = { resetGrid } > Reset Board</ button >
@@ -512,21 +514,25 @@ export const GraphPage = () => {
512514
513515 { /* Animation Speed Slider */ }
514516 < label className = "form-label d-block mb-1" > Animation Speed : </ label >
515- < input type = "range" step = "1" min = "1" max = "100" defaultValue = { 50 } className = "form-range"
517+ < input type = "range" step = "1" min = "1" max = "100" defaultValue = { 50 } className = "form-range mb-2 "
516518 onChange = { ( e ) => {
517519 clearVisualization ( true ) ;
518520 animationSpeed = parseInt ( e . target . value ) ;
519521 } } />
522+
523+ < button className = "btn btn-outline-light" data-bs-toggle = "modal" data-bs-target = "#tutorial" onClick = { ( ) => { setTutorialPage ( 1 ) } } >
524+ < i class = "fas fa-question-circle" > </ i >
525+ Tutorial
526+ </ button >
520527 </ div >
521- < li type = "button" data-bs-toggle = "modal" data-bs-target = "#tutorial" onClick = { ( ) => { setTutorialPage ( 1 ) } } > Tutorial</ li >
522528 </ div >
523529
524530 { /* Graph Algorithm Grid */ }
525531 { makeGridElement ( ) }
526532
527533 { /* Webcam Popup Window */ }
528- < div className = "modal fade" id = "modal" tabindex = "-1" aria-labelledby = "modal-label" aria-hidden = "true " >
529- < div className = "modal-dialog modal-dialog-centered" >
534+ < div className = "modal fade" id = "modal" tabindex = "-1" aria-labelledby = "modal-label" aria-hidden = "false " >
535+ < div className = "modal-dialog modal-dialog-centered modal-lg " >
530536 < div className = "modal-content camera-modal" >
531537 < div className = "modal-header" >
532538 < h5 className = "modal-title text-white" id = "modal-label" > Webcam Terrain Generator</ h5 >
@@ -543,7 +549,7 @@ export const GraphPage = () => {
543549 </ div >
544550
545551 { /* Tutorial Popup Window */ }
546- < div className = "modal show fade" id = "tutorial" tabindex = "-1" aria-labelledby = "myLargeModalLabel" aria-hidden = "true" >
552+ < div className = "modal fade" id = "tutorial" tabindex = "-1" aria-labelledby = "myLargeModalLabel" aria-hidden = "true" >
547553 < div className = "modal-dialog modal-dialog-centered modal-lg" >
548554 < div className = "modal-content camera-modal" >
549555 < div className = "modal-header" >
0 commit comments