Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Moon, Earth, Sun orbital simulation
- # using Turtle graphics
- # Juhani Kaukoranta 15th June 2018
- from turtle import Turtle
- import math
- # Sun, Earth, Moon initiation
- def Sun_init(size,color):
- Sun = Turtle()
- Sun.hideturtle()
- Sun.color(color)
- Sun.begin_fill()
- Sun.circle(size)
- Sun.end_fill()
- def OrbitCalculation(object1,color1,size1,object2,color2,size2):
- # Earth, Sun initiation
- object1 = Turtle()
- object1.hideturtle()
- object1.color(color1)
- object1.pensize(size1)
- object1.up()
- object2 = Turtle()
- object2.hideturtle()
- object2.color(color2)
- object2.pensize(size2)
- object2.up()
- # Earth, Sun orbit coodinates
- for i in range (0,360):
- xE = 200*math.cos(i*math.pi/180.0)
- yE = 200*math.sin(i*math.pi/180.0)
- object1.setposition(xE,yE)
- object1.down()
- xM = xE+30*math.cos(13.4*i*math.pi/180.0)
- yM = yE+30*math.sin(13.4*i*math.pi/180.0)
- object2.setposition(xM,yM)
- object2.down()
- # Main program
- Sun_init(10,'yellow')
- OrbitCalculation('Earth','green',3,'Moon','blue',2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement