diff --git a/Beginner_Projects/Turtle/Readme.md b/Beginner_Projects/Turtle/Readme.md new file mode 100644 index 0000000000..c183913e71 --- /dev/null +++ b/Beginner_Projects/Turtle/Readme.md @@ -0,0 +1,103 @@ +**Turtle Graphics** + +## Overview +The Turtle module in Python is a beginner-friendly graphics library that allows users to create complex shapes, patterns, and designs by giving simple commands to a "turtle" on the screen. It's a great way to learn the basics of programming, while making coding visually engaging and fun. + +## Installation +The Turtle module comes pre-installed with Python, so there's no need for additional installations. However, you can ensure it’s available by running: + + pip install PythonTurtle + + +## Features: +1) Direction: + Turtle can move a specified number of steps forward and backward. + - Move forward by x steps: + ```sh + forward(20) + ``` + - Move backward by x steps: + ```sh + backward(20) + ``` +2) Turn: + Turtle can turn by given degree in either direction (right or left). + ```sh + right(45) + ``` +3) Shape: + You can decide the shape of turtle using shape() function. + Available shapes are: turtle, circle, square, triangle, arrow, classic. + ```sh + shape("arrow") + ``` +4) Color: + You can control the color of turtle's drawing and appearance. + - To set drawing color: + ```sh + color('red') + ``` + - To set pen color: + ```sh + pencolor('green') + ``` + - To set background color: + ```sh + bgcolor('black') + ``` +5) Speed: + You can control the turtle's speed with speed(). + ```sh + speed(10) + ``` +6) Turtle position: + - Send turtle back to starting point. + ```sh + home() + ``` + Mainly used when turtle go off-screen. + - Get turtle's current position co-ordinates. + ```sh + pos() + ``` + - Clear all previous drawing, i.e. to get a clear screen. + ```sh + clearscreen() + ``` +7) Pen Control: + You can lift the pen up and down to control when the turtle draws. + - Lift the pen (Stop drawing): + When user want to move turtle without drawing anything. + ```sh + up() + ``` + - Put pen down (Start drawing): + When user want to start drawing again. + ```sh + down() + ``` +8) Width: + You can set the width of the turtle’s drawing line with width(x), where x is an integer value. + ```sh + width(x) + ``` + + +## General Turtle Graphics Code Syntax + +1) Import the Turtle Module. +2) Set up the screen. +3) Create a function to draw desired shape or pattern. +4) Take user input (if required) and pass it to the function. +5) Run the program. + +Don’t forget to use **turtle.done()** to keep the window open after the drawing is complete. + +## Example: Spiral Pattern + +For refernece, you can check out this [Spiral Patten example](turtle_spiral.py) created using turtle module. + +## Further Reading +For more detailed usage of the Turtle module, visit the official [Python documentation](https://docs.python.org/3/library/turtle.html). + + diff --git a/Beginner_Projects/Turtle/rainbow_spiral.py b/Beginner_Projects/Turtle/rainbow_spiral.py new file mode 100644 index 0000000000..dc24c42d37 --- /dev/null +++ b/Beginner_Projects/Turtle/rainbow_spiral.py @@ -0,0 +1,22 @@ +import turtle + +# defining colors +colors = ['red', 'yellow', 'green', 'purple', 'blue', 'orange'] + +# setup turtle pen +t= turtle.Pen() + +# changes the speed of the turtle +t.speed(10) + +# changes the background color +turtle.bgcolor("black") + +# make spiral_web +for x in range(200): + t.pencolor(colors[x%6]) # setting color + t.width(x/100 + 1) # setting width + t.forward(x) # moving forward + t.left(59) # moving left + +turtle.done() \ No newline at end of file diff --git a/Beginner_Projects/Turtle/turtle_spiral.py b/Beginner_Projects/Turtle/turtle_spiral.py new file mode 100644 index 0000000000..533194bccc --- /dev/null +++ b/Beginner_Projects/Turtle/turtle_spiral.py @@ -0,0 +1,30 @@ +import turtle as t + +# Setup the display window where turtle will draw +window = t.Screen() +# Configure Screen size +window.setup(800,800) +#set the speed of turtle +t.speed(50) +# Set background color +t.bgcolor('black') + +# Define a function to draw spiral with total steps and list of colors +def spiral(steps,color_list): + for step in range(steps): + for c in color_list: + t.width(step/50 ) # Set pattern width + t.color(c) # Set's turtle color + t.forward(step) # Move the turtle forward by "steps" + t.left(30) # Turn the turtle 30 degree to left + +if __name__ == '__main__': + print("Sprial printing!!") + total_steps = int(input("enter no. of steps: ")) + # split(',') denotes split input of colors string into list + color_list = input("enter the list of colors separated by commas: ").split(',') + spiral(total_steps,color_list) + t.done() + + + \ No newline at end of file diff --git a/README.md b/README.md index 9fcdea2802..ace669d118 100644 --- a/README.md +++ b/README.md @@ -94,16 +94,17 @@ The PyVerse repository is organized as follows: │ │ ├── main.py │ │ └── screenshots │ │ └── tkinter-working.gif -│ ├── QR Generator -│ │ ├── README.md -│ │ └── generate_qrcode.py -│ └── Stock App +│ ├── Stock App +│ │ ├── Readme.md +│ │ ├── Templates +│ │ │ ├── base.html +│ │ │ ├── financials.html +│ │ │ └── index.html +│ │ └── server.py +│ └── Turtle │ ├── Readme.md -│ ├── Templates -│ │ ├── base.html -│ │ ├── financials.html -│ │ └── index.html -│ └── server.py +│ ├── rainbow_spiral.py +│ └── turtle_spiral.py ├── Blockchain_Development ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md diff --git a/repo_structure.txt b/repo_structure.txt index e61850ed2b..a6eebc9ca8 100644 --- a/repo_structure.txt +++ b/repo_structure.txt @@ -18,16 +18,17 @@ │ │ ├── main.py │ │ └── screenshots │ │ └── tkinter-working.gif -│ ├── QR Generator -│ │ ├── README.md -│ │ └── generate_qrcode.py -│ └── Stock App +│ ├── Stock App +│ │ ├── Readme.md +│ │ ├── Templates +│ │ │ ├── base.html +│ │ │ ├── financials.html +│ │ │ └── index.html +│ │ └── server.py +│ └── Turtle │ ├── Readme.md -│ ├── Templates -│ │ ├── base.html -│ │ ├── financials.html -│ │ └── index.html -│ └── server.py +│ ├── rainbow_spiral.py +│ └── turtle_spiral.py ├── Blockchain_Development ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md