- 老师答疑区
- 帖子详情
turtle一朵花
an-bang
发表于2017年11月20日
<p>第8周课后练习题:画一朵花</p><p><code class="brush:python;toolbar:false" >import turtle
import math
turtle.speed(0)
turtle.tracer(False) # 不显示动画效果,立刻得出最终效果
def arc(radian,angle):
arc_length = 2 * math.pi * radian * angle /360
n = int(arc_length / 10) + 1 #线段条数
step_length = arc_length /n #每条线段的长度
step_angle = angle / n
polyline(n,step_length,step_angle)
def polyline(n,length,angle):
for i in range(n):
turtle.fd(length)
turtle.lt(angle)
turtle.dot(5)
turtle.penup()
def single_leaf(chord_length): #chord_length 每朵花瓣中心距离整朵花中心的长度
turtle.forward(chord_length)
turtle.pendown()
turtle.right(45)
arc(60,90)
turtle.left(90)
arc(60,90)
turtle.penup()
turtle.goto(0,0)
turtle.setheading(0)
leaf_num = 12
def leafs1(chord_length1):
for i in range(leaf_num):
turtle.right(i*360/leaf_num)
single_leaf(chord_length1)
def leafs2(chord_length2):
for i in range(leaf_num):
turtle.right(i*360/leaf_num+15)
single_leaf(chord_length2)
def leafs3(chord_length3):
for i in range(6):
turtle.right(i*360/6)
single_leaf(chord_length3)
leafs1(60)
leafs2(40)
leafs3(10)
turtle.done()</code>先要知道怎么画一朵rose,然后才是用python turtle实现它,可惜从小就不会画画。</p>
2
回复