think python turtleworld练习
来源:互联网 发布:微信推广淘宝商品 编辑:程序博客网 时间:2024/05/22 03:33
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">练习1 </span>
#!/usr/bin/python
from swampy.TurtleWorld import *
world = TurtleWorld()
bob = Turtle()
fd(bob,100)
lt(bob)
fd(bob,100)
print bob
wait_for_user()
#!/usr/bin/python
from swampy.TurtleWorld import *def square(t): #定义这个乌龟运动的函数
world = TurtleWorld()
t = Turtle()
for i in range(4): #用for循环进行遍历
fd(t,100) #往前都100步
lt(t) #往左拐
print t
square('bob') #进行调用这个函数
wait_for_user()
#!/usr/bin/python #通过函数可以改变乌龟的行走距离
from swampy.TurtleWorld import *
def square(t,length):
world = TurtleWorld()
t = Turtle()
for i in range(4):
fd(t,length)
lt(t)
print t
square('bob',200)
wait_for_user()
#!/usr/bin/python #函数再添加一个形参,用来控制遍历的次数、乌龟转弯的角度。本例乌龟爬行的轨迹是正六边形
from swampy.TurtleWorld import *
def square(t,length,n):
world = TurtleWorld()
t = Turtle()
for i in range(n):
fd(t,length)
lt(t,360/n)
print t
square('bob',100,6)
wait_for_user()
乌龟画圆重构后的
from swampy.TurtleWorld import * from math import * world = TurtleWorld()def polyline(t,n,length,angle):for i in range(n):fd(t,length)lt(t,angle)def arc(t,r,angle):arc_length = 2 * pi * r * angle /360.0n = int(arc_length / 3) + 1 #每个边长近似为3,已经足够小到画出好看的圆了step_length = arc_length / nstep_angle = float(angle) / npolyline(t,n,step_length,step_angle)bob = Turtle()bob.delay = 0.01arc(bob,70,270)wait_for_user()
0 0
- think python turtleworld练习
- Think Python 练习答案
- TurtleWorld
- <think python>一些练习的答案
- TurtleWorld demo
- Think in Python
- 《Think Python》笔记1
- 《Think Python》笔记2
- Think In Python Exercise
- 《think Python》学习笔记
- Think Python: Chapter 10 Lists
- Think Python: Chapter 11 Dictionaries
- Think Python: Chapter 12 Tuples
- (think python 读书笔记)文件
- think python 课后题实现
- think
- Think
- THINK
- CSS样式中,background-image 背景图片如何居中显示
- 【OVS2.5.0源码分析】openflow连接实现分析(4)
- 应届生面试嵌入式工程师的一点点经验
- jQuery的deferred
- lombok使用
- think python turtleworld练习
- Mybatis 3+Mysql 实现批量插入
- 设计模式之禅——代理模式(二)代理模式&AOP编程&JDK对代理模式的支持
- 三大运营商号段分配
- 简单排序--冒泡排序
- ubuntu112.04安装tslib库失败的解决方法
- C++一个很难看出来的错误
- 应用:线程同步
- 图像处理之霍夫变换(Hough)