|
1 |
| - #Demo Video |
| 1 | +# Turtle Shapes |
| 2 | + This repository contains a Python project that uses the Turtle graphics module to draw shapes on the screen. The project is suitable for intermediate-level |
| 3 | + programmers who are interested in exploring the capabilities of the Turtle module and learning how to create simple games in Python. |
| 4 | + |
| 5 | +## Requirements |
| 6 | + - To run the project, you will need to have Python 3 installed on your computer, as well as the Turtle module. |
| 7 | + - The project was developed and tested on Python 3.9.5, but it should work on other versions of Python 3 as well. |
| 8 | + |
| 9 | +## Usage |
| 10 | + - Clone or Download the repository to your local machine. |
| 11 | + - Open the terminal/command prompt and navigate to the directory where file is located. |
| 12 | + - To run the project, run the main.py file using Python: |
| 13 | +```cmd |
| 14 | + python main.py |
| 15 | +``` |
| 16 | + - This will launch the game, which will draw a series of shapes on the screen using randomly selected colors. |
| 17 | + |
| 18 | +# Demo Video |
2 | 19 |
|
3 | 20 | https://user-images.githubusercontent.com/67270567/226439699-38ad1816-0113-43e0-bb75-43655b69e6b1.mp4
|
4 | 21 |
|
5 | 22 | Press Play to Exit!!!
|
| 23 | + |
| 24 | +# Line By Line Explanation of Code |
| 25 | +```python |
| 26 | +import turtle as t |
| 27 | +import random |
| 28 | + |
| 29 | +tim = t.Turtle() |
| 30 | + |
| 31 | +colours = ["CornflowerBlue", "DarkOrchid", "IndianRed", "DeepSkyBlue", "LightSeaGreen", "wheat", "SlateGray", "SeaGreen"] |
| 32 | +``` |
| 33 | +1. **import turtle as t:** This line imports the turtle module and renames it as "t" to make it easier to reference in the code. |
| 34 | + - **import random:** This line imports the random module, which will be used later to randomly choose colors from a list. |
| 35 | + - **tim = t.Turtle():** This line creates a new turtle object named "tim", which will be used to draw shapes on the screen. |
| 36 | + - **colours = ["CornflowerBlue", "DarkOrchid", "IndianRed", "DeepSkyBlue", "LightSeaGreen", "wheat", "SlateGray", "SeaGreen"]:** This line creates a list of color names that will be used to randomly color the shapes. |
| 37 | + |
| 38 | + ```python |
| 39 | + def draw_shape(num_sides): |
| 40 | + angle = 360 / num_sides |
| 41 | + for i in range(num_sides): |
| 42 | + tim.forward(100) |
| 43 | + tim.right(angle) |
| 44 | + ``` |
| 45 | + 2. **def draw_shape(num_sides):** This line defines a function called "draw_shape" that takes one parameter called "num_sides", which represents the number of sides of the shape to be drawn. |
| 46 | + - **angle = 360 / num_sides:** This line calculates the angle that the turtle will need to turn in order to draw each side of the shape. |
| 47 | + - **for i in range(num_sides):** This line starts a loop that will repeat "num_sides" times, each time drawing one side of the shape. |
| 48 | + - **tim.forward(100):** This line moves the turtle forward 100 pixels to draw the next side of the shape. |
| 49 | + - **tim.right(angle):** This line turns the turtle to the right by the angle calculated earlier, so that it will be facing in the correct direction to draw the next side of the shape. |
| 50 | + |
| 51 | + ```python |
| 52 | + for shape_side_n in range(3, 10): |
| 53 | + tim.color(random.choice(colours)) |
| 54 | + draw_shape(shape_side_n) |
| 55 | + ``` |
| 56 | + 3. **for shape_side_n in range(3, 10):** This line starts a loop that will repeat 7 times, each time drawing a shape with a different number of sides, |
| 57 | + ranging from 3 to 9. |
| 58 | + - **tim.color(random.choice(colours)):** This line randomly selects a color from the "colours" list and sets it as the turtle's drawing color for the next shape. |
| 59 | + - **draw_shape(shape_side_n):** This line calls the "draw_shape" function, passing in the current number of sides as the argument, so that the turtle will draw a shape with that number of sides. |
| 60 | + |
| 61 | +4. In summary, this code creates a turtle named "tim" and a list of colors, defines a function to draw shapes with a given number of sides, and then uses a loop to draw a series of shapes with different numbers of sides, randomly selecting colors for each shape from the list of colors. |
| 62 | + |
| 63 | + |
| 64 | +## Customization |
| 65 | + - The project can be customized in various ways, such as changing the number of shapes drawn, the colors used, and the size of the shapes. |
| 66 | + - These customizations can be made by modifying the main.py file. |
| 67 | + |
| 68 | +## License |
| 69 | + This project is licensed under the `MIT License`. Feel free to use, modify, and distribute the code as you see fit. See the LICENSE file for more details. |
0 commit comments