Skip to content

Commit

Permalink
[Code Addition Request]: Turtle-Art beginner project #592 (#602)
Browse files Browse the repository at this point in the history
## Pull Request for PyVerse 💡

### Requesting to submit a pull request to the PyVerse repository.

---

#### Issue Title
**Please enter the title of the issue related to your pull request.**  
*[Code Addition Request]: Turtle-Art beginner project #592*

- [x] I have provided the issue title.

---

#### Info about the Related Issue
**What's the goal of the project?**  
*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.*

- [x] I have described the aim of the project.

---

#### Name
**Please mention your name.**  
*Ujjwal Singh*

- [x] I have provided my name.

---

#### GitHub ID
**Please mention your GitHub ID.**  
*Ujjwal-Singh-20*

- [x] I have provided my GitHub ID.

---

#### Email ID
**Please mention your email ID for further communication.**  
*[email protected]*

- [x] I have provided my email ID.

---

#### Identify Yourself
**Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC,
SWOC).**
*hacktoberfest*

- [x] I have mentioned my participant role.

---

#### Closes
**Enter the issue number that will be closed through this PR.**  
*Closes: #592 *

- [x] I have provided the issue number.

---

#### Describe the Add-ons or Changes You've Made
**Give a clear description of what you have added or modified.**  
*Added python file and readme file.*

- [x] I have described my changes.

---

#### Type of Change
**Select the type of change:**  
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Code style update (formatting, local variables)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

---

#### How Has This Been Tested?
**Describe how your changes have been tested.**  
*Tested on my local computer.*

- [x] I have described my testing process.

---

#### Checklist
**Please confirm the following:**  
- [x] My code follows the guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly wherever it was hard to
understand.
- [ ] I have made corresponding changes to the documentation.
- [x] My changes generate no new warnings.
- [ ] I have added things that prove my fix is effective or that my
feature works.
- [x] Any dependent changes have been merged and published in downstream
modules.
  • Loading branch information
UTSAVS26 authored Oct 16, 2024
2 parents d8b8616 + 70b10ff commit 1980a10
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Beginner_Projects/Turtle/Turtle-Art/README.md
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.
83 changes: 83 additions & 0 deletions Beginner_Projects/Turtle/Turtle-Art/Turlte-Art.py
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()

0 comments on commit 1980a10

Please sign in to comment.