🌈 Welcome to the Begginer-friendly Spirograph Drawing project
Crafted and taught by Shreya Malogi! 🌐
- Functionality: Creates vibrant and mesmerizing spirograph drawings using Python's Turtle module.
- Tech Stack:
Python
,turtle
,random
- Author: @shreyamalogi
- Year of Project: 2021
- Introduction
- Prerequisites
- Installation
- Running the Script
- Understanding the Code
- Customizing Your Spirograph
- Contribution
- License
Welcome to Spirograph Drawing! This Python script allows you to create vibrant and mesmerizing spirograph drawings using the Turtle module. Get ready to unleash your creativity with a few lines of code! 🌀🌈
Before you dive into the world of spirographs, make sure you have Python installed on your machine. If not, you can download it here.
No additional modules are required for this script. Just make sure you have Python installed.
- Open the script in your favorite Python environment.
- Run the script. This will launch the Turtle graphics window.
Let's break down the provided Python code for the Spirograph Drawing script:
import turtle as t
import random
myrtle = t.Turtle()
t.colormode(255)
def random_color():
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
color = (r, g, b)
return color
def draw_spirograph(size_of_gap):
for _ in range(int(360 / size_of_gap)):
myrtle.color(random_color())
myrtle.circle(100)
myrtle.setheading(myrtle.heading() + size_of_gap)
draw_spirograph(5)
-
Importing Libraries:
import turtle as t import random
turtle
is a module in Python that provides a way to create simple graphics.random
is a module that provides functions for generating random numbers.
-
Creating a Turtle:
myrtle = t.Turtle() t.colormode(255)
myrtle
is an instance of theTurtle
class, which is used for drawing.t.colormode(255)
sets the color mode to use RGB values ranging from 0 to 255.
-
Generating Random Colors:
def random_color(): r = random.randint(0, 255) g = random.randint(0, 255) b = random.randint(0, 255) color = (r, g, b) return color
- The
random_color
function generates a random RGB color and returns it as a tuple.
- The
-
Drawing Spirograph:
def draw_spirograph(size_of_gap): for _ in range(int(360 / size_of_gap)): myrtle.color(random_color()) myrtle.circle(100) myrtle.setheading(myrtle.heading() + size_of_gap)
- The
draw_spirograph
function uses a loop to draw circles in a spirograph pattern. myrtle.color(random_color())
sets the turtle's color to a random color.myrtle.circle(100)
draws a circle with a radius of 100 units.myrtle.setheading(myrtle.heading() + size_of_gap)
changes the heading of the turtle, creating the spirograph effect.
- The
-
Executing the Drawing:
draw_spirograph(5)
- This line calls the
draw_spirograph
function with asize_of_gap
of 5, determining the gap between each circle in the spirograph.
- This line calls the
The script, when executed, will create a visually appealing spirograph drawing with randomized colors. Adjusting the parameters can lead to various spirograph patterns.
Feel free to experiment with the script! Adjust the size_of_gap
parameter in the draw_spirograph
function to change the gap between each circle in the spirograph. You can also modify colors, circle radii, and other parameters to create various spirograph patterns.
Enjoying the magic of spirographs? Contribute to this creative journey and make it even more enchanting. Don't forget to star the project! ⭐🌟
This project is enchanted under the spell of the MIT License. Share the magic responsibly!
MIT License
Copyright (c) 2021 Shreya Malogi
Stay Enchanted! 🌍💙