Dan Anglin
4c7e50ec39
Add a side panel to allow users to interact with the app. The generate button now generates the maze.
78 lines
1.8 KiB
Python
78 lines
1.8 KiB
Python
from tkinter import Tk, Canvas
|
|
|
|
|
|
class Point:
|
|
"""
|
|
Point represents the position of a point.
|
|
"""
|
|
|
|
def __init__(self, x: int, y: int):
|
|
self.x = x
|
|
self.y = y
|
|
|
|
|
|
class Line:
|
|
"""
|
|
Line represents a graphical line.
|
|
"""
|
|
|
|
def __init__(self, point_a: Point, point_b: Point) -> None:
|
|
self.point_a = point_a
|
|
self.point_b = point_b
|
|
|
|
|
|
class Graphics:
|
|
def __init__(self, canvas: Canvas) -> None:
|
|
self._canvas = canvas
|
|
|
|
def draw_line(
|
|
self,
|
|
line: Line,
|
|
fill_colour: str = "black",
|
|
width: int = 2
|
|
) -> None:
|
|
"""
|
|
draws a line onto the canvas.
|
|
"""
|
|
self._canvas.create_line(
|
|
line.point_a.x, line.point_a.y,
|
|
line.point_b.x, line.point_b.y,
|
|
fill=fill_colour,
|
|
width=width,
|
|
)
|
|
|
|
|
|
class Window:
|
|
"""
|
|
Window is a Graphical window.
|
|
"""
|
|
|
|
def __init__(self, width: int, height: int) -> None:
|
|
self._root = Tk()
|
|
self._root.title("Maze Solver")
|
|
|
|
# Position the window to the centre of the screen
|
|
screen_width = self._root.winfo_screenwidth()
|
|
screen_height = self._root.winfo_screenheight()
|
|
centre_x = int(screen_width/2 - width/2)
|
|
centre_y = int(screen_height/2 - height/2)
|
|
self._root.geometry(f"{width}x{height}+{centre_x}+{centre_y}")
|
|
|
|
# Styling
|
|
self.background_colour = "white"
|
|
self.cell_grid_colour = "black"
|
|
|
|
self._canvas = Canvas(self._root)
|
|
self._canvas.config(
|
|
bg=self.background_colour,
|
|
height=height,
|
|
width=width,
|
|
)
|
|
self._canvas.pack()
|
|
|
|
def redraw(self) -> None:
|
|
"""
|
|
redraw redraws all the graphics in the window.
|
|
"""
|
|
self._root.update_idletasks()
|
|
self._root.update()
|