roo.left(30) # moving the turtle 30 degrees towards left draw(3 * l / 4) # drawing a fractal on the left of the turtle object 'roo' with 3/4th of its length roo.right(60) # moving the turtle 60 degrees towards right draw(3 * l / 4) # drawing a fractal on the right of t...
'yellow','blue','green','orange','purple','white','gray'] sides = 4 # 可以改变sides,看其它的多边形效果 for x in range(360): turtle.pencolor(colors[x % sides]) turtle.forward(x * 3 / sides + x) turtle.left(360 / sides + 1) turtle.width(x * sides / 200) ...
undobuffersize=1000, visible=True)|| RawTurtle auto-creating (scrolled) canvas.|| When a Turtle object is created or a function derived from some| Turtle method is called a TurtleScreen object is automatically created.|| Method resolution order:|...
RawTurtle/Turtle 方法和对应函数 本节中的大部分示例都使用 Turtle 类的一个实例,命名为 turtle。 海龟动作 turtle.forward(distance) turtle.fd(distance) 参数 distance -- 一个数值 (整型或浮点型) 海龟前进 distance 指定的距离,方向为海龟的朝向。 >>> turtle.position() (0.00,0.00) >>> turtle....
turtle.bk(distance) turtle.backward(distance) 参数 distance -- 一个数值 海龟后退 distance 指定的距离,方向与海龟的朝向相反。不改变海龟的朝向。 >>> turtle.position() (0.00,0.00) >>> turtle.backward(30) >>> turtle.position() (-30.00,0.00) turtle.right(angle) turtle.rt(angle) 参数 angle...
TurtleScreen/Screen 的所有方法还存在对应的函数,即作为面向过程的接口组成部分。 RawTurtle(别名:RawPen) 类定义海龟对象在TurtleScreen上绘图。它的构造器需要一个 Canvas, ScrolledCanvas 或 TurtleScreen 作为参数,以指定 RawTurtle 对象在哪里绘图。 从RawTurtle 派生出子类Turtle(别名:Pen),该类对象在Screen实例...
我们现在可以开始使用面向对象的原则,矢量化移动进行事件处理,旋转技术来旋转游戏中使用的图像或精灵,甚至使用我们在 turtle 模块中学到的东西。在 turtle 模块中,我们学习了如何创建对象(参见第六章,面向对象编程),这些对象可以用于在我们可能使用 Pygame 构建的游戏的基本阶段调试不同的功能。因此,我们迄今为止学到的...
turtle — 海龟绘图¶ 源码:Lib/turtle.py 概述¶ 海龟绘图是对 最早在 Logo 中引入的受欢迎的几何绘图工具 的实现,它由 Wally Feurzeig, Seymour Papert 和 Cynthia Solomon 在 1967 年开发。 入门¶ 请想象绘图区有一只机器海龟,起始位置在 x-y 平面的 (0, 0) 点。先执行import turtle,再执行turtle...
#TurtleScreen methods can then be called for that object. #p.speed(10) p.left(90) #Turn turtle left by angle units. direction 调整画笔 p.penup() #Pull the pen up – no drawing when moving. p.goto(0,-200)#Move turtle to an absolute position. If the pen is down, draw line. Do...
当 Screen 类的方法对应函数被调用时会自动创建一个 Screen 对象。当 Turtle 类的方法对应函数被调用时会自动创建一个 (匿名的) Turtle 对象。 如果屏幕上需要有多个海龟,就必须使用面向对象的接口。 注解 以下文档给出了函数的参数列表。对于方法来说当然还有额外的第一个参数 self,这里省略了。