Guest User

Orbits

a guest
Dec 17th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. import math
  2.  
  3. class Planets(object): #Lookup why to use object here
  4. def __init__(self, posx, posy, speed, radius, angle, distance_from_sun):
  5. self.posx = posx
  6. self.posy = posy
  7. self.speed = speed
  8. self.radius = radius
  9. self.angle = angle
  10. self.distance_from_sun = distance_from_sun
  11.  
  12.  
  13. EARTH_650 = 5 #Setting constants of earth to modify for other planets in relation
  14. EARTH_650 = 5
  15.  
  16. #Don't forget moons, look into adding aphelion and perhelion!!!
  17.  
  18. #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
  19. TEST_SUN = Planets(650/2, 650/2, 1, 10, 0.0, 0) #Small dot to help represent other planet's distances
  20. EARTH = Planets(None, None, .11, 5, 0.0, 30) #All other planet sizes are scaled compared to actual physical earth size
  21.  
  22. MERCURY = Planets(None, None, .5, EARTH.radius*.383, 0.0, 10)
  23. VENUS = Planets(None, None, .1, EARTH.radius*.949, 0.0, 20)
  24. MARS = Planets(None, None, .1, EARTH.radius*.532, 0.0, 40)
  25. JUPITER = Planets(None, None, .5, EARTH.radius*11.21, 0.0, 50) #Jupiter and following have a ring system
  26. SATURN = Planets(None, None, .1, EARTH.radius*9.45, 0.0, 60)
  27. URANUS = Planets(None, None, .1, EARTH.radius*4.01, 0.0, 70)
  28. NEPTUNE = Planets(None, None, .1, EARTH.radius*4.01, 0.0, 80)
  29. #PLUTO = Planets(650/2, 650/2, 100, 100, 255)
  30.  
  31.  
  32. def setup(): #Static variables defined for entirety of runtime
  33.  
  34. size(650, 650, P3D) #P3D/P2D optimize 3D/2D build programs
  35. noStroke()
  36. frameRate(30)
  37.  
  38.  
  39. i = 0
  40. def draw():
  41. img = loadImage('background.jpg')
  42. background(img)
  43.  
  44.  
  45. #Add option to click on planet and see details on it, translate z+1 over multiple frames till a desired scalar is achieved
  46. def planet_Orbit(PLANET): #Add test that orbits with its planet
  47. global i
  48.  
  49. PLANET.angle += PLANET.speed
  50.  
  51. cosval = PLANET.distance_from_sun * cos(PLANET.angle) #Together create a circular orbit, whilst one just portrays sin/cos motion
  52. sinval = PLANET.distance_from_sun * sin(PLANET.angle)
  53.  
  54. x = (cosval * PLANET.radius) + TEST_SUN.posx #Adding the TEST_SUN positions to identify where to orbit around
  55. y = (sinval * PLANET.radius) + TEST_SUN.posy
  56. sphere(PLANET.radius)
  57.  
  58. #Might make NEPTUNE.pos variables irrelevant check later
  59. directionalLight(255, 255, 255,1, 0, 0)
  60. translate((x-(650/2)), (y-(650/2)))
  61.  
  62. if i == 0:
  63. fill(random(255), random(255), random(255))
  64. i += 1
  65. else:
  66. pass
  67.  
  68. print PLANET, x, y
  69.  
  70.  
  71. sphere(TEST_SUN.radius)
  72. translate(TEST_SUN.posx, TEST_SUN.posy)
  73.  
  74.  
  75. #Can only do light on 8 objects on a screen hence why TEST_SUN is not shaded
  76.  
  77. planet_Orbit(MERCURY)
  78. #planet_Orbit(VENUS)
  79. #planet_Orbit(EARTH)
  80. #planet_Orbit(MARS)
  81. planet_Orbit(JUPITER)
  82. #planet_Orbit(SATURN)
  83. #planet_Orbit(URANUS)
  84. #planet_Orbit(NEPTUNE)
Advertisement
Add Comment
Please, Sign In to add comment