In this tutorial we will show you how to create beautiful constellations using Python turtle.
This article can be particularly helpful for teachers and parents to teach about Python; namely basic syntax, data structures, variables, accessing data, drawing with coding, computer graphics, loops and many more concepts.
Aside of teaching kids and young teens, turtle can also be an incredibly fun way to practice coding, internalize Python fundamentals, get some exercise or simply express yourself and have some fun.
So why shouldn’t you add some visual spice to your Python exercise? There is absolutely no reason why not. Anyway here is the turtle constellations tutorial for anyone and everyone that wishes to draw some beautiful starry nights.
We have a turtle tutorial about drawing stars and night sky, on which this tutorial sort of builds. You can find it here:
In this tutorial we’ll get a little more astrological and we will show you how to draw constellations with turtle and how much fun it can be.
- By following a list of coordinates we will attempt drawing a couple of popular constellations using stars.
- We will also follow the same coordinates to draw a yellow line between constellation stars as they are usually illustrated by connecting the stars.
Let’s first open an image so we can resize it.
Constellations, Stars and Python
Constellations are famous star patterns that correspond to celestial spheres and they go way back. First documented lists about constellations date back to 3rd century BC when ancient Greek poet Aratus worked on some 43 constellations. But who knows how much older the origination goes back.
In this section we’re going to elaborate on the significance of stars and constellations, what they meant to humans for ages, how to distinguish between Ursa Major and Ursa Minor constellations or in other words the differences of great bear and little bear. Feel free to go a couple section below for Python turtle examples.
What matters is we humans have always been mesmerized by the look of stars and they have been a burning torch of inspiration probably since humans first started walking on earth.
If you’ve ever looked at stars from a mountain summit, a remote farmland or from a beach at a dark night you probably know how charming stars really look.
So no wonder why it’s so much fun to mingle with constellations or even just look at them.
Luckily in this tutorial we will attempt to draw a couple of most popular constellations with Python’s turtle:
- Ursa Major
- Ursa Minor
Asterism vs Constellation
Ursa Major also consists of Big Dipper asterism while Ursa Minor consists of Little Dipper and the names can be often used synonymously. Asterisms are also star groups that don’t necessarily correspond to constellations or they can cover multiple constellations as well.
Ursa Major (Great Bear)
Famously shaped like a perfect saucepan, Ursa Major has been used to place Polaris (or Pole Star or North Star) for many centuries to find direction by sea captains, mountaineers, explorers and whoever else that might have needed it.
Outer most side of Ursa Major’s container part has two stars. If this side is projected further up (relative to the container) this projection coincides with Polaris and can be used to find both Ursa Minor and Polaris.
Ursa Major’s second handle star has a steeper handle compared to Ursa Minor and it’s also significantly bigger in general.
Ursa Minor (Little Bear)
Ursa Minor’s last star on its handle is the Polaris. Since, Polaris lays in direct line with Earth’s rotational axis it falls above the North Pole and as the Earth rotates its relative position always stays fixed. This creates a beautiful illusion as if all the other stars rotate around Polaris as the Earth turns around.
But more importantly it also provides a perfect fixed reference point and always points to North. You can imagine how valuable this would be especially in the old days in which electronic technology wasn’t advanced.
Even today, it can be extremely reliable for navigation when the electronics fail, batteries run out or accidents happen.
Besides Polaris Ursa Minor has a smoother handle curve than Ursa Major and it’s also significantly smaller in size.
Example 1: Drawing Ursa Major Constellation
We will basically navigate to each pseudo-coordinate for Ursa Major Constellation and then we will run the star making function at each of these coordinates.
Second step of the turtle drawing is connecting the constellation stars. This is quite simple we will just start drawing from beginning coordinate to the end coordinate simply by iterating through the coordinate list.
coordinates=((x,y),(x+135,y+1),(x+220,y-50),(x+330,y-105),(x+344,y-188), (x+470,y-209), (x+500,y-123))
# Big Dipper import turtle import random turtle.bgcolor("darkblue") turtle.speed(0) turtle.hideturtle() def ursamajor(i,j): for k in range(7): lst=["red","green","orange", "yellow","darkgray","brown","lightgreen"] turtle.color(lst[random.randint(0,6)]) turtle.forward(i) turtle.right(j) x=-350 y=-50 coordinates=((x,y),(x+135,y+1),(x+220,y-50),(x+330,y-105),(x+344,y-188), (x+470,y-209), (x+500,y-123)) def starconnect(): for i in range(1): ursamajor(12,144) for i in coordinates: turtle.penup() turtle.setpos(i) turtle.pendown() starconnect() my=turtle.Turtle() my.hideturtle() my.penup() for i in coordinates: my.goto(i) my.color("yellow") my.pendown() my.goto(coordinates[-4]) turtle.exitonclick()
Example 2: Drawing Ursa Minor Constellation
We’ll follow the same routine as Ursa Major drawing. Here is the coordinates for Ursa Minor.
coordinates=((x,y),(x-105,y-15),(x-220,y-60),(x-290,y-145),(x-315,y-258), (x-395,y-260), (x-375,y-135))
# Little Dipper import turtle import random turtle.bgcolor("darkblue") turtle.speed(0) turtle.hideturtle() def ursaminor(i,j): for iter in range(5): lst=["red","green","orange", "yellow","darkgray","brown","lightgreen"] turtle.color(lst[random.randint(0,6)]) turtle.forward(i) turtle.right(j) x=+340 y=280 coordinates=((x,y),(x-105,y-15),(x-220,y-60),(x-290,y-145),(x-315,y-258), (x-395,y-260), (x-375,y-135)) def starconnect(): for i in range(1): ursaminor(12,144) for i in coordinates: turtle.penup() turtle.setpos(i) turtle.pendown() starconnect() my=turtle.Turtle() my.hideturtle() my.penup() for i in coordinates: my.goto(i) my.color("yellow") my.pendown() my.goto(coordinates[-4]) turtle.exitonclick()
And here is how it looks.
Example 3: Combining Two Constellations
Finally, you can combine the code for both constellations to get them both in the same screen. It’s just copy paste from the codes above and you don’t need any adjustments.
Here is how it will look.
In this Python Tutorial, we’ve covered some basic astrology knowledge such as stars, constellations, asterisms and North Star.
We also built on the previous turtle star tutorial and drew something more sophisticated than random stars such as constellations.
We hope you liked this turtle tutorial. Feel free to share it and you’re more than welcome to visit our other Python tutorials anytime.