Advertisement
bwukki

Untitled

Aug 1st, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.21 KB | None | 0 0
  1. #NOTE! use (7910000000000,7910000000000,7910000000000)  to see entire system, delete one zero from each dimension to see just the center of solar system
  2.  
  3.  
  4. from visual import *
  5. scene=display(title="Universe!",x=0, y=0, width=800,
  6.               height=600,range=vector(7910000000000,7910000000000,7910000000000),
  7.               center=vector(0,0,0))
  8.  
  9. t = 0.0
  10. dt = 1*10**5 #change in time
  11.  
  12. #initial positions of planets and sun
  13. sEarth = vector(150000000000.0,0.0,0.0)
  14. sMoon = vector(sEarth.x + 384472282.0, 0.0, 0.0)
  15. sSun = vector(0.0,0.0,0.0)
  16. sMars = vector(228000000000,0.0,0.0)
  17. sVenus = vector(108000000000,0.0,0.0)
  18. sUranus = vector(2880000000000,0.0,0.0)
  19. sNeptune = vector(4500000000000,0.0,0.0)
  20. sPluto = vector(5910000000000,0.0,0.0)
  21. sJupiter = vector(779000000000,0.0,0.0)
  22. sSaturn = vector(1430000000000,0.0,0.0)
  23. sMercury = vector(57000000000,0.0,0.0)
  24.  
  25. #initial velocities in m/s of the planets orbiting around the sun
  26. vEarth = 30000
  27. vMoon = 1023.41
  28. vSun = 0
  29. vMars = 24077
  30. vVenus = 35020
  31. vUranus = 6810
  32. vNeptune = 5430
  33. vPluto = 4670
  34. vJupiter = 13070
  35. vSaturn = 9690
  36. vMercury = 47870
  37.  
  38. rMoon = 384472282 #distance between earth and moon in m
  39.  
  40. #distance between the sun and planets in m
  41.  
  42. rEarth = 150000000000
  43. rSun = 0
  44. rMars = 228000000000
  45. rVenus = 108000000000
  46. rUranus = 2880000000000
  47. rNeptune = 4500000000000
  48. rPluto = 5910000000000
  49. rJupiter = 779000000000
  50. rSaturn = 1430000000000
  51. rMercury = 57000000000
  52.  
  53. #object creation / making the planets and sun
  54. Moon=sphere(pos=sMoon,radius=4000000,color=color.white, make_trail=True, trail_type="points", interval=10, retain=15)
  55. Earth=sphere(pos=sEarth, radius=90000000, material=materials.earth)
  56. Sun=sphere(pos=sSun,radius=695700000,color=color.orange, make_trail=True, trail_type="points", interval=10, retain=15)
  57. Mars=sphere(pos=sMars,radius=3397000,color=(1,0.7,0.2), make_trail=True, trail_type="points", interval=10, retain=15)
  58. Venus=sphere(pos=sVenus,radius=6052000,color=color.red, make_trail=True, trail_type="points", interval=10, retain=15)
  59. Uranus=sphere(pos=sUranus,radius=25559000,color=color.blue, make_trail=True, trail_type="points", interval=10, retain=15)
  60. Neptune=sphere(pos=sNeptune,radius=24766000,color=(1,0,1), make_trail=True, trail_type="points", interval=10, retain=15)
  61. Pluto=sphere(pos=sPluto,radius=1150000,color=(0.7,0.5,0.5), make_trail=True, trail_type="points", interval=10, retain=15)
  62. Jupiter=sphere(pos=sJupiter,radius=71492000,color=color.yellow, make_trail=True, trail_type="points", interval=10, retain=15)
  63. Saturn=sphere(pos=sSaturn,radius=60268000,color=(0.5,0,0.2), make_trail=True, trail_type="points", interval=10, retain=15)
  64. Mercury=sphere(pos=sMercury,radius=2440000,color=(0.5,0.5,0.5), make_trail=True, trail_type="points", interval=10, retain=15)
  65.  
  66.  
  67.  
  68. while t < 500000000000: #time for program to run, right now just an arbitrarily large number
  69.     rate(100)  # Sets fps to 100, 400 works even better (especially with higher dts) if the computer can handle it
  70.     #the following calculates the position of each planet and updates their position
  71.     sMoon = (cos(vMoon*t/rMoon)*rMoon +cos(vEarth*t/rEarth)*rEarth ,sin(vMoon*t/rMoon)*rMoon+sin(vEarth*t/rEarth)*rEarth,0) #calculates the position of the moon
  72.     Moon.pos=sMoon #updating moon's position
  73.     sEarth = (cos(vEarth*t/rEarth)*rEarth,sin(vEarth*t/rEarth)*rEarth,0)
  74.     Earth.pos = sEarth
  75.     sMars = (cos(vMars*t/rMars)*rMars,sin(vMars*t/rMars)*rMars,0)
  76.     Mars.pos = sMars
  77.     sVenus = (cos(vVenus*t/rVenus)*rVenus,sin(vVenus*t/rVenus)*rVenus,0)
  78.     Venus.pos = sVenus
  79.     sUranus = (cos(vUranus*t/rUranus)*rUranus,sin(vUranus*t/rUranus)*rUranus,0)
  80.     Uranus.pos = sUranus
  81.     sNeptune = (cos(vNeptune*t/rNeptune)*rNeptune,sin(vNeptune*t/rNeptune)*rNeptune,0)
  82.     Neptune.pos = sNeptune
  83.     sPluto = (cos(vPluto*t/rPluto)*rPluto,sin(vPluto*t/rPluto)*rPluto,0)
  84.     Pluto.pos = sPluto
  85.     sJupiter = (cos(vJupiter*t/rJupiter)*rJupiter,sin(vJupiter*t/rJupiter)*rJupiter,0)
  86.     Jupiter.pos = sJupiter
  87.     sSaturn = (cos(vSaturn*t/rSaturn)*rSaturn,sin(vSaturn*t/rSaturn)*rSaturn,0)
  88.     Saturn.pos = sSaturn
  89.     sMercury = (cos(vMercury*t/rMercury)*rMercury,sin(vMercury*t/rMercury)*rMercury,0)
  90.     Mercury.pos = sMercury
  91.  
  92.    
  93.    
  94.    
  95.     t = t + dt #updating time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement