① python怎么画玫瑰花
操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令
1. 运动命令:
forward(degree) #向前移动距离degree代表距离
backward(degree) #向后移动距离degree代表距离
right(degree) #向右移动多少度
left(degree) #向左移动多少度
goto(x,y) #将画笔移动到坐标为x,y的位置
stamp() #复制当前图形
speed(speed) #画笔绘制的速度范围[0,10]整数
2. 画笔控制命令:
down() #移动时绘制图形,缺省时也为绘制
up() #移动时不绘制图形
pensize(width) #绘制图形时的宽度
color(colorstring) #绘制图形时的颜色
fillcolor(colorstring) #绘制图形的填充颜色
fill(Ture)
fill(false)
lucy : 梦想照进现实;露茜;青春风采;
draw_flower1.py
[python]view plain
#-*-coding:cp936-*-
importturtle
importmath
defp_line(t,n,length,angle):
"""Drawsnlinesegments."""
foriinrange(n):
t.fd(length)
t.lt(angle)
defpolygon(t,n,length):
"""Drawsapolygonwithnsides."""
angle=360/n
p_line(t,n,length,angle)
defarc(t,r,angle):
"""."""
arc_length=2*math.pi*r*abs(angle)/360
n=int(arc_length/4)+1
step_length=arc_length/n
step_angle=float(angle)/n
#Beforestartingreces,makingaslightleftturn.
t.lt(step_angle/2)
p_line(t,n,step_length,step_angle)
t.rt(step_angle/2)
defpetal(t,r,angle):
"""Drawsa花瓣usingtwoarcs."""
foriinrange(2):
arc(t,r,angle)
t.lt(180-angle)
defflower(t,n,r,angle,p):
"""Drawsaflowerwithnpetals."""
foriinrange(n):
petal(t,r,angle)
t.lt(p/n)
defleaf(t,r,angle,p):
"""Drawsa叶子andfillit."""
t.begin_fill()#Beginthefillprocess.
t.down()
flower(t,1,40,80,180)
t.end_fill()
defmain():
window=turtle.Screen()#creatascreen
window.bgcolor("blue")
lucy=turtle.Turtle()
lucy.shape("turtle")
lucy.color("red")
lucy.width(5)
lucy.speed(0)
#Drawingflower
flower(lucy,7,60,100,360)
#Drawingpedicel
lucy.color("brown")
lucy.rt(90)
lucy.fd(200)
#Drawingleaf
lucy.rt(270)
lucy.color("green")
leaf(lucy,40,80,180)
lucy.ht()
window.exitonclick()
main()