模拟3d星空python_python模拟3D星空动画turtle版右出

以下是部分代码预览:

"""

模拟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) # 添加到星星列表

下载完整源代码与素材,请扫码付款。

VIP免费查看

当前隐藏内容需要支付

59元

已有0人支付

立即购买

你可能感兴趣的:(模拟3d星空python)