Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions turtle_spirograph_art/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Turtle Spirograph Art Generator

This is a simple Python script that uses the built-in `turtle` module to draw a beautiful, colorful spirograph-style rosette.

## Description

The script opens a new graphics window and uses a turtle (a cursor) to draw a series of 36 overlapping circles. Each circle is drawn in a different random color from a predefined palette. By tilting the turtle 10 degrees after each circle, it creates a complex, symmetrical, and beautiful geometric pattern.

## Features

* Generates unique, colorful art every time.
* Uses a black background to make the colors pop.
* Shows a visual process as it draws.
* Finishes in just a few seconds.

## How to Run

1. Ensure you have Python 3 installed (which includes the `turtle` module).
2. Run the script from your terminal:
```sh
python spirograph_art.py
```
3. A new window will open and begin drawing.
4. Once finished, simply **click the window** to close it.

## Modules Used

* **`turtle`**: (Python's built-in graphics and art library)
* **`random`**: (Built-in module for picking random colors)
49 changes: 49 additions & 0 deletions turtle_spirograph_art/spirograph_art.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import turtle
import random

# --- 1. Setup the Screen and Turtle ---
try:
# Create a screen for the art
screen = turtle.Screen()
screen.bgcolor("black") # Set a black background
screen.title("Spirograph Art Generator")

# Create a turtle to do the drawing
t = turtle.Turtle()
t.speed(0) # '0' is the fastest speed
t.hideturtle() # Hide the arrow cursor
t.width(2) # Make the lines a bit thicker

# --- 2. Define the Color Palette ---
# A list of bright colors to choose from
colors = [
"red", "orange", "yellow", "green", "blue",
"cyan", "purple", "magenta", "white"
]

# --- 3. The Drawing Loop ---
# This loop will draw 36 overlapping circles
num_circles = 36
radius = 120 # The size of each circle

for _ in range(num_circles):
# Pick a new random color for each circle
t.color(random.choice(colors))

# Draw one circle
t.circle(radius)

# Tilt the turtle's "pen" by 10 degrees
# (360 degrees / 36 circles = 10 degrees)
t.left(10)

# --- 4. Finish ---
print("Art generation complete! Click the window to close.")
# This keeps the window open until you click on it
screen.exitonclick()

except turtle.Terminator:
# This catches the error if the user closes the window early
print("Drawing terminated.")
except Exception as e:
print(f"An error occurred: {e}")