Advertisement
jukaukor

MoonEarthSun_Turtle_Animation.py

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