用户:
果敢的超能鸭viwX查看:0 回复:0 评论:0 创建时间:2021-05-05T17:14:14
【作品展示】

【作品介绍】
星空中,除了地球,还有许许多多的星球。
【作品源代码】
import turtle
import random
pen = turtle.Pen()
turtle.bgcolor("black")
pen.speed(0)
pen.up()
x = random.randint(-500, 500)
y = random.randint(-500, 500)
# 星星
def star(num, shape, color, x, y):
for i in range(num):
pen.dot(shape, color)
pen.goto(x, y)
x = random.randint(-500, 500)
y = random.randint(-500, 500)
# 画笔移动(不留痕迹)
def going(x, y):
pen.up()
pen.goto(x, y)
pen.down()
# 星球1
def one_planet():
pen.color("blue")
pen.pensize(5)
going(-200,150)
pen.circle(100)
going(-350,310)
pen.setheading(70)
pen.pensize(2)
# 椭圆
a = 1
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90: # 控制a的变化
a = a-0.5
pen.left(3) # 向左转3度
pen.forward(a) # 向前走a的步长
else:
a = a+0.5
pen.left(3)
pen.forward(a)
going(-320, 300)
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90: # 控制a的变化
a = a-0.4
pen.left(3) # 向左转3度
pen.forward(a) # 向前走a的步长
else:
a = a+0.4
pen.left(3)
pen.forward(a)
# 月球
def moon():
pen.fillcolor("yellow")
pen.color("yellow")
going(210, 100)
pen.begin_fill()
for i in range(120):
pen.fd(5)
pen.left(3)
pen.end_fill()
going(160,100)
pen.color("black")
pen.fillcolor("black")
pen.begin_fill()
for i in range(120):
pen.fd(5)
pen.left(3)
pen.end_fill()
# 太阳
def sun():
pen.color("gold")
going(-100,-160)
for i in range(100):
pen.fd(200)
pen.lt(136)
# 调用函数
star(100, 3, 'yellow', random.randint(-500, 500), random.randint(-500, 500))
one_planet()
moon()
sun()
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn