The program itself
From GeoMod
I do believe that this is the entire program. If you would like any more information see, lurbano-5.memphis.edu/GeoMod for any further questions.
from visual import *
from planet import *
import math
from random import *
from sys import *
class copernicus:
def __init__(self, display=scene):
self.scene = display
self.scene.title = 'Copernican Model'
self.sun_radius = 6.96
self.earth_radius = 6.4
self.earth_sun = 149.60
self.earth_year = 365.25
self.scene.autoscale = 0
self.scene.range = (200,200,200)
self.scene.forward = (0,0.001,-0.9999995)
self.scene.up = (0,0,1)
# Make stars
n=0
while n<100:
sphere(pos=5.0*self.earth_sun*norm(vector(0.5-random(),
0.5-random(),
0.5-random())),
radius = self.sun_radius/2.0,
display = self.scene)
n=n+1
# Make planets, and label them.
self.sun = sphere(pos = (0,0,0),
radius = self.sun_radius,
color = color.yellow,
display = self.scene)
self.lSun = label(pos = self.sun.pos,
xoffset = 20,
yoffset = 20,
opacity = 0,
text = 'Sun',
display = self.scene)
self.earth = planet(pos = (self.earth_sun,0,0),
radius = self.earth_radius,
display = self.scene)
self.lEarth = label(pos = self.earth.pos,
xoffset = 20,
yoffset = 20,
opacity = 0,
text = 'Earth',
display = self.scene)
self.days = label(pos = (-self.earth_sun, -self.earth_sun, 0),
text = 'Day 0',
display = self.scene)
- self.tEarth = curve(pos=self.earth.pos, color=color.yellow, radius = self.earth_radius/2, display=self.scene)
self.dt = 0.2
self.ddt = 0.1
self.t = 0.0
def step(self):
# Update the frame rate and wait for the next frame.
self.t = self.t+self.dt
rate(100)
# Update the positions of planets and labels.
self.earth.change(pos =\
(self.earth_sun*cos(2*pi/self.earth_year*self.t),
self.earth_sun*sin(2*pi/self.earth_year*self.t)*0.5,
0),
sun = self.sun.pos-self.earth.pos)
self.lEarth.pos = self.earth.pos
- self.tEarth.append(pos= self.earth.pos)
# Simulate light from the sun with lights illuminating the scene.
self.scene.lights = [norm(self.sun.pos-self.earth.pos)/2.0,
(0,0,0.5),
(0,0,-0.5)]
# Update the day number display.
self.days.text = 'Day %d' % (self.t)
c = cross(self.scene.forward,vector(1,0,0))
if c == vector(0,0,0):
self.days.pos = self.earth_sun*1.2*vector(0,-1,0)
else:
self.days.pos = \
self.earth_sun*1.2*norm(c)
w = 704+4+4 h = 576+24+4 scene.x = 0 scene.y = 0 scene.width = w scene.height = h
if __name__ == '__main__':
c = copernicus() scene.userzoom = 0 scene.userspin = 0 scene.range = (210,210,210)
print 'Keyboard controls:' print 'v : toggle view' print 'f : faster' print 's : slower' print 'r : reverse' print 'q : quit'
view = 'top'
while 1:
# Process keyboard commands.
while scene.kb.keys:
k = scene.kb.getkey()
if k == 'v':
if view == 'top':
view = 'earth'
scene.range = (150,150,150)
c.earth.change(visible=0)
c.lEarth.visible=0
else:
view = 'top'
scene.range = (210,210,210)
scene.center = (0, 0, 0)
scene.forward = (0, 0.001, -1)
c.earth.change(visible=1)
c.lEarth.visible=1
if k == 'f':
if abs(c.dt) < 20.0:
c.dt = c.dt + c.ddt
if k == 's':
if abs(c.dt) > 0.0:
c.dt = c.dt - c.ddt
if k == 'r':
c.ddt = -c.ddt
c.dt = -c.dt
if k == 'q':
scene.visible = 0
sys.exit(None)
c.step()
if view == 'earth':
scene.center = c.sun.pos
scene.forward = c.sun.pos-c.earth.pos
# pos = c.venus_sun*norm(cross(c.scene.forward,vector(1,0.001,0)))
# pos.z = -abs(pos.z)
# c.days.pos = pos
Once again, this program was basically taken from the website previously mentioned in the documentation. This is not all my doing.
from visual import *
scene.autoscale=1
earth=sphere(color=color.blue, radius=2.5,pos=(3,0,0))
- sun=sphere(pos=(-5,0,0),radius=5, color=color.yellow)
pointer = arrow(pos=(1.3,6.75,0), axis=(0,-5,0), shaftwidth=0.5, color=color.red) ray = cylinder(pos=(-1,1,0), axis=(-10,0,0), radius=0.75)
from visual import *
import math
class planet:
def __init__(self,
pos = vector(0,0,0),
sun = vector(1,0,0), # points at the sun
radius = 1.0,
light = color.white,
dark = (0.2,0.2,0.2),
visible = 1,
fr = None,
display = scene):
self.pos = vector(pos)
self.sun = vector(sun)
self.radius = radius
self.light = light
self.dark = dark
self.visible = visible
self.scene = display
self.frame = frame(pos=vector(pos),
axis = (0,0,1))
if fr != None:
self.frame.frame = fr
# Build the planet from two hemispheres.
V = self.vertices()
self.hemi1 = faces(frame = self.frame,
pos = V,
normal = V,
color = light,
visible = self.visible,
display = self.scene)
V = self.vertices(offset=pi)
self.hemi2 = faces(frame = self.frame,
pos = V,
normal = V,
color = dark,
visible = self.visible,
display = self.scene)
# Orient bright side toward the "sun"
self.frame.rotate(angle=-pi/2) # Default is sun to the right.
if self.sun.x == 0:
self.phase = pi/2*self.sun.y/abs(self.sun.y)
else:
self.phase = atan(self.sun.y/self.sun.x)
if (self.sun.x < 0):
self.phase = self.phase + pi
self.frame.rotate(angle=self.phase)
def vertices(self,
offset=0,
factor=1):
# Generate vertices.
# Every three entries are the vertices of a triangular face
List=[]
for i in arange(0,10,1):
for j in arange(0,10,1):
# These angles describe a four-sided face.
p1=i*pi/10.0 + offset
t1=j*pi/10.0
p2=(i+1)*pi/10.0 + offset
t2=(j+1)*pi/10.0
# Append the first triangle in the four-sided face.
List.append(factor*self.radius*vector((cos(t2),
sin(p1)*sin(t2),
cos(p1)*sin(t2))))
List.append(factor*self.radius*vector((cos(t1),
sin(p1)*sin(t1),
cos(p1)*sin(t1))))
List.append(factor*self.radius*vector((cos(t2),
sin(p2)*sin(t2),
cos(p2)*sin(t2))))
# Append the second triangle in the four-sided face.
List.append(factor*self.radius*vector((cos(t1),
sin(p2)*sin(t1),
cos(p2)*sin(t1))))
List.append(factor*self.radius*vector((cos(t2),
sin(p2)*sin(t2),
cos(p2)*sin(t2))))
List.append(factor*self.radius*vector((cos(t1),
sin(p1)*sin(t1),
cos(p1)*sin(t1))))
return List
def change(self, pos=None, sun=None,
light=None, dark=None, visible=None):
if pos <> None:
self.pos = vector(pos)
self.frame.pos = vector(pos)
if sun <> None:
self.sun = vector(sun)
if self.sun.x == 0:
phase = pi/2*self.sun.y/abs(self.sun.y)
else:
phase = atan(self.sun.y/self.sun.x)
if (self.sun.x < 0):
phase = phase + pi
self.frame.rotate(angle=(phase-self.phase))
self.phase = phase
if light <> None:
self.hemi1.color = light
if dark <> None:
self.hemi2.color = dark
if visible <> None:
self.hemi1.visible = visible
self.hemi2.visible = visible
if __name__ == '__main__':
a = planet(light=color.yellow,dark=color.blue)
b = planet(pos=(3,0,0),
sun=(1,1,0),
radius = 2.0)
c = planet(pos=(0,-3,0),
sun=(0,1,0))
n=0
l=0
while 1:
rate(10)
n=n+1
t=n*0.1
c.change(sun=vector(cos(t),sin(t),0))
l=l+2
if l>100:
l=30
b.change(dark=(l/100.0,l/100.0,l/100.0))

