Creating Spirograph using Python - Aman Aadi

Creating Spirograph using Python

Introduction:

Remember the fascinating geometric patterns of Spirograph toys from your childhood? Now, you can relive those nostalgic moments and unleash your creativity by creating a digital Spirograph using Python. In this blog post, we will embark on an exciting Python project that combines mathematics, art, and programming to generate mesmerizing Spirograph patterns. With just a few lines of code, you can design your unique Spirograph creations and explore the endless possibilities of intricate and captivating designs.

Understanding the Beauty of Spirographs:

Spirograph is a geometric drawing toy that creates intricate, symmetrical patterns through a combination of rotating gears and pens. It is based on mathematical principles of parametric equations and polar coordinates. These mesmerizing patterns are a delightful combination of mathematics and art, captivating people of all ages.

How would the python code work? It will use the turtle module for drawing spirograph. It will create circles continuously by moving 10 degree right from the same point.

Requirements:

Before we dive into the code, ensure you have Python installed on your computer. You can download the latest version from the official Python website (https://www.python.org/downloads/) and follow the installation instructions. Additionally, a code editor, such as Visual Studio Code or PyCharm, will make coding and testing more convenient. 

We’ll use the turtle graphics library in Python for drawing, which is a standard library included with Python.

Python Code:

# Importing Turtle and Screen class from turtle module
from turtle import Turtle, Screen

# Creating object from Turtle class
pen = Turtle()
# sets the speed of turtle
pen.speed("fastest")

# creating circles until it form a spirograph
for _ in range(int(360/10)):
    # create a circle given radius
    pen.circle(150)
    # turns turtle right by given angle
    pen.right(10)

# Creating object from Screen class
paper = Screen()

# using a method of Screen class to open the screen until the mouse is clicked
paper.exitonclick()

Output:

Python-turtle-spirograph

Conclusion:

Congratulations! You’ve successfully created a Spirograph masterpiece using Python. With the turtle module and a touch of creativity, you can generate an array of captivating Spirograph patterns. Experiment with different values for R, r, and d to explore endless possibilities and discover new Spirograph designs. Whether you’re a Python enthusiast or an aspiring artist, this delightful Python-Spirograph fusion is sure to ignite your passion for both programming and art. Happy drawing and enjoy the mesmerizing world of Spirograph art!

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Aman Aadi

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top