Advertisement
jukaukor

MoonEarthSun_Turtle.py

Jun 8th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. # Moon, Earth, Sun orbital simulation
  2. # using Turtle graphics
  3. # Juhani Kaukoranta 8th June 2018
  4.  
  5. from turtle import Turtle
  6. import math
  7.  
  8. # Moon, Sun, Earth initiation
  9.  
  10. Moon = Turtle()
  11. Moon.hideturtle()
  12. Earth = Turtle()
  13. Earth.hideturtle()
  14. Sun = Turtle()
  15. Sun.color("yellow")
  16. Sun.begin_fill()
  17. Sun.hideturtle()
  18. Sun.circle(10)
  19. Sun.end_fill()
  20. Moon.color("blue")
  21. Moon.pensize(2)
  22. Earth.color("green")
  23. Earth.pensize(6)
  24. Moon.up()
  25. Moon.setposition(230,0)
  26. Moon.down()
  27. Earth.up()
  28. Earth.setposition(200,0)
  29. Earth.down()
  30.  
  31. # Earth, Sun orbit calculations
  32.  
  33. for i in range (0,360):
  34. xM = 200*math.cos(i*math.pi/180.0)+30*math.cos(13.4*i*math.pi/180.0)
  35. yM = 200*math.sin(i*math.pi/180.0)+30*math.sin(13.4*i*math.pi/180.0)
  36. Moon.setposition(xM,yM)
  37. xE = 200*math.cos(i*math.pi/180.0)
  38. yE = 200*math.sin(i*math.pi/180.0)
  39. Earth.setposition(xE,yE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement