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 refer to our video player troubleshooting guide for assistance.

Add More Primitives

00:00 Adding More Primitives. Two other primitives closely related to a line are SVG polylines and polygons, which extend the idea of a line. They’re both tuples of two or more points, which look nearly identical.

00:23 The difference is that a polygon is closed, meaning that it connects the first and last point, while the polyline isn’t, leaving the last point unconnected. In case you’re wondering, the points parameter must be passed as a keyword argument to avoid conflating it with the value positional argument.

01:02 Sometimes it may be more convenient to combine existing lines instead of individual points, especially when they don’t form a continuous polyline. That’s when a DisjointLines primitive comes in handy.

01:30 Note that this is merely a logical collection of lines and has no SVG equivalent. Other, more specific SVG primitives that you’ll be interested in include a rectangle and a text element. You implement them as data classes rather than tuples or named tuples because they’re not inherently sequences of elements.

02:04 The rectangle accepts an optional top-left corner, whose coordinates get mixed in with the rest of the attributes through the union operator (|).

03:03 Last but not least, you’ll apply the null object pattern again by implementing a dummy NullPrimitive, which returns an empty string. This will let you avoid checking for a special case when there are no primitives to represent something in SVG, ultimately leading to cleaner and more readable code.

03:37 In the next section of the course, you’ll put your primitives to use by decomposing various border patterns around the maze squares into SVG elements.

Become a Member to join the conversation.