我正在使用乌龟和蟒蛇绘制印度国旗。到目前为止,我已经得到了矩形和颜色,但我正努力在中间制作脉轮。
它有24个辐条,周围是一个封闭的圆圈。有关如何完成此任务的任何提示?
这是我现在的代码:
import turtle
def drawRectangle (t, w, h, c):
t.fillcolor(c)
t.begin_fill()
for i in range(2):
t.forward(h)
t.left(90)
t.forward(w)
t.left(90)
t.end_fill()
def main ():
wn = turtle.Screen()
chloe = turtle.Turtle()
drawRectangle(chloe,50,200, "chartreuse3")
chloe.up()
chloe.goto(0,-100)
chloe.down()
drawRectangle(chloe,50,200, "orange1")
chloe.up()
chloe.goto(100,-25)
chloe.down()
chloe.pencolor("blue4")
for i in range(24):
chloe.forward(20)
chloe.backward(20)
chloe.left(15)
chloe.up()
chloe.goto(300,300)
main()
答案 0 :(得分:1)
您可以使用circle
绘制圆圈:
chloe.pencolor("blue4")
# draw the spokes
for i in range(24):
chloe.forward(20)
chloe.backward(20)
chloe.left(15)
# raise pen
chloe.up()
# head down
chloe.setheading(270)
# go forward 20
chloe.forward(20)
# reset heading
chloe.setheading(0)
# pen down
chloe.down()
# draw the circle
chloe.circle(20)
答案 1 :(得分:-1)
import turtle
def drawRectangle (t, l, b, c):
t.fillcolor(c)
t.begin_fill()
for i in range(2):
t.forward(b)
t.left(90)
t.forward(l)
t.left(90)
t.end_fill()
def main ():
wn = turtle.Screen()
india = turtle.Turtle()
drawRectangle(india,50,200, "orange1")
india.up()
india.goto(0,-100)
india.down()
drawRectangle(india,50,200, "green")
india.up()
india.goto(100,-20)
india.down()
india.pencolor("blue3")
for i in range(24):
india.forward(20)
india.backward(20)
india.left(15)
india.up()
india.goto(400,400)
main()