Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Draw the Solution

00:00 Drawing the Solution. The last missing method in the SVGRenderer class is one that draws a solution as a line ending with an arrow marker.

00:39 You transform the squares of the solution to get their corresponding pixel coordinates. Notice that you add an extra offset to center the solution’s line vertically and horizontally in each square,

01:07 the marker-end SVG attribute refers to the SVG object identified as #arrow, which you defined earlier. At this point, you can print the resulting SVG in the console or save its XML content to a local file. You’ll make use of the maze you saved earlier in the course here, so ensure that your REPL session starts at the same level as the pyproject.toml file to ensure that the relative import of the mini_maze works correctly.

01:37 First, you import the mini_maze, which was created earlier, and then Path from pathlib to make creation of the file smpler. The Solution and SVGRenderer are imported from the maze_solver project …

01:58 and then a solution is manually created. An SVGRenderer object is created with the maze and solution as arguments. And finally, the file is written to disk.

02:28 This will save the rendered maze and your manually built solution in a file named maze.svg, which you can open using an external editor or viewer.

02:41 You should see something similar to what’s seen on-screen, but bear in mind that the rendering will look different depending on how you open it. On-screen, you can see the difference when opening in Firefox and Inkscape, and which one you prefer will be personal choice.

02:59 What is beyond debate is that it would be much more convenient to have a .preview() method on the SVG instance that you could call directly to have the image displayed to you.

03:08 You’ll implement that method in the next section of the course.

Become a Member to join the conversation.