以下是部分代码预览:
"""
模拟3D星空-海龟画图版-星星从右边出来,这个程序让很多星星从右边出来,越大的速度越快,越小的速度越慢。所以这样就模拟了一种3D效果。
"""
from turtle import *
from random import random,randint
screen = Screen()
width ,height = 800,600
screen.setup(width,height)
screen.title("模拟3D星空_海龟画图版_作者:李兴球")
screen.bgcolor("black")
screen.mode("logo")
screen.delay(0) # 这里要设为0,否则很卡
t = Turtle(visible = False,shape='circle')
t.color("white")
t.penup()
t.setheading(-90)
t.goto(width/2,randint(-height/2,height/2))
stars = []
for i in range(200):
star = t.clone() # 克隆一个海龟对象
s =random() /3 # s做为新对象的大小的比例
star.shapesize(s,s) # 设定新的星星的大小
star.speed(int(s*10)) # 设定新的星星的速度
star.setx(width/2 + randint(1,width)) # 设置初始x坐标
star.sety( randint(-height/2,height/2)) # 设置初始y坐标
star.showturtle() # 显示海龟对象
stars.append(star) # 添加到星星列表
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

