-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy path3D_Solar_System_Viewer.rb
63 lines (51 loc) · 1.46 KB
/
3D_Solar_System_Viewer.rb
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
53
54
55
56
57
58
59
60
61
62
63
require 'ruby-processing'
class SolarSystemSketch < Processing::App
def setup
size(800, 800, P3D)
background(255)
no_loop
end
def draw
background(255)
draw_solar_system
end
def draw_solar_system
data = {
'Name' => ['Sun', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'],
'Type' => ['Star', 'Planet', 'Planet', 'Planet', 'Planet', 'Planet', 'Planet', 'Planet', 'Planet'],
'x' => [0, 0.39, 0.72, 1.0, 1.52, 5.20, 9.58, 19.18, 30.07],
'y' => [0, 0, 0, 0, 0, 0, 0, 0, 0],
'z' => [0, 0, 0, 0, 0, 0, 0, 0, 0]
}
df = create_dataframe(data)
# Plot the Sun
sun = df[df['Name'] == 'Sun']
draw_planet(sun['x'][0], sun['y'][0], sun['z'][0], 500, color(255, 255, 0))
# Plot the planets
planets = df[df['Type'] == 'Planet']
planets.each do |planet|
draw_planet(planet['x'], planet['y'], planet['z'], 50, color(0, 0, 255))
end
# Set the axis labels
lights
translate(width / 2, height / 2, -200)
rotate_x(PI / 6)
rotate_y(PI / 6)
# Set the title
text_align(CENTER)
text('Solar System', 0, -300, 0)
end
def create_dataframe(data)
require 'pandas'
pd = Pandas::DataFrame
pd.new(data)
end
def draw_planet(x, y, z, size, color)
push_matrix
translate(x * 100, y * 100, z * 100)
fill(color)
sphere(size)
pop_matrix
end
end
SolarSystemSketch.new(title: 'Solar System', width: 800, height: 800)