turtle一朵花

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