当前位置:   article > 正文

用python海龟制图画花瓣_Python教程:使用Turtles画出带有花瓣的花

用python海龟制图画花瓣

9131545298f447e394be1bfdb8cb33fd

简单画出一朵带有花瓣的花

# -*- coding:utf-8 -*-

import turtle

# create window and turtle

window = turtle.Screen()

babbage = turtle.Turtle()

# draw stem and centre

# draw stem

babbage.color('green', 'black')

babbage.left(90)

babbage.forward(100)

babbage.right(90)

# draw centre

babbage.color('black', 'black')

babbage.begin_fill()

babbage.circle(10)

babbage.end_fill()

# draw all petals

for i in range(1, 24):

if babbage.color() == ('red', 'black'):

babbage.color('orange', 'black')

elif babbage.color() == ('orange', 'black'):

babbage.color('yellow', 'black')

else:

babbage.color('red', 'black')

babbage.left(15)

babbage.forward(50)

babbage.left(157)

babbage.forward(50)

# hide the turtle

babbage.hideturtle()

# tidy up window

window.exitonclick()

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号