TurtleWorld

本文通过使用Python编程语言和swampy.TurtleWorld模块来绘制简单的几何图形,如正方形、八边形和多边形等。介绍了如何定义函数来重复绘制过程,并进一步扩展到绘制圆形,展示了基本的绘图技巧和技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)

输出:



 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值