-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00c4043
commit 70b10ff
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# **PYTHON TURTLE ART GENERATOR** | ||
|
||
## 🎯 **Goal** | ||
The goal of this project is to create a dynamic, interactive program that draws random patterns using geometric shapes like squares, circles, triangles, and stars. Users can customize the background color, turtle speed, and the number of shapes drawn. | ||
|
||
## 🧾 **Description** | ||
This project leverages the turtle module to draw random shapes at random locations on the screen. Users can choose background colors, control the drawing speed, and specify the number of shapes to be generated. The program creates a visually appealing display of geometric patterns using random colors, all within an interactive Python environment. | ||
|
||
## 🧮 **What I had done!** | ||
Created functions to draw squares, circles, triangles, and stars. | ||
Implemented random color generation to enhance the visual experience. | ||
Added user customization features for background color, turtle speed, and the number of shapes. | ||
Developed a function to randomly place and draw these shapes on the screen with varying sizes. | ||
Included input validation to ensure smooth user interaction. | ||
|
||
## 📚 **Libraries Needed** | ||
turtle: A Python standard library used to create graphics and shapes. | ||
random: Used for generating random colors, positions, and selecting random shapes. | ||
Both libraries are part of Python's standard library, so no external installation is needed. | ||
|
||
## 📢 **Conclusion** | ||
This project demonstrates how Python's turtle graphics can be used to create customizable visual displays with random patterns. It highlights user interaction, simple input validation, and the use of basic shapes to generate interesting graphics. Future improvements could include more shape options, enhanced user controls, and improved input handling. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import turtle | ||
import random | ||
from turtle import Screen, Turtle | ||
|
||
# Setup Turtle and Screen | ||
screen = Screen() | ||
screen.bgcolor("black") # Background color set to black for better contrast | ||
|
||
artist = Turtle() | ||
artist.speed(0) # Maximum speed for faster drawing | ||
artist.hideturtle() # Hide turtle icon | ||
turtle.colormode(1.0) # Use RGB colors | ||
|
||
# Function to generate random colors | ||
def random_color(): | ||
return (random.random(), random.random(), random.random()) | ||
|
||
# Function to draw a square | ||
def draw_square(size): | ||
for _ in range(4): | ||
artist.forward(size) | ||
artist.right(90) | ||
|
||
# Function to draw a circle | ||
def draw_circle(radius): | ||
artist.circle(radius) | ||
|
||
# Function to draw a triangle | ||
def draw_triangle(size): | ||
for _ in range(3): | ||
artist.forward(size) | ||
artist.left(120) | ||
|
||
# Function to draw a star | ||
def draw_star(size): | ||
for _ in range(5): | ||
artist.forward(size) | ||
artist.right(144) | ||
|
||
# Function to draw random patterns with shapes | ||
def draw_random_patterns(num_shapes): | ||
shapes = [draw_square, draw_circle, draw_triangle, draw_star] | ||
for _ in range(num_shapes): | ||
artist.penup() | ||
artist.goto(random.randint(-200, 200), random.randint(-200, 200)) | ||
artist.pendown() | ||
artist.color(random_color()) | ||
shape = random.choice(shapes) | ||
size_or_radius = random.randint(20, 100) | ||
shape(size_or_radius) | ||
|
||
# Function to allow user customization | ||
def customization_options(): | ||
bg_color = input("Enter background color (e.g., black, white): ") | ||
screen.bgcolor(bg_color) | ||
|
||
while True: | ||
try: | ||
turtle_speed = int(input("Enter turtle speed (1-10): ")) | ||
if 1 <= turtle_speed <= 10: | ||
artist.speed(turtle_speed) | ||
break | ||
else: | ||
print("Please enter a number between 1 and 10.") | ||
except ValueError: | ||
print("Invalid input. Please enter a valid number.") | ||
|
||
while True: | ||
try: | ||
num_shapes = int(input("Enter the number of shapes to draw: ")) | ||
if num_shapes > 0: | ||
draw_random_patterns(num_shapes) | ||
break | ||
else: | ||
print("Please enter a positive number.") | ||
except ValueError: | ||
print("Invalid input. Please enter a valid number.") | ||
|
||
# Execute the customization options | ||
customization_options() | ||
|
||
# Close the turtle graphics window when clicked | ||
screen.exitonclick() |