绘制风轮

image

初始样式:

import turtle as t
t.begin_fill()

t.fillcolor("red")
t.seth(0)  #改变方向朝向0°
t.forward(180)
t.right(90) #方向顺时针旋转90°
t.circle(-100,45) #顺时针为-,逆时针为+,后面是长度,第二个参数为旋转角度。
t.right(90)
t.goto(0,0)

t.end_fill()

t.begin_fill()
t.fillcolor("yellow")

t.seth(90)  #改变方向朝向0°
t.forward(180)
t.right(90) #方向顺时针旋转90°
t.circle(-100,45) #顺时针为-,逆时针为+,后面是长度,第二个参数为旋转角度。
t.right(90)
t.goto(0,0)

t.end_fill()

t.begin_fill()
t.fillcolor("green")

t.seth(180)  #改变方向朝向0°
t.forward(180)
t.right(90) #方向顺时针旋转90°
t.circle(-100,45) #顺时针为-,逆时针为+,后面是长度,第二个参数为旋转角度。
t.right(90)
t.goto(0,0)

t.end_fill()

t.begin_fill()
t.fillcolor("blue")

t.seth(270)  #改变方向朝向0°
t.forward(180)
t.right(90) #方向顺时针旋转90°
t.circle(-100,45) #顺时针为-,逆时针为+,后面是长度,第二个参数为旋转角度。
t.right(90)
t.goto(0,0)
t.end_fill()

使用循环简化步骤:

angles=[0,90,190,270]
colors=["red","yellow","green","blue"]

for i in range(4):
    t.begin_fill()
    t.fillcolor(colors[i])
    t.seth(angles[i])
    t.forward(100)
    t.right(90)
    t.circle(-100,45)
    t.goto(0,0)
    t.end_fill()
t.exitonclick() # turtle执行完后保留那个页面

image

用函数封装:

def draw():
    angles=[0,90,190,270]
    colors=["red","yellow","green","blue"]
    t.begin_fill()
    t.fillcolor(colors[i])
    t.seth(angles[i])
    t.forward(100)
    t.right(90)
    t.circle(-100, 45)
    t.goto(0, 0)
    t.end_fill()

for i in range(4):
    draw()

t.exitonclick() #turtle执行完后保留那个页面


image

posted @ 2022-10-14 22:33  Selina风乎舞雩  阅读(43)  评论(0)    收藏  举报