用户:嘤嘤怪哟查看:0 回复:1 评论:0 创建时间:2021-05-15T21:44:01
【作品展示】

【作品介绍】
本次作品在上次基础上完善了用户体验,加入了与用户选择的过程,用户可以在星空和祝福直接进行选择,主要是运用了海龟库的画图功能,和def函数,祝中国航天越来越棒!
【作品源代码】
from turtle import *
from random import random, randint
def Stars():
printer = Turtle()
screen = Screen()
width, height = 800, 600
screen.setup(width, height)
screen.bgcolor("black")
screen.mode("logo")
screen.delay(0)
printer.hideturtle()
printer.penup()
printer.color('white')
printer.goto(-100, -150)
t = Turtle(visible=False, shape='circle')
t.pencolor("white") # 设置画笔的颜色
t.fillcolor("white") # 设置图形填充颜色
t.penup() # 抬起画笔
t.setheading(-90) # 设置当前朝向角度
t.goto(width/2, randint(-height/2, height/2)) # 把画笔移动到定点
stars = []
for i in range(300):
star = t.clone()
s = random()/3
if s > 0.01 and s < 0.03:
star.pencolor("black")
star.fillcolor("black")
elif s > 0.03 and s < 0.04:
star.pencolor("lightcoral")
star.fillcolor("lightcoral")
elif s > 0.05 and s < 0.1:
star.pencolor("green")
star.fillcolor("green")
elif s > 0.15 and s < 0.16:
star.pencolor("yellow")
star.fillcolor("yellow")
elif s > 0.19 and s < 0.2:
star.pencolor("red")
star.fillcolor("red")
elif s > 0.21 and s < 0.22:
star.pencolor("purple")
star.fillcolor("purple")
elif s > 0.29 and s < 0.3:
star.pencolor("darkorange")
star.fillcolor("darkorange")
elif s > 0.31 and s < 0.32:
star.pencolor("red")
star.fillcolor("yellow")
elif s > 0.32 and s < 0.33:
star.pencolor("yellow")
star.fillcolor("white")
star.shapesize(s, s)
star.speed(int(s*30)) # 设置画笔移动速度,画笔绘制的速度范围[0,10]整数,数字越大越快
star.setx(width/2 + randint(1, width)) # 将当前x轴移动到指定位置
star.sety(randint(-height/2, height/2)) # 将当前y轴移动到指定位置
stars.append(star)
i = 0
while True:
i += 0
for star in stars:
star.setx(star.xcor() - 3 * star.speed())
if star.xcor() < -width/2:
star.hideturtle()
star.setx(width/2 + randint(1, width))
star.sety(randint(-height/2, height/2))
star.showturtle()
if i >= 100:
break
def love():
printer = Turtle()
printer.speed(0)
def go_to(x, y):
printer.up()
printer.goto(x, y)
printer.down()
def head(x, y, r):
go_to(x, y)
printer.circle(r)
leg(x, y)
def leg(x, y):
printer.right(90)
printer.forward(180)
printer.right(30)
printer.forward(100)
printer.left(120)
go_to(x, y-180)
printer.forward(100)
printer.right(120)
printer.forward(100)
printer.left(120)
hand(x, y)
def hand(x, y):
go_to(x, y-60)
printer.forward(100)
printer.left(60)
printer.forward(100)
go_to(x, y - 90)
printer.right(60)
printer.forward(100)
printer.right(60)
printer.forward(100)
printer.left(60)
eye(x, y)
def eye(x, y):
go_to(x-50, y+130)
printer.right(90)
printer.forward(50)
go_to(x+40, y+130)
printer.forward(50)
printer.left(90)
def big_Circle(size):
for i in range(150):
printer.forward(size)
printer.right(0.3)
def line(size):
printer.forward(51*size)
def 喵all_Circle(size):
for i in range(210):
printer.forward(size)
printer.right(0.786)
def heart(x, y, size):
go_to(x, y)
printer.left(150)
printer.begin_fill()
line(size)
big_Circle(size)
喵all_Circle(size)
printer.left(120)
喵all_Circle(size)
big_Circle(size)
line(size)
printer.end_fill()
def main():
printer.pensize(2)
printer.color('red', 'pink')
head(-120, 100, 100)
heart(250, -80, 1)
go_to(200, -300)
printer.write("To: 中国航天", move=True,
align="left", font=("楷体", 20, "normal"))
done()
main()
def Main():
while True:
print("请自行打开画图界面,谢谢")
a = int(input("中国的航天事业发展迅速,你是想领路星空还是表达祝福呢?输入1即可观看唯美星空,输入2即可表达祝福"))
if a == 1:
Stars()
break
if a == 2:
love()
break
else:
print("只可以输入1或2哦请重新输入")
Main()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn