top of page

Using Python Coding to Learn Other Subjects: Understanding Two-Point Perspective Drawing


Earlier this week, my son was asking about two-point perspective drawing. As art is definitely not one of my strong points, we went straight to Google and YouTube to try and learn.


After a couple of videos I felt I understood the basics. But I wanted to get a more thorough understanding of what's going on. So I took the obvious next step, of course: I wrote a Python program using the turtle module that allows me to easily draw using two-point perspective. Here's a video that will show you the program I wrote in action in which I use it to draw a building with a couple of roads:


 

The programming used in this project includes topics that we start introducing right from the start in our Spring Term Coding Courses, or courses starting later in the year too, of course

 

The ability to write computer code gives you a powerful tool to explore other subjects. In this case it's perspective drawing, but the same is true for many other topics and subjects. Science and Maths are especially suited for this learning through coding approach, but the same is true for other subjects as well.


The learning comes from two separate aspects of this exercise:


Writing the code

Using the code


Let's have a look at how this works.



Learning a Topic by Writing and Using a Computer Program


One of the key principles of coding is that you, the programmer, are fully in control of everything that happens in a program you write. This means you need to be able to understand every step of the process you are trying to recreate through your program.


In the past, when I worked as a research physicist, I would often find myself writing code to simulate some physics process I was exploring, using the laws of physics. I would then get to a point in writing my code, almost always, where I ask myself "what should happen next?" and realise that there is a small part of the physical process that I don't quite fully understand.


Since the program will not write itself, this would force me to find the information and knowledge needed for that next step. As a result, I would have understood that particular topic at a deeper level than before. When studying things theoretically, from a text book, it is sometimes hard to know what are the things you don't know about a subject. Having to write a computer program exposes these gaps in knowledge and forces you to learn them.


Once the code has been completed, the program can then be used to explore the subject further, and this is the second of the methods of learning mentioned above.


Both writing the code and using it help you learn the subject better, in different ways.



Understanding Two-Point Perspective Drawing using Python


But in this post I'm going to focus on a different topic: two-point perspective drawing (which falls just as much under the geometry category as it does under art!)


The basic idea behind two-point perspective drawing is that there are two vanishing points, one on each side, and all lines which should be horizontal in the real world should point towards one of these two vanishing points in the perspective drawing. This means that lines that are parallel to each other in the real world are not parallel in the drawing but converge to the same point. Vertical lines are drawn as vertical and remain parallel to each other. The video above will show this more clearly.


While writing the code, I had to fully understand what needs to happen at each point on the diagram and what all the geometric options are at each point. Having to write code that gets this geometric relationship right meant that I got to understand it a lot better than just through the videos I had watched on YouTube!


And once the code was completed, I could use it to draw several drawings, helping me to further understand what's going on.



Overview of the Coding Process


From a programming point of view, the method I used was as follows.


First, I created two turtles, one to draw the reference points and guide lines, and one to draw the actual lines. This way the guides can easily be removed when they're no longer needed.


This is a program that is best tackled by writing several functions. First, we need to choose the two vanishing points. The onclick method of the Screen() object comes in useful here as all we need to do is click on the points we want to use. The coordinates are stored as tuples in a list. The third click in my program defines the vertical line position and draws the vertical guide line.


From this point onwards, a click will placed the drawing pen turtle at this location. Changing what onclick does can be easily achieved by redefining the binding in the functions that are called by onclick.


Next, we need to be able to make the turtle point in one of three directions: either vertical, or towards the left vanishing point, or towards the right vanishing point. This is done by binding three keys to three functions that change the orientation of the turtle. The towards() method in the turtle module comes in useful for this as it gives us the angle needed for the turtle to point towards one of the vanishing points, and then we can use this angle in a call to setheading()


Drawing the guides is very useful for later on, so another key can be bound to a function that uses the reference turtle to draw a long line in the required direction, at the position of the drawing turtle.


Yet another key can be used to clear all drawings drawn by the reference turtle, so that we can remove the guides whenever we want.


The remaining functions and keybinds toggle penup() and pendown() to give us control on when the turtle draws a line or not, and two more keys to increases and decreases the pensize. You can add colour too if you want but in my version, the drawings are always done in black.


And there you go. You have the framework to create a drawing program that makes drawing using 2-point perspective relatively easy.


Happy Coding. And Happy Drawing.

 

Enrol you son or daughter on weekly Live Online Coding in Python course this Spring Half Term


 

169 views

Python Coding for Young People

CT-Unlimited-FinalRAW-transparent.png

Codetoday Unlimited is for the curious teenager or preteen keen to learn proper Python coding. Stephen's courses start from the basics and carry on to intermediate and advanced levels.

Python Coding for Adults

The Python Coding Place is Stephen's platform full of courses and other resources for beginners and intermediate learners. The focus is on clarity and Stephen's unique communication style.

bottom of page