欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python-turtle模块绘图(升国旗)

程序员文章站 2022-05-04 11:44:00
Python的turtle模块绘画国旗...

Python-turtle模块绘图(升国旗)

画国旗

import turtle
turtle.bgcolor('wheat')

turtle.speed(6)

def down(x,y):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    turtle.begin_fill()
    turtle.fillcolor("yellow")
    turtle.pencolor("yellow")
    for x in range(5):
        turtle.forward(20)
        turtle.right(144)
    turtle.end_fill()


str =("我的祖国")
turtle.setup(1800,700,70,70)
turtle.color('black', 'pink')
turtle.pensize(3)  
turtle.hideturtle() 
turtle.up() 
turtle.goto(-255, -255)
turtle.down()
turtle.showturtle()
#画左边的小人
turtle.goto(-200,-200)
turtle.goto(-200,-120)
turtle.circle(35)
turtle.goto(-200,-200)
turtle.forward(40)
turtle.right(90)
turtle.forward(60)
turtle.hideturtle()
turtle.up() 
turtle.goto(-200, -160)
turtle.down()
turtle.showturtle()
turtle.left(90)
turtle.forward(55)
turtle.right(45)
turtle.forward(20)
turtle.hideturtle()
turtle.up()
turtle.goto(-200, -145)
turtle.down()
turtle.showturtle()
turtle.goto(-145, -145)
turtle.left(90)
turtle.forward(20)

#画第一个爱心
turtle.color('pink', 'pink')
turtle.begin_fill()
turtle.hideturtle()
turtle.up()
turtle.goto(-100, -153)
turtle.down()
turtle.showturtle()
turtle.right(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(30)
turtle.left(45)
turtle.circle(10.6,180)
turtle.left(180)
turtle.circle(10.6,180)
turtle.end_fill()
#下一个大爱心
turtle.color('pink', 'pink')
turtle.begin_fill()
turtle.hideturtle()
turtle.up()
turtle.goto(-30, -143)
turtle.down()
turtle.showturtle()
turtle.left(135)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(45)
turtle.circle(17.67,180)
turtle.left(180)
turtle.circle(17.67,180)
turtle.end_fill()

#第三个爱心
turtle.color('pink', 'pink')
turtle.begin_fill()
turtle.hideturtle()
turtle.up()
turtle.goto(65, -133)
turtle.down()
turtle.showturtle()
turtle.left(135)
turtle.right(90)
turtle.forward(70)
turtle.left(90)
turtle.forward(70)
turtle.left(45)
turtle.circle(24.74,180)
turtle.left(180)
turtle.circle(24.74,180)
turtle.end_fill()

#第四个爱心
turtle.color('pink', 'pink')
turtle.begin_fill()
turtle.hideturtle()
turtle.up()
turtle.goto(187, -133)
turtle.down()
turtle.showturtle()
turtle.left(135)
turtle.right(90)
turtle.forward(70)
turtle.left(90)
turtle.forward(70)
turtle.left(45)
turtle.circle(24.74,180)
turtle.left(180)
turtle.circle(24.74,180)
turtle.end_fill()

#第5个爱心
turtle.color('pink', 'pink')
turtle.begin_fill()
turtle.hideturtle()
turtle.up()
turtle.goto(313.7, -143)
turtle.down()
turtle.showturtle()
turtle.left(135)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(45)
turtle.circle(17.67,180)
turtle.left(180)
turtle.circle(17.67,180)
turtle.end_fill()

#第6个爱心
turtle.color('pink', 'pink')
turtle.begin_fill()
turtle.hideturtle()
turtle.up()
turtle.goto(420, -153)
turtle.down()
turtle.showturtle()
turtle.right(90)
turtle.right(225)
turtle.forward(30)
turtle.left(90)
turtle.forward(30)
turtle.left(45)
turtle.circle(10.6,180)
turtle.left(180)
turtle.circle(10.6,180)
turtle.end_fill()

#画右边的小人
turtle.hideturtle()
turtle.color('dimgray')
turtle.up()
turtle.goto(651.28, -255)
turtle.down()
turtle.showturtle()
turtle.goto(550,-200)
turtle.goto(550,-120)
turtle.left(90)
turtle.circle(35)
turtle.goto(550,-200)
turtle.left(180)
turtle.forward(40)
turtle.left(90)
turtle.forward(60)
turtle.hideturtle()
turtle.up()
turtle.goto(550,-160)
turtle.down() 
turtle.showturtle()
turtle.right(90)
turtle.forward(55)
turtle.left(45)
turtle.forward(20)
turtle.hideturtle()
turtle.up() 
turtle.goto(550, -145)
turtle.down()
turtle.showturtle()
turtle.right(45)
turtle.forward(55)
turtle.right(45)
turtle.forward(20)

#画气球线和气球
#第一个气球
turtle.color('pink')
turtle.hideturtle()
turtle.up()
turtle.goto(235, -133)
turtle.down()
turtle.showturtle()
turtle.goto(245, 0)
turtle.right(135)
turtle.circle(35)
#第2个气球
turtle.hideturtle()
turtle.up()
turtle.goto(235, -133)
turtle.down()
turtle.showturtle()
turtle.goto(105, 80)
turtle.circle(40)
#第3个气球
turtle.hideturtle()
turtle.up()
turtle.goto(347, -133)
turtle.down()
turtle.showturtle()
turtle.goto(367, 0)
turtle.circle(35)
#第4一个气球
turtle.hideturtle()
turtle.up()
turtle.goto(337, -133)
turtle.down()
turtle.showturtle()
turtle.goto(317, 80)
turtle.circle(40)
#写字LOVE
turtle.pencolor("GREEN")
turtle.penup()
turtle.goto(245,10)
turtle.write("O",move=False,align='center',font=("微软雅黑",30,'normal'))


turtle.pencolor("PURPLE")
turtle.penup()
turtle.goto(105,90)
turtle.write("L",move=False,align='center',font=("微软雅黑",30,'normal'))

turtle.pencolor("YELLOW")
turtle.penup()
turtle.goto(367,10)
turtle.write("E",move=False,align='center',font=("微软雅黑",30,'normal'))

turtle.pencolor("ORANGE")
turtle.penup()
turtle.goto(317, 90)
turtle.write("V",move=False,align='center',font=("微软雅黑",30,'normal'))


#写送给谁
turtle.pencolor("indianred")
turtle.penup()
turtle.goto(300, 200)
turtle.write(str,move=False,align='center',font=("方正舒体",30,'normal'))


turtle.up()
turtle.goto(-400,300)
turtle.down()
turtle.fillcolor("grey")
turtle.pencolor("grey")
turtle.right(90)
turtle.pensize(8)
turtle.forward(600)

turtle.begin_fill()
turtle.fillcolor("silver")
turtle.pensize(1)
turtle.right(90)
turtle.forward(80)
turtle.left(90)
turtle.forward(10)
turtle.right(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.forward(224)
turtle.left(90)
turtle.forward(10)
turtle.left(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(10)
turtle.left(90)
turtle.forward(80)
turtle.end_fill()

turtle.pensize(1)
turtle.right(90)
turtle.forward(400)
turtle.right(90)

#红旗
turtle.up()
turtle.goto(-400,300)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("red")
turtle.pencolor("red")
for i in range(2):
 turtle.forward(280)
 turtle.right(90)
 turtle.forward(200)
 turtle.right(90)
turtle.end_fill()

#大星星
turtle.up()
turtle.goto(-370,245)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")
for x in range(5):
 turtle.forward(50)
 turtle.right(144)
turtle.end_fill()

#小星星
down(-300,280)
down(-270,260)
down(-270,220)
down(-300,200)

turtle.pencolor("black")

turtle.color("orangered")

turtle.up()
turtle.goto(60,250)
turtle.down()
turtle.write("热烈庆祝70周年华诞!",font = ("Times", 40, "bold"))


turtle.hideturtle()
turtle.done()




效果图:(喜欢记得点个赞,谢谢支持!)
Python-turtle模块绘图(升国旗)

本文地址:https://blog.csdn.net/m0_45069853/article/details/107446550