python基础—turtle画国旗

kai_xk

2022-03-09 18:45:27

Personal

写在前面:

由于本人代码能力弱爆了所以有很多冗余,望各位大佬轻喷

话不多说,上代码!

import turtle
t=turtle.Turtle
turtle.speed(0)
turtle.color("red")
turtle.width(15)
turtle.begin_fill()
turtle.forward(180)
turtle.left(-90)
turtle.forward(120)
turtle.left(-90)
turtle.forward(180)
turtle.left(90)
turtle.color("gray")
turtle.forward(120)
turtle.color("red")
turtle.end_fill()
turtle.penup()
turtle.home()
turtle.pendown()
turtle.color("red")
turtle.left(-90)
turtle.forward(120)
turtle.penup()
turtle.home()
turtle.pendown()

turtle.forward(30)
turtle.left(-90)
turtle.forward(40)
turtle.color("yellow")
turtle.width(1)
turtle.begin_fill()
for i in range(5):
    turtle.forward(27)
    turtle.left(144)
turtle.end_fill()
turtle.penup()
turtle.home()

turtle.forward(50)
turtle.left(-90)
turtle.forward(10)
turtle.color("yellow")
turtle.width(1)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
    turtle.forward(15)
    turtle.left(144)
turtle.end_fill()
turtle.penup()
turtle.home()

turtle.forward(70)
turtle.left(-90)
turtle.forward(30)
turtle.color("yellow")
turtle.width(1)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
    turtle.forward(15)
    turtle.left(144)
turtle.end_fill()
turtle.penup()
turtle.home()

turtle.forward(70)
turtle.left(-90)
turtle.forward(60)
turtle.color("yellow")
turtle.width(1)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
    turtle.forward(15)
    turtle.left(144)
turtle.end_fill()
turtle.penup()
turtle.home()

turtle.forward(50)
turtle.left(-90)
turtle.forward(80)
turtle.color("yellow")
turtle.width(1)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
    turtle.forward(15)
    turtle.left(144)
turtle.end_fill()
turtle.penup()
turtle.home()

turtle.done()

最终效果:

附上岛国国旗一幅:

代码:

import turtle
t=turtle.Turtle
turtle.speed(0)
turtle.color("red")
turtle.width(5)
turtle.forward(180)
turtle.left(-90)
turtle.forward(120)
turtle.left(-90)
turtle.forward(180)
turtle.left(90)
turtle.color("gray")
turtle.forward(120)
turtle.color("red")
turtle.penup()
turtle.home()
turtle.pendown()
turtle.color("red")
turtle.left(-90)
turtle.forward(120)
turtle.penup()
turtle.home()

turtle.forward(70)
turtle.left(-90)
turtle.forward(60)

turtle.pendown()
turtle.begin_fill()
turtle.circle(20,360,100)
turtle.end_fill()