操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令
1.运动命令:
forward(degre待名e) #向前移动距离degree代表距离
backward(degree)#向后移动距离degree代表距离
right(degree) #向右移动多少度
left(degree) #向左移动多来自少度
goto(x,y) #将画笔移动到坐标为x,y的位置
stamp360问答() #复制当前图形
speed(speed) #画笔绘制的速度范围[0,10]整数
2.画笔控制命令:
down()#移动时绘州运查停百去密制图形,缺省时也为绘制
up() #移动时不绘制图形
pensize(width) #绘制图形时的宽度
color(colorstring)#绘制图形时的颜色
fillcolor(colorstring)#绘制图形的填充颜色
fill(Ture)
fill(false)
lucy:梦想照进现实;露茜;青春风采;
draw_***.py
[pyth观里育绝抗围化态员仍接on] viewplain copy
# -*- coding: cp936 -*-
import turtle
import math
def p_lin北培频划到e(t, n, length, angle):
"""Draws n line segments."""
for i in range(n):
***.fd(候米京行length)
t.lt(angle)
def polygon(t, n, length):
"""Draws a polygon with n sides."""
angle = 360/n
p_line(t, n, length普, angle)
de路f arc(t, r, angle):
"""Draws an arc with the given radius and angle."""
arc_length = 2 * ***.pi * r * abs(angle) / 360
n = int(arc_length / 4) + 1
step_lengt把主重脚绍围技h = arc_length / n
step_angle = float(angle) / n
# Before starting reduces, making a slight left turn.
t.lt(step_angle/天收2)
p_line(t, n, step_length, step_angle)
*岩密阶山但将约福委六**.r***(step_angle/2)
def petal(t, r, angle):
"""Draws a 花瓣 using two arcs."""
for i in range(2):
arc(t, r, angle)
t.lt(180-an场gle)
def flower(t, n, r, angle, p):
"""Draws a flower with n petal协s."""
for i in range(n):
petal(t, r, angle)
t.lt(p/n)
def leaf(t, r, angle, p):
"""Draws a 叶子 and fill it."""
***.begin_fill() # Begin the fill process.
*坐很波哪握围江夜存胞**.down()
flower(t, 1, 40, 80, 180)
***.end_fill()
def main():
window=***.screen() #creat a screen
***.bgcolor("blue")
lucy=***.***()
***.shape("turtle")
***.col信or("red")
*可病显期线将查草别**.width(5)
***.speed(0)
# Drawing flower
flower(l沙便院机高检真以ucy, 7, 60, 100, 360)
# Drawing pedicel
***.color("brown")
***.rt(90)
***.fd(200)
# Drawing leaf
***.rt(270)
***.color("green")
leaf(lucy, 40, 80, 180)
***.ht()
**片击减油粮*.exitonclick()
main()