Skip to content

Commit 2de2b7a

Browse files
committed
Add animation to pathfinding algorithm
* Animation makes it easier to track progress of algorithm
1 parent aac3d15 commit 2de2b7a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/components/MazeGrid.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ const MazeGrid: React.FC<MazeGridProps> = ({ handleMouseDown, handleMouseEnter,
1515
return (
1616
<div onMouseUp={handleMouseUp}>
1717
{maze.map((row, rowIndex) => (
18-
<div key={rowIndex} className="pathfinding-row" id={'row-' + rowIndex}>
18+
<div key={rowIndex} className="pathfinding-row wrapper" id={'row-' + rowIndex}>
1919
{row.map((cell, colIndex) => (
2020
<div
2121
key={colIndex}
22+
className={cell.visited ? 'animate' : 'pathfinding-cell'}
2223
onMouseDown={() => handleMouseDown(rowIndex, colIndex)}
2324
onMouseEnter={() => handleMouseEnter(rowIndex, colIndex)}
2425
style={{

src/styles/pathfinding.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,20 @@
4141
transition: .5s;
4242
}
4343

44+
@keyframes backgroundScaleIn {
45+
0% {
46+
transform: scale(0.2);
47+
}
48+
100% {
49+
transform: scale(1);
50+
}
51+
}
52+
53+
.animate {
54+
position: relative;
55+
animation: backgroundScaleIn .5s ease-in-out;
56+
}
4457

58+
.wrapper{
59+
background-color: white;
60+
}

0 commit comments

Comments
 (0)