From a36c05c7f2296a2fe4b78d9ca8adf160405e3f6d Mon Sep 17 00:00:00 2001 From: Aditya12604 Date: Fri, 31 Oct 2025 02:07:11 +0530 Subject: [PATCH] Added a turtle art generator --- turtle_spirograph_art/README.md | 29 +++++++++++++++ turtle_spirograph_art/spirograph_art.py | 49 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 turtle_spirograph_art/README.md create mode 100644 turtle_spirograph_art/spirograph_art.py diff --git a/turtle_spirograph_art/README.md b/turtle_spirograph_art/README.md new file mode 100644 index 0000000..9327fa8 --- /dev/null +++ b/turtle_spirograph_art/README.md @@ -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) \ No newline at end of file diff --git a/turtle_spirograph_art/spirograph_art.py b/turtle_spirograph_art/spirograph_art.py new file mode 100644 index 0000000..2dd15db --- /dev/null +++ b/turtle_spirograph_art/spirograph_art.py @@ -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}") \ No newline at end of file