1、画线
1 #!/usr/bin/python
2 from swampy.TurtleWorld import *
3
4 world = TurtleWorld()
5 bob = Turtle()
6 print bob
7
8 for i in range(4):
9 fd(bob,100)
10 lt(bob)
11
12 for i in range(4):
13 print('Hello')
14
15 wait_for_user()
输出:
1 #!/usr/bin/python
2 from swampy.TurtleWorld import *
3
4 world = TurtleWorld()
5 bob = Turtle()
6 print bob
7
8 def draw_square(Tt,length):
9 fd(Tt,length)
10 lt(Tt)
11
12 for i in range(4):
13 draw_square(bob,100)
1 #!/usr/bin/python
2 from swampy.TurtleWorld import *
3
4 world = TurtleWorld()
5 bob = Turtle()
6 print bob
7 # the functions lt and rt make 90-degree turns by default.
8 # lt(bob,45) turns bob 45 degrees to the left
9 def draw_eight_sides(Tt,length):
10 fd(Tt,length)
11 lt(Tt,45)
12
13 for i in range(8):
14 draw_eight_sides(bob,60)
1 #!/usr/bin/python
2 from swampy.TurtleWorld import *
3
4 world = TurtleWorld()
5 bob = Turtle()
6 print bob
7 # the functions lt and rt make 90-degree turns by default.
8 # lt(bob,45) turns bob 45 degrees to the left
9 def draw_polygon(Tt,length,n):
10 fd(Tt,length)
11 lt(Tt,360/n)
12
13 for i in range(6):
14 draw_polygon(bob,60,6)
1 #!/usr/bin/python
2 from swampy.TurtleWorld import *
3
4 world = TurtleWorld()
5 bob = Turtle()
6 print bob
7 # the functions lt and rt make 90-degree turns by default.
8 # lt(bob,45) turns bob 45 degrees to the left
9 def draw_polygon(Tt,length,n):
10 angle = 360/n
11 for i in range(n):
12 fd(Tt,length)
13 lt(Tt,angle)
14
15 draw_polygon(bob,60,6)
1 #!/usr/bin/python
2 from swampy.TurtleWorld import *
3 import math
4 world = TurtleWorld()
5 bob = Turtle()
6 print bob
7 # the functions lt and rt make 90-degree turns by default.
8 # lt(bob,45) turns bob 45 degrees to the left
9 def polygon(t,length,n):
10 angle = 360/n
11 for i in range(n):
12 fd(t,length)
13 lt(t,angle)
14 def draw_circle(Tt,r):
15 circumference = 2 * math.pi * r
16 n = 100
17 length = circumference/n
18 polygon(Tt,length,n)
19
20 draw_circle(bob,50)
输出: