-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathearthmoon.py
36 lines (24 loc) · 1018 Bytes
/
earthmoon.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
# Name: Jack Chou
# Date: 10/22/2023
# Purpose: Example for CS 1 Lab Assignment 2.
# Source: https://cs.dartmouth.edu/kvasanta/cs1/sa11/index.html
from cs1lib import *
from system import System
from body import Body
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 400
TIME_SCALE = 100000 # real seconds per simulation second
PIXELS_PER_METER = 3 / 1e7 # distance scale for the simulation
FRAMERATE = 30 # frames per second
TIMESTEP = 1.0 / FRAMERATE # time between drawing each frame
def main():
set_clear_color(0, 0, 0) # black background
clear()
# Draw the system in its current state.
earth_moon.draw(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, PIXELS_PER_METER)
# Update the system for its next state.
earth_moon.update(TIMESTEP * TIME_SCALE)
earth = Body(5.9736e24, 0, 0, 0, 0, 24, 0, 0, 1) # blue earth
moon = Body(7.3477e22, 3.84403e8, 0, 0, 1022, 4, 1, 1, 1) # white moon
earth_moon = System([earth, moon])
start_graphics(main, 2400, framerate=FRAMERATE)