-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPy_TurtleTest2.py
More file actions
181 lines (137 loc) · 3.82 KB
/
Py_TurtleTest2.py
File metadata and controls
181 lines (137 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from logging import root
import turtle
from turtle import Screen, Turtle
from random import random
def stop():
turtle.bye()
def DrawRainbow2():
mypen = turtle.Turtle()
mypen.shape('turtle')
mypen.speed(15)
root.protocol("WM_DELETE_WINDOW", stop)
window = turtle.Screen()
window.bgcolor('white')
rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
size = 180
mypen.penup()
mypen.goto(0, -180)
for color in rainbow:
mypen.color(color)
mypen.fillcolor(color)
mypen.begin_fill()
mypen.circle(size)
mypen.end_fill()
size -= 20
turtle.done()
def DrawRainbow1():
# Creating a turtle screen object
sc = turtle.Screen()
turtle.TurtleScreen._RUNNING=True
# Creating a turtle object(pen)
pen = turtle.Turtle()
root.protocol("WM_DELETE_WINDOW", stop)
# Defining a method to form a semicircle
# with a dynamic radius and color
def semi_circle(col, rad, val):
# Set the fill color of the semicircle
pen.color(col)
# Draw a circle
pen.circle(rad, -180)
# Move the turtle to air
pen.up()
# Move the turtle to a given position
pen.setpos(val, 0)
# Move the turtle to the ground
pen.down()
pen.right(180)
# Set the colors for drawing
col = ['violet', 'indigo', 'blue', 'green', 'yellow', 'orange', 'red']
# Setup the screen features
sc.setup(600, 600)
# Set the screen color to black
sc.bgcolor('black')
# Setup the turtle features
pen.right(90)
pen.width(10)
pen.speed(7)
# Loop to draw 7 semicircles
for i in range(7):
semi_circle(col[i], 10 * (i + 8), -10 * (i + 1))
# Hide the turtle
pen.hideturtle()
def DrawAxis():
t1 = Turtle() # Turtle is a drawer
# set direction at 0
# angle using seth
t1.seth(0)
# motion
t1.forward(80)
t1.write("East")
# back to home
t1.home()
# set direction at 90
# angle using sethading
t1.setheading(90)
# motion
t1.forward(80)
t1.write("North")
# back to home
t1.home()
# set direction at 180
# angle using seth
t1.seth(180)
# motion
t1.forward(80)
t1.write("West",align="right")
# back to home
t1.home()
# set direction at 270
# angle using setheading
t1.setheading(270)
# motion
t1.forward(80)
t1.write("South")
# hide the turtle
t1.ht()
t1.screen.mainloop()
def DrawRectanlge():
t2 = Turtle() # Turtle is a drawer
t2.forward(100) # Draw a line
t2.right(90) # Direction to Right
t2.forward(100) # Draw a line
t2.right(90) # Direction to Right
t2.forward(100) # Draw a line
t2.right(90) # Direction to Right
t2.forward(100) # Draw a line
t2.clear()
t2.forward(50)
t2.right(90)
t2.forward(50)
t2.right(90)
t2.forward(50)
t2.right(90)
t2.forward(50)
t2.screen.mainloop()
def Draw1():
t3 = Turtle() # Turtle is a drawer
for steps in range(100):
for c in ('blue', 'red', 'green'):
t3.color(c)
t3.forward(steps)
t3.right(30)
t3.screen.mainloop()
def Draw2():
t4 = Turtle() # Turtle is a drawer
for i in range(100):
steps = int(random() * 100)
angle = int(random() * 360)
t4.right(angle)
t4.fd(steps)
t4.screen.mainloop()
# Main Program
#DrawRectanlge()
#DrawAxis()
#Draw1()
#Draw2()
DrawRainbow2()
DrawRainbow1()