How to Draw the Houston Astros 2000-2012 Logo in Python IDLE Shell Using Turtle
by laserdude239 in Craft > Digital Graphics
30 Views, 0 Favorites, 0 Comments
How to Draw the Houston Astros 2000-2012 Logo in Python IDLE Shell Using Turtle
Coding can be quite daunting for beginner programmers. Luckily, Python's "Turtle" feature is widely regarded as an easy-to-use, beginner-friendly introduction to coding, allowing programming novices to gain some comfort with the language. Today, I'll demonstrate some of the Turtle class's basic methods and functionalities, and showcase how to utilize them to draw the Houston Astros 2000-2012 logo in Python's IDLE shell.
Install Python
Before we can get to coding, we must first make sure we have the correct version of Python installed on your device. Ensure that you have Python version 3 on your device or higher installed. If not, you can download it from the Python website. Here are two tutorials explaining the installation process for Mac and PC.
Open Python IDLE Shell
Once you've launched Python, a window should appear with the version number and a blank page for the user to write text. This window is called the terminal. Navigate to the upper left corner and click File. A dropdown menu will open. From this screen, click "New File" or press Ctrl+N. This will open a second screen called the IDLE Shell. This screen can be used to write multiple lines of code that can be run all at once, The output will be displayed on another screen.
Turtle Methods
Before we can begin writing the code, we must first familiarize ourselves with some of our new turtle methods and their functionalities. The following are a few basic ones:
- .penup()
- Lifts the pen off of the virtual canvas. When pen is lifted, it will not draw when moved.
- .pendown()
- Drops the pen onto the virtual canvas, When moved, pen will draw.
- .goto()
- Moves the pen from its resting location to a specific coordinate.
- .color()
- Allows user to change pen color
- .begin_fill()/.end_fill()
- After writing script to create a closed shape, using these functions to bookend your script will fill in the shape. We'll get more into detail when we use these functions in practice later.
Choose a Drawing
Next, it's time to select a drawing. I chose the 2000-2012 logo of the Houston Astros MLB Organization. The above functions can be used to create straight lines, so I chose a symbol comprised of only sharp corners and straight edges. Above is a template we can use to plot the logo on a coordinate grid.
Import Turtle Library
The first step in writing our script will be to import the turtle library. "Turtle" is a pre-installed class containing specific functions that allow a programmer to create shapes and drawings. Before we can use these functions in our script, we first must import the library containing them. To do so, we must insert the following brief line of code into our IDLE script.
Create Outer Layer
With our library imported and our drawing template chosen, we can begin our script!
The first thing that must be done is to initialize our turtle drawing by assigning it to a variable. This is done with the following line of code.
Note that I've chosen "tur" as the name of my variable. You can replace this with any variable name you like.
Next, I'll be mapping the outer layer of the star. Since I'll be starting off-center, I'm going to begin by lifting my pen off of the page, moving it to the coordinate of my choice, telling Python that I'll be filling my closed shape with .begin_fill(), and putting the pen back on the page before forming any lines/shapes. This is done with the following code:
Notice that we reference the "tur" variable we defined earlier in each of these method uses. We'll be doing this with every line of code we need for the rest of this drawing. Next, we can use the .goto() method to move our pen across the canvas, line by line, until we have something resembling our star. This can be done by copying and pasting the following code into the IDLE shell.
This is the code for each penstroke for the outer layer of our drawing. All that's left to do is lift our pen off the page and tell Python that our closed shape is ready to be filled in with the following lines of code.
To run your script, press Fn+F5 (Or Run>Run Module) and save your code file anywhere on your device. You'll only have to make this save the first time you run your code. A new window should appear with your virtual canvas and your new design!
To review the entire script thus far, view the code screenshot at the top of step 6.
Create Middle Layer
With our first layer created, we must now repeat the process two more times for the middle and innermost layers.
There's one small difference from our first script, however: we must now consider pen color. The turtle will default to a black pen color unless we specify that another color is needed. For the middle layer of the Astros logo, a sand/beige color is needed.
There is no shortage of online resources for finding the hex codes of sports/commercial logos. I used this website to find the exact hex codes needed for the next two layers of this logo. The setup for the middle layer of the Astros logo looks like this:
Note that we already lifted the pen in step 6, allowing us to move freely to position ourselves for the middle layer before lowering it again. The hex code is entered twice, once to define the line color and again to define the fill color. The same process from step 6 is repeated with slightly different coordinates:
Once this code has been typed (or pasted) into the shell, run the code to check for errors and prepare for the final layer! (See image above for code of the entire middle layer)
Create Final Layer
With one layer left, repeat the processes from steps 6 and 7. Use the following code to align your pen and change its color to brick red.
Use the following code to outline and fill the final layer.
Run your code and marvel at your new creation!
Python is known to many as the best language for beginners to learn programming. This exercise should help these novice coders familiarize themselves with writing scripts.