-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimated Solar System.py
More file actions
46 lines (40 loc) · 1.41 KB
/
Animated Solar System.py
File metadata and controls
46 lines (40 loc) · 1.41 KB
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
import turtle
import math
# Set up the screen
screen = turtle.Screen()
screen.setup(width=800, height=600)
screen.bgcolor("black")
# Create the Turtle object for the sun
sun_turtle = turtle.Turtle()
sun_turtle.shape("circle")
sun_turtle.color("yellow")
sun_turtle.penup()
sun_turtle.goto(0, 0)
sun_turtle.pendown()
# Define planet properties (name, distance from the sun, radius, color, and speed)
planets = [
{"name": "Mercury", "distance": 50, "radius": 5, "color": "gray", "speed": 2},
{"name": "Venus", "distance": 100, "radius": 10, "color": "orange", "speed": 1.5},
{"name": "Earth", "distance": 150, "radius": 12, "color": "blue", "speed": 1},
# Add more planets here
]
# Create the Turtle objects for planets
planet_turtles = []
for planet in planets:
planet_turtle = turtle.Turtle()
planet_turtle.shape("circle")
planet_turtle.color(planet["color"])
planet_turtle.penup()
planet_turtle.goto(planet["distance"], 0)
planet_turtle.pendown()
planet_turtles.append(planet_turtle)
# Animate the planets' orbits
while True:
for planet, planet_turtle in zip(planets, planet_turtles):
angle = planet_turtle.heading() + planet["speed"]
planet_turtle.setheading(angle)
x = planet["distance"] * math.cos(math.radians(angle))
y = planet["distance"] * math.sin(math.radians(angle))
planet_turtle.goto(x, y)
# Close the window on click
screen.exitonclick()