turtle之绘制美国队长的盾牌
第一步:导入库turtle
import turtle as t
第二步,绘制盾牌的圆:
def circle(x,y,r,color):
t.goto(x,y)
t.color(color,color)
t.begin_fill()
t.circle(r)
t.end_fill()
circle(0,-200,200,'red')
circle(0,-150,150,'white')
circle(0,-100,100,'red')
circle(0,-50,50,'blue')
第三步:绘制盾牌中间的五角星:
def wjx(x,y,p,color):
t.goto(x,y)
t.color(color,color)
t.begin_fill()
for i in range(5):
t.forward(p)
t.right(144)
t.end_fill()
最后一步:调用定义五角星的函数:
if __name__=="__main__":
wjx(-48,15,93,'white')
t.done()
完整代码如下:
import turtle as t
t.speed(0)#一步生成图像,不用慢慢画
def circle(x,y,r,color):
t.goto(x,y)
t.color(color,color)
t.begin_fill()
t.circle(r)
t.end_fill()
circle(0,-200,200,'red')
circle(0,-150,150,'white')
circle(0,-100,100,'red')
circle(0,-50,50,'blue')
def wjx(x,y,p,color):
t.goto(x,y)
t.color(color,color)
t.begin_fill()
for i in range(5):
t.forward(p)
t.right(144)
t.end_fill()
if __name__=="__main__":
wjx(-48,15,93,'white')
t.done()#使画布一直停留,不会画完就消失
效果如图: