Skip to content

Commit da34f0e

Browse files
authored
Update readme.md
1 parent b5c869f commit da34f0e

File tree

1 file changed

+36
-2
lines changed
  • Python Projects/Intermediate Games/Spirograph

1 file changed

+36
-2
lines changed

Python Projects/Intermediate Games/Spirograph/readme.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,50 @@ This program allows you to create a spirograph using Python's turtle module. A s
1212
2. Open the terminal/command prompt and navigate to the directory where the files are located
1313

1414
3. Run the following command to start the program:
15-
'''cmd
15+
```cmd
1616
python spirograph_turtle.py
17-
'''
17+
```
1818
4. The spirograph will be drawn on the turtle window. You can close the window once the drawing is complete.
1919

2020
# Live Demo
2121
https://user-images.githubusercontent.com/67270567/226445938-1d5e2b6e-8ed3-4e7d-8064-139ca8ef9b02.mp4
2222

2323
Play the Video to see the Output
2424

25+
## Line By Line Explanation of the Sourcecode
26+
27+
```python
28+
import turtle as t
29+
import random
30+
```
31+
1. In this line, we import the turtle moduleThe code imports the turtle module and renames it as t for ease of use. It also imports the random module for generating random colors.
32+
33+
```python
34+
tim = t.Turtle()
35+
t.colormode(255)
36+
```
37+
2. Here, we create a turtle object called "tim". We also set the color mode to 255. This means that the colors we choose will be in the range of 0 to 255, instead of 0 to 1.
38+
39+
```python
40+
def random_color():
41+
r = random.randint(0, 255)
42+
g = random.randint(0, 255)
43+
b = random.randint(0, 255)
44+
color = (r, g, b)
45+
return color
46+
```
47+
3. The code defines a function random_color() that generates a random RGB color by generating random values for red, green, and blue components of the color, and returning the tuple of the three values.
48+
49+
```python
50+
def draw_spirograph(size_of_gap):
51+
for _ in range(int(360 / size_of_gap)):
52+
tim.color(random_color())
53+
tim.circle(100)
54+
tim.setheading(tim.heading() + size_of_gap)
55+
tim.speed(20)
56+
```
57+
4.
58+
2559
## Customization
2660
You can customize the appearance of the spirograph by changing the following values in the code:
2761

0 commit comments

Comments
 (0)