mirror of
https://gitlab.com/MisterBiggs/gravities-of-the-solar-system.git
synced 2025-06-15 14:46:40 +00:00
lots of reformatting
This commit is contained in:
parent
17dce0b6a8
commit
235139125d
BIN
gravities.gif
Normal file
BIN
gravities.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 MiB |
70
gravities.jl
70
gravities.jl
@ -1,6 +1,12 @@
|
||||
#=
|
||||
Visualization of the gravities of different bodies around the solar system inspired by Dr. James O'Donoghue visualization here: https://twitter.com/physicsJ/status/1414233142861262855
|
||||
|
||||
Planetary data from NASA: https://nssdc.gsfc.nasa.gov/planetary/factsheet/
|
||||
=#
|
||||
|
||||
using Javis
|
||||
|
||||
# Planetary data from: https://nssdc.gsfc.nasa.gov/planetary/factsheet/
|
||||
|
||||
diameters = Dict(
|
||||
"Mercury" => 4879,
|
||||
"Venus" => 12104,
|
||||
@ -63,9 +69,12 @@ font_height = 25
|
||||
width = 1500
|
||||
|
||||
# Give room for header and footer
|
||||
top_padding = font_height * 3
|
||||
bottom_padding = font_height * 5 + 50
|
||||
top_padding = font_height
|
||||
bottom_padding =
|
||||
font_height * 5 + 50 + maximum(ceil.(Int, [p.radius * 5 for p in planets])) + 1
|
||||
total_height = height + top_padding + bottom_padding
|
||||
start_height = total_height / 2 - top_padding * 4
|
||||
|
||||
|
||||
myvideo = Video(width, total_height)
|
||||
Background(1:frames, ground)
|
||||
@ -73,31 +82,51 @@ Background(1:frames, ground)
|
||||
# Determine spacing and make some functions to help space the planets and text
|
||||
spacing = width / (length(planets) + 1)
|
||||
x_calc(planet::Planet) = (planet.position) * spacing - width / 2 + spacing / 2
|
||||
y_calc(planet::Planet) = -height / 2 + planet.radius
|
||||
y_height(row) = total_height / 2 - font_height / 2 - font_height * row
|
||||
|
||||
for planet in planets
|
||||
|
||||
# 1km and 0km lines have to be drawn first to be under everything
|
||||
Object(
|
||||
1:frames,
|
||||
JLine(
|
||||
Point(-width / 2, -start_height),
|
||||
Point(width, -start_height),
|
||||
color = "darkgray",
|
||||
linewidth = 5,
|
||||
),
|
||||
)
|
||||
|
||||
Object(
|
||||
1:frames,
|
||||
JLine(
|
||||
Point(-width / 2, -start_height + height),
|
||||
Point(width, -start_height + height),
|
||||
color = "darkgray",
|
||||
linewidth = 5,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
for planet in planets
|
||||
# Kinematic equations to calculate how many frames each planet will be active
|
||||
t_final = 2 * (height - planet.radius * 2) / planet.gravity |> sqrt
|
||||
t_final = 2 * height / planet.gravity |> sqrt
|
||||
v_final = planet.gravity * t_final
|
||||
frame_final = ceil(Int, t_final * framerate)
|
||||
|
||||
|
||||
|
||||
for f = 1:frame_final
|
||||
|
||||
# Calculate time of current frame for kinematic math
|
||||
time = f / framerate
|
||||
|
||||
# Calculate planets current position
|
||||
planet_y = 0.5 * planet.gravity * time^2 - height / 2
|
||||
planet_y = 0.5 * planet.gravity * time^2 - start_height
|
||||
|
||||
# Set the planets position
|
||||
Object(
|
||||
f:f,
|
||||
JCircle(O, planet.radius, color = planet.color, action = :fill),
|
||||
Point(x_calc(planet), planet_y + planet.radius),
|
||||
Point(x_calc(planet), planet_y),
|
||||
)
|
||||
|
||||
# Update text for planets current state
|
||||
@ -132,7 +161,7 @@ for planet in planets
|
||||
Object(
|
||||
frame_final:frames,
|
||||
JCircle(O, planet.radius, color = planet.color, action = :fill),
|
||||
Point(x_calc(planet), height / 2 - planet.radius),
|
||||
Point(x_calc(planet), -start_height + height),
|
||||
)
|
||||
|
||||
# Set all the text for after the planet is done moving
|
||||
@ -140,7 +169,7 @@ for planet in planets
|
||||
frame_final:frames,
|
||||
@JShape begin
|
||||
fontsize(font_height)
|
||||
sethue("green")
|
||||
sethue("springgreen4")
|
||||
text(planet.name, Point(x_calc(planet), y_height(3)), halign = :center)
|
||||
text(
|
||||
string(planet.gravity, "m/s^2"),
|
||||
@ -166,6 +195,7 @@ for planet in planets
|
||||
1:frame_final,
|
||||
@JShape begin
|
||||
fontsize(font_height)
|
||||
sethue(planet.color)
|
||||
text(planet.name, Point(x_calc(planet), y_height(3)), halign = :center)
|
||||
text(
|
||||
string(planet.gravity, "m/s^2"),
|
||||
@ -175,21 +205,22 @@ for planet in planets
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
|
||||
Object(
|
||||
1:frames,
|
||||
JCircle(O, planet.radius, color = planet.color, action = :fill),
|
||||
Point(x_calc(planet), y_height(4) - planet.radius),
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
# Set the legend text
|
||||
Object(
|
||||
1:frames,
|
||||
@JShape begin
|
||||
fontsize(font_height)
|
||||
x_pt = -width / 2 + 10
|
||||
|
||||
text("1km", Point(x_pt, -height / 2 + font_height), halign = :left)
|
||||
text("0km", Point(x_pt, height / 2), halign = :left)
|
||||
text("1km", Point(x_pt, -start_height - 10), halign = :left)
|
||||
text("0km", Point(x_pt, -start_height + height - 10), halign = :left)
|
||||
|
||||
|
||||
fontsize(font_height * 0.75)
|
||||
@ -203,12 +234,11 @@ Object(
|
||||
sethue("royalblue")
|
||||
text(
|
||||
"Ball Falling 1km on Bodies in the Solar System",
|
||||
Point(0, -height / 2 - font_height * 2),
|
||||
Point(0, -total_height / 2 + font_height * 2.5),
|
||||
halign = :center,
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
render(myvideo; liveview = true)
|
||||
# render(myvideo; pathname = "hacktober.gif")
|
||||
# render(myvideo; pathname = "gravities.mp4")
|
||||
|
BIN
gravities.mp4
BIN
gravities.mp4
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user