From 70b10ff19a8ff5ebaf24b7678fa2ea2e7e200100 Mon Sep 17 00:00:00 2001 From: Ujjwal Singh Date: Tue, 15 Oct 2024 12:03:19 +0530 Subject: [PATCH] Added python and readme file --- Beginner_Projects/Turtle/Turtle-Art/README.md | 22 +++++ .../Turtle/Turtle-Art/Turlte-Art.py | 83 +++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 Beginner_Projects/Turtle/Turtle-Art/README.md create mode 100644 Beginner_Projects/Turtle/Turtle-Art/Turlte-Art.py diff --git a/Beginner_Projects/Turtle/Turtle-Art/README.md b/Beginner_Projects/Turtle/Turtle-Art/README.md new file mode 100644 index 00000000..e1522ae0 --- /dev/null +++ b/Beginner_Projects/Turtle/Turtle-Art/README.md @@ -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. \ No newline at end of file diff --git a/Beginner_Projects/Turtle/Turtle-Art/Turlte-Art.py b/Beginner_Projects/Turtle/Turtle-Art/Turlte-Art.py new file mode 100644 index 00000000..21be5461 --- /dev/null +++ b/Beginner_Projects/Turtle/Turtle-Art/Turlte-Art.py @@ -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() \ No newline at end of file