skymap 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ CAPTION_SIZE_RATIO = 0.028
6
+
7
+ Caption = Data.define(:position, :text, :size, :kind) do
8
+ def self.size_for(canvas)
9
+ CAPTION_SIZE_RATIO * canvas.radius
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ Ecliptic = Data.define(:points, :width)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ Moon = Data.define(:center, :radius, :illuminated_fraction, :rotation)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ Planet = Data.define(:center, :radius)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ Sun = Data.define(:center, :radius)
6
+ end
7
+ end
@@ -10,6 +10,15 @@ module Skymap
10
10
  HORIZON_WIDTH = 3
11
11
  STAR_COLOR = "#ffffff"
12
12
  LINE_COLOR = "#46689c"
13
+ BOUNDARY_COLOR = "#2b3f5e"
14
+ BOUNDARY_DASH_RATIO = 4
15
+ ECLIPTIC_COLOR = "#8c7a3a"
16
+ PLANET_COLOR = "#ffe6b3"
17
+ SUN_COLOR = "#ffd34d"
18
+ MOON_COLOR = "#f1ecd6"
19
+ MOON_SHADOW_COLOR = "#232a35"
20
+ MOON_SHADOW_OPACITY = 0.6
21
+ CAPTION_COLORS = {constellation: "#6f8fc2", planet: PLANET_COLOR}
13
22
  LABEL_COLOR = HORIZON_COLOR
14
23
  LABEL_FONT = "sans-serif"
15
24
 
@@ -35,9 +44,15 @@ module Skymap
35
44
 
36
45
  elements.each do |element|
37
46
  case element
47
+ when Boundary then draw_boundary(svg, element)
48
+ when Caption then draw_caption(svg, element)
38
49
  when Line then draw_line(svg, element)
39
50
  when Dot then draw_dot(svg, element)
51
+ when Ecliptic then draw_ecliptic(svg, element)
40
52
  when Label then draw_label(svg, element)
53
+ when Moon then draw_moon(svg, element)
54
+ when Planet then draw_planet(svg, element)
55
+ when Sun then draw_sun(svg, element)
41
56
  else raise ArgumentError, "unknown element: #{element.class}"
42
57
  end
43
58
  end
@@ -59,6 +74,32 @@ module Skymap
59
74
  )
60
75
  end
61
76
 
77
+ def draw_boundary(svg, boundary)
78
+ dash = (boundary.width * BOUNDARY_DASH_RATIO).round(2)
79
+
80
+ svg.polyline(
81
+ points: boundary.points.map { |point|
82
+ "#{point.x.round(2)},#{point.y.round(2)}"
83
+ }.join(" "),
84
+ fill: "none",
85
+ stroke: BOUNDARY_COLOR,
86
+ stroke_width: boundary.width.round(2),
87
+ stroke_dasharray: "#{dash} #{dash}"
88
+ )
89
+ end
90
+
91
+ def draw_ecliptic(svg, ecliptic)
92
+ svg.polyline(
93
+ points: ecliptic.points.map { |point|
94
+ "#{point.x.round(2)},#{point.y.round(2)}"
95
+ }.join(" "),
96
+ fill: "none",
97
+ stroke: ECLIPTIC_COLOR,
98
+ stroke_width: ecliptic.width.round(2),
99
+ stroke_linejoin: "round"
100
+ )
101
+ end
102
+
62
103
  def draw_dot(svg, dot)
63
104
  svg.circle(
64
105
  cx: dot.center.x.round(2),
@@ -68,7 +109,59 @@ module Skymap
68
109
  )
69
110
  end
70
111
 
112
+ def draw_planet(svg, planet)
113
+ svg.circle(
114
+ cx: planet.center.x.round(2),
115
+ cy: planet.center.y.round(2),
116
+ r: planet.radius.round(2),
117
+ fill: PLANET_COLOR
118
+ )
119
+ end
120
+
121
+ def draw_sun(svg, sun)
122
+ svg.circle(
123
+ cx: sun.center.x.round(2),
124
+ cy: sun.center.y.round(2),
125
+ r: sun.radius.round(2),
126
+ fill: SUN_COLOR
127
+ )
128
+ end
129
+
130
+ def draw_moon(svg, moon)
131
+ x = moon.center.x.round(2)
132
+ y = moon.center.y.round(2)
133
+ radius = moon.radius.round(2)
134
+ fraction = moon.illuminated_fraction
135
+ terminator = (radius * (1 - 2 * fraction).abs).round(2)
136
+ bulge = (fraction > 0.5) ? 1 : 0
137
+ top = "#{x},#{(y - radius).round(2)}"
138
+ bottom = "#{x},#{(y + radius).round(2)}"
139
+ lit = "M #{top} A #{radius},#{radius} 0 0 1 #{bottom} " \
140
+ "A #{terminator},#{radius} 0 0 #{bulge} #{top} Z"
141
+
142
+ svg.build do
143
+ g(transform: "rotate(#{moon.rotation.round(2)} #{x} #{y})") do
144
+ circle(
145
+ cx: x,
146
+ cy: y,
147
+ r: radius,
148
+ fill: MOON_SHADOW_COLOR,
149
+ fill_opacity: MOON_SHADOW_OPACITY
150
+ )
151
+ path(d: lit, fill: MOON_COLOR)
152
+ end
153
+ end
154
+ end
155
+
71
156
  def draw_label(svg, label)
157
+ draw_text(svg, label, LABEL_COLOR)
158
+ end
159
+
160
+ def draw_caption(svg, caption)
161
+ draw_text(svg, caption, CAPTION_COLORS.fetch(caption.kind))
162
+ end
163
+
164
+ def draw_text(svg, label, fill)
72
165
  svg.text(
73
166
  label.text,
74
167
  x: label.position.x.round(2),
@@ -77,7 +170,7 @@ module Skymap
77
170
  font_family: LABEL_FONT,
78
171
  text_anchor: "middle",
79
172
  dominant_baseline: "central",
80
- fill: LABEL_COLOR
173
+ fill: fill
81
174
  )
82
175
  end
83
176
  end
data/lib/skymap/star.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skymap
4
- Star = Data.define(:hr, :equatorial_coordinates, :magnitude)
4
+ Star = Data.define(:hr, :equatorial_coordinates, :magnitude) do
5
+ def self.by_hr(stars)
6
+ stars.to_h { |star| [star.hr, star] }
7
+ end
8
+ end
5
9
  end
@@ -2,6 +2,21 @@
2
2
 
3
3
  module Skymap
4
4
  class StarSize
5
+ MAX_RADIUS_MAGNITUDE = -1.5
6
+ MIN_RADIUS_RATIO = 0.0025
7
+ MAX_RADIUS_RATIO = 0.02
8
+ EXPONENT = 1.5
9
+
10
+ def self.for(canvas:, magnitude_limit:)
11
+ new(
12
+ brightest_magnitude: [MAX_RADIUS_MAGNITUDE, magnitude_limit - 1].min,
13
+ faintest_magnitude: magnitude_limit,
14
+ min_radius: MIN_RADIUS_RATIO * canvas.radius,
15
+ max_radius: MAX_RADIUS_RATIO * canvas.radius,
16
+ exponent: EXPONENT
17
+ )
18
+ end
19
+
5
20
  def initialize(
6
21
  brightest_magnitude:,
7
22
  faintest_magnitude:,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skymap
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/skymap.rb CHANGED
@@ -3,19 +3,35 @@
3
3
  require "astronoby"
4
4
 
5
5
  require_relative "skymap/canvas"
6
+ require_relative "skymap/catalog/constellation_boundaries"
6
7
  require_relative "skymap/catalog/constellation_lines"
8
+ require_relative "skymap/catalog/constellation_names"
7
9
  require_relative "skymap/catalog/stars"
8
10
  require_relative "skymap/chart"
11
+ require_relative "skymap/constellation_boundary"
9
12
  require_relative "skymap/constellation_line"
10
13
  require_relative "skymap/context"
14
+ require_relative "skymap/horizon"
11
15
  require_relative "skymap/layers/cardinal_directions"
16
+ require_relative "skymap/layers/constellation_boundaries"
12
17
  require_relative "skymap/layers/constellation_lines"
18
+ require_relative "skymap/layers/constellation_names"
19
+ require_relative "skymap/layers/ecliptic"
20
+ require_relative "skymap/layers/moon"
21
+ require_relative "skymap/layers/planets"
13
22
  require_relative "skymap/layers/stars"
23
+ require_relative "skymap/layers/sun"
14
24
  require_relative "skymap/point"
15
25
  require_relative "skymap/projection/stereographic"
26
+ require_relative "skymap/renderer/boundary"
27
+ require_relative "skymap/renderer/caption"
16
28
  require_relative "skymap/renderer/dot"
29
+ require_relative "skymap/renderer/ecliptic"
17
30
  require_relative "skymap/renderer/label"
18
31
  require_relative "skymap/renderer/line"
32
+ require_relative "skymap/renderer/moon"
33
+ require_relative "skymap/renderer/planet"
34
+ require_relative "skymap/renderer/sun"
19
35
  require_relative "skymap/renderer/svg"
20
36
  require_relative "skymap/star"
21
37
  require_relative "skymap/star_size"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skymap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémy Hannequin
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.10'
18
+ version: '0.11'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0.10'
25
+ version: '0.11'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: csv
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -145,23 +145,41 @@ files:
145
145
  - CHANGELOG.md
146
146
  - LICENSE.txt
147
147
  - README.md
148
- - data/constellations/iau.csv
148
+ - data/constellations/iau/boundaries.csv
149
+ - data/constellations/iau/lines.csv
150
+ - data/constellations/iau/names.csv
149
151
  - data/stars.csv
150
152
  - lib/skymap.rb
151
153
  - lib/skymap/canvas.rb
154
+ - lib/skymap/catalog/constellation_boundaries.rb
152
155
  - lib/skymap/catalog/constellation_lines.rb
156
+ - lib/skymap/catalog/constellation_names.rb
153
157
  - lib/skymap/catalog/stars.rb
154
158
  - lib/skymap/chart.rb
159
+ - lib/skymap/constellation_boundary.rb
155
160
  - lib/skymap/constellation_line.rb
156
161
  - lib/skymap/context.rb
162
+ - lib/skymap/horizon.rb
157
163
  - lib/skymap/layers/cardinal_directions.rb
164
+ - lib/skymap/layers/constellation_boundaries.rb
158
165
  - lib/skymap/layers/constellation_lines.rb
166
+ - lib/skymap/layers/constellation_names.rb
167
+ - lib/skymap/layers/ecliptic.rb
168
+ - lib/skymap/layers/moon.rb
169
+ - lib/skymap/layers/planets.rb
159
170
  - lib/skymap/layers/stars.rb
171
+ - lib/skymap/layers/sun.rb
160
172
  - lib/skymap/point.rb
161
173
  - lib/skymap/projection/stereographic.rb
174
+ - lib/skymap/renderer/boundary.rb
175
+ - lib/skymap/renderer/caption.rb
162
176
  - lib/skymap/renderer/dot.rb
177
+ - lib/skymap/renderer/ecliptic.rb
163
178
  - lib/skymap/renderer/label.rb
164
179
  - lib/skymap/renderer/line.rb
180
+ - lib/skymap/renderer/moon.rb
181
+ - lib/skymap/renderer/planet.rb
182
+ - lib/skymap/renderer/sun.rb
165
183
  - lib/skymap/renderer/svg.rb
166
184
  - lib/skymap/star.rb
167
185
  - lib/skymap/star_size.rb
File without changes