-
Notifications
You must be signed in to change notification settings - Fork 0
/
sun.py
52 lines (46 loc) · 1.48 KB
/
sun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import turtle
import math
from math import*
screen=turtle.Screen()
screen.tracer(50)
sun = turtle.Turtle()#turtle object for sun
sun.shape('circle')#shape of sun
sun.color('yellow')#color of sun
class Planet(turtle.Turtle):
def __init__(self,name,radius, color):#initialize function
super().__init__(shape='circle')
self.name = name
self.radius = radius
self.c = color
self.color(self.c)
self.up()
self.pd()
self.angle = 0
def move(self):
x = self.radius*cos(self.angle) # Angle in radians
y = self.radius*sin(self.angle)
self.goto(sun.xcor()+x,sun.ycor()+y)
# making plantes
mercury = Planet("Mercury",40, 'grey')
venus = Planet("Venus",80, 'orange')
earth=Planet("Earth",100,'blue')
mars = Planet("Mars",150, 'red')
jupiter=Planet("Jupiter",180, 'brown')
saturn=Planet("Saturn",230, 'pink')
uranus=Planet("Uranus",250, 'light blue')
neptune=Planet("Neptune",280, 'black')
#adding planets to a list
myList = [ mercury, venus,earth, mars,jupiter,saturn,uranus,neptune]
while True:#while statement
screen.update()#updating the screen
for i in myList:
i.move()#moving the elements of the list
# Increase the angle by 0.0x radians
mercury.angle += 0.05
venus.angle += 0.03
earth.angle += 0.01
mars.angle += 0.007
jupiter.angle += 0.02
saturn.angle += 0.018
uranus.angle += 0.016
neptune.angle += 0.005