太阳地球月亮旋转曲线测试程序
"""太阳地球月亮旋转曲线测试程序
简单的利用三角函数制作的螺旋曲线。
本程序需要gameturtle0.2版支持。
"""
from gameturtle import *
from math import cos,sin,radians
# 新建窗口
root = Tk()
root.geometry('640x640+0+30')
root.title('太阳地球月亮by李兴球')
# 铺设画布
cv = Canvas(width=640,height=640,bg='black')
cv.pack()
# 新建太阳
sunpic = Image.new("RGBA",(30,30),color='red')
sun = GameTurtle(cv,sunpic)
# 新建地球
earthpic = Image.new("RGBA",(50,50),color='green')
earth = GameTurtle(cv,earthpic,pos=(520,320))
earth.radius = 200 # 自定义属性
earth.angle = 0 # 自定义属性
# 新建月亮
moonpic = Image.new("RGBA",(10,10),color='white')
moon = GameTurtle(cv,moonpic)
moon.radius = 80 # 自定义属性
moon.angle = 0 # 自定义属性
moon.pencolor('cyan')
frames = 0
while True:
sun.right(0.01)
x = cv.center()[0] + earth.radius * cos(radians(earth.angle))
y = cv.center()[1] + earth.radius * sin(radians(earth.angle))
earth.goto(x,y)
earth.angle += 0.01
x = earth.position()[0] + moon.radius * cos(radians(moon.angle))
y = earth.position()[1] + moon.radius * sin(radians(moon.angle))
moon.goto(x,y)
if frames % 120 == 0 : moon.dot()
moon.angle += 0.05
cv.update()
frames += 1
本作品采用《CC 协议》,转载必须注明作者和本文链接
No source of
gameturtle
for all recent posts !