Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- class Planets(object): #Lookup why to use object here
- def __init__(self, posx, posy, speed, radius, angle, distance_from_sun):
- self.posx = posx
- self.posy = posy
- self.speed = speed
- self.radius = radius
- self.angle = angle
- self.distance_from_sun = distance_from_sun
- EARTH_650 = 5 #Setting constants of earth to modify for other planets in relation
- EARTH_650 = 5
- #Don't forget moons, look into adding aphelion and perhelion!!!
- #SUN = Planets(650/2, 650/2, EARTH_650*109, EARTH_650*109) #assigning SUN to Planets class, find out how to change color to yellow
- TEST_SUN = Planets(650/2, 650/2, 1, 10, 0.0, 0) #Small dot to help represent other planet's distances
- EARTH = Planets(None, None, .11, 5, 0.0, 30) #All other planet sizes are scaled compared to actual physical earth size
- MERCURY = Planets(None, None, .5, EARTH.radius*.383, 0.0, 10)
- VENUS = Planets(None, None, .1, EARTH.radius*.949, 0.0, 20)
- MARS = Planets(None, None, .1, EARTH.radius*.532, 0.0, 40)
- JUPITER = Planets(None, None, .5, EARTH.radius*11.21, 0.0, 50) #Jupiter and following have a ring system
- SATURN = Planets(None, None, .1, EARTH.radius*9.45, 0.0, 60)
- URANUS = Planets(None, None, .1, EARTH.radius*4.01, 0.0, 70)
- NEPTUNE = Planets(None, None, .1, EARTH.radius*4.01, 0.0, 80)
- #PLUTO = Planets(650/2, 650/2, 100, 100, 255)
- def setup(): #Static variables defined for entirety of runtime
- size(650, 650, P3D) #P3D/P2D optimize 3D/2D build programs
- noStroke()
- frameRate(30)
- i = 0
- def draw():
- img = loadImage('background.jpg')
- background(img)
- #Add option to click on planet and see details on it, translate z+1 over multiple frames till a desired scalar is achieved
- def planet_Orbit(PLANET): #Add test that orbits with its planet
- global i
- PLANET.angle += PLANET.speed
- cosval = PLANET.distance_from_sun * cos(PLANET.angle) #Together create a circular orbit, whilst one just portrays sin/cos motion
- sinval = PLANET.distance_from_sun * sin(PLANET.angle)
- x = (cosval * PLANET.radius) + TEST_SUN.posx #Adding the TEST_SUN positions to identify where to orbit around
- y = (sinval * PLANET.radius) + TEST_SUN.posy
- sphere(PLANET.radius)
- #Might make NEPTUNE.pos variables irrelevant check later
- directionalLight(255, 255, 255,1, 0, 0)
- translate((x-(650/2)), (y-(650/2)))
- if i == 0:
- fill(random(255), random(255), random(255))
- i += 1
- else:
- pass
- print PLANET, x, y
- sphere(TEST_SUN.radius)
- translate(TEST_SUN.posx, TEST_SUN.posy)
- #Can only do light on 8 objects on a screen hence why TEST_SUN is not shaded
- planet_Orbit(MERCURY)
- #planet_Orbit(VENUS)
- #planet_Orbit(EARTH)
- #planet_Orbit(MARS)
- planet_Orbit(JUPITER)
- #planet_Orbit(SATURN)
- #planet_Orbit(URANUS)
- #planet_Orbit(NEPTUNE)
Advertisement
Add Comment
Please, Sign In to add comment