scorched_earth 5.0.4.pre-java → 5.0.5.pre-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/bin/console +1 -1
  3. data/exe/scorched +3 -1
  4. data/lib/scorched_earth/event_runner.rb +1 -1
  5. data/lib/scorched_earth/events/{game_ending.rb → game_over.rb} +1 -1
  6. data/lib/scorched_earth/events/{entity_created.rb → game_update.rb} +1 -1
  7. data/lib/scorched_earth/events/{entity_destroyed.rb → hit.rb} +1 -1
  8. data/lib/scorched_earth/game.rb +39 -53
  9. data/lib/scorched_earth/game_window.rb +2 -7
  10. data/lib/scorched_earth/helpers.rb +2 -1
  11. data/lib/scorched_earth/objects/explosion.rb +17 -0
  12. data/lib/scorched_earth/objects/mouse.rb +13 -0
  13. data/lib/scorched_earth/objects/player.rb +12 -0
  14. data/lib/scorched_earth/objects/shot.rb +41 -0
  15. data/lib/scorched_earth/renders/explosion.rb +33 -0
  16. data/lib/scorched_earth/renders/map.rb +76 -0
  17. data/lib/scorched_earth/renders/mouse.rb +27 -0
  18. data/lib/scorched_earth/renders/player.rb +30 -0
  19. data/lib/scorched_earth/renders/shot.rb +23 -0
  20. data/lib/scorched_earth/renders/trajectory.rb +34 -0
  21. data/lib/scorched_earth/renders.rb +16 -0
  22. data/lib/scorched_earth/services/cie94.rb +23 -23
  23. data/lib/scorched_earth/services/color_palette.rb +66 -0
  24. data/lib/scorched_earth/services/deform.rb +30 -0
  25. data/lib/scorched_earth/services/wave.rb +21 -0
  26. data/lib/scorched_earth/subscribers/game_over/timeout.rb +15 -0
  27. data/lib/scorched_earth/subscribers/game_update/collisions.rb +18 -0
  28. data/lib/scorched_earth/subscribers/hit/deform.rb +18 -0
  29. data/lib/scorched_earth/subscribers/hit/effect.rb +15 -0
  30. data/lib/scorched_earth/subscribers/hit/radius.rb +17 -0
  31. data/lib/scorched_earth/subscribers/mouse_moved.rb +13 -0
  32. data/lib/scorched_earth/subscribers/mouse_pressed.rb +13 -0
  33. data/lib/scorched_earth/subscribers/mouse_released/fire.rb +35 -0
  34. data/lib/scorched_earth/subscribers/mouse_released/next_player.rb +13 -0
  35. data/lib/scorched_earth/version.rb +1 -1
  36. data/lib/scorched_earth.rb +1 -0
  37. metadata +28 -11
  38. data/lib/scorched_earth/color_palette.rb +0 -66
  39. data/lib/scorched_earth/explosion.rb +0 -23
  40. data/lib/scorched_earth/mouse.rb +0 -75
  41. data/lib/scorched_earth/player.rb +0 -18
  42. data/lib/scorched_earth/shot.rb +0 -52
  43. data/lib/scorched_earth/terrain.rb +0 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f00d9340bc3c2def8581c5632ff80cfb2c9a1c7b
4
- data.tar.gz: 628dff9384fc39729eaa311a7c5377e5857bb606
3
+ metadata.gz: f5194b6a1289adc43e4d2e6a619f1f92919f1924
4
+ data.tar.gz: 5a5a91fb6b9dbd47e948fdbb1934b70976242dae
5
5
  SHA512:
6
- metadata.gz: 6d50a62e49990eb185ff5a7c2b22d6e4d7ecc43efbb45b30a901496b30c12fdf19434c249e6752837ed3d8344e126e1d1f413000838cb8a041c65f12b25f2ccd
7
- data.tar.gz: cb23c05a6f96ac3f4a82903331c5918f01e46e9b11b2ba77e18eeae7066abc0192cf75d8ca819070c5c3350ac8d3b9c44ec2e0e7db5c6b50cf1185804cc6f5dc
6
+ metadata.gz: 6d2f4458c1e45261dd3000dd32d41d93f1583ea2e7deb5f45ad6b40af29b0553a9e308b9f872fcd7fc0ebde40b7427b68710e9af0a4f60ff76b97f5a89f19100
7
+ data.tar.gz: e67a02cfd9786bef1a123bbdb8fdf5165961718652fcdd9842700d93bd89f49257760a212ab7e9e3ef0c5b3bf3c51eff91eeb5944b190dbcf6fc8091080c798d
data/bin/console CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env jruby
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'scorched_earth'
data/exe/scorched CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  require_relative '../lib/scorched_earth'
4
4
 
5
- ScorchedEarth::GameWindow.new(800, 600).run
5
+ game = ScorchedEarth::Game.new 800, 600
6
+
7
+ ScorchedEarth::GameWindow.new(game.width, game.height, game).run
@@ -16,7 +16,7 @@ module ScorchedEarth
16
16
  end
17
17
 
18
18
  def process!
19
- processing = queue.size.times.map { queue.pop }
19
+ processing = Array.new(queue.size) { queue.pop }
20
20
 
21
21
  processing.each do |event|
22
22
  subscribers.each do |klass, block|
@@ -1,5 +1,5 @@
1
1
  module ScorchedEarth
2
2
  module Events
3
- GameEnding = Struct.new(:time)
3
+ GameOver = Struct.new(:time)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module ScorchedEarth
2
2
  module Events
3
- EntityCreated = Struct.new(:entity)
3
+ GameUpdate = Struct.new(:delta)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module ScorchedEarth
2
2
  module Events
3
- EntityDestroyed = Struct.new(:entity)
3
+ Hit = Struct.new(:object, :radius)
4
4
  end
5
5
  end
@@ -2,91 +2,77 @@ include Java
2
2
 
3
3
  import java.awt.Color
4
4
 
5
- require 'scorched_earth/helpers'
6
- require 'scorched_earth/terrain'
7
- require 'scorched_earth/player'
8
- require 'scorched_earth/shot'
9
- require 'scorched_earth/explosion'
10
- require 'scorched_earth/mouse'
11
- require 'scorched_earth/color_palette'
5
+ require 'scorched_earth/objects/player'
6
+ require 'scorched_earth/objects/shot'
7
+ require 'scorched_earth/objects/explosion'
8
+ require 'scorched_earth/objects/mouse'
12
9
  require 'scorched_earth/event_runner'
13
- require 'scorched_earth/events/entity_created'
14
- require 'scorched_earth/events/entity_destroyed'
15
- require 'scorched_earth/events/game_ending'
10
+ require 'scorched_earth/events/game_update'
11
+ require 'scorched_earth/subscribers/game_over/timeout'
12
+ require 'scorched_earth/subscribers/game_update/collisions'
13
+ require 'scorched_earth/subscribers/hit/deform'
14
+ require 'scorched_earth/subscribers/hit/effect'
15
+ require 'scorched_earth/subscribers/hit/radius'
16
+ require 'scorched_earth/subscribers/mouse_moved'
17
+ require 'scorched_earth/subscribers/mouse_pressed'
18
+ require 'scorched_earth/subscribers/mouse_released/fire'
19
+ require 'scorched_earth/subscribers/mouse_released/next_player'
20
+ require 'scorched_earth/helpers'
21
+ require 'scorched_earth/services/color_palette'
22
+ require 'scorched_earth/services/deform'
23
+ require 'scorched_earth/services/wave'
24
+ require 'scorched_earth/renders'
16
25
 
17
26
  module ScorchedEarth
18
27
  class Game
19
28
  include Helpers
20
29
 
21
- attr_reader :width, :height,
22
- :color_palette, :entities, :mouse, :players, :terrain,
23
- :event_runner
30
+ Subscribers.constants.each { |name| prepend Subscribers.const_get name }
31
+
32
+ attr_reader :width, :height, :mouse,
33
+ :event_runner, :color_palette, :objects, :players, :array
24
34
 
25
35
  def initialize(width, height)
26
36
  @width = width
27
37
  @height = height
38
+ @mouse = Mouse.new
28
39
  end
29
40
 
30
41
  def setup
31
- @color_palette = ColorPalette.new Color.red, Color.yellow, Color.white
32
- @entities = []
42
+ @color_palette = Services::ColorPalette.new Color::RED, Color::YELLOW, Color::WHITE
33
43
  @event_runner = EventRunner.new
34
- @players = Array.new(2) { |index| Player.new rand(width), color_palette.get("player_#{index}") }
35
- @terrain = Terrain.new width, height, rand(10), color_palette.get('terrain')
36
- @mouse = Mouse.new event_runner, players, terrain
37
-
38
- register_events
44
+ @objects = []
45
+ @array = Services::Wave.new(width, height, phases = rand(10)).each.to_a # Array.new(width) { height / 4 }
46
+ @players = Array.new(2) { x = rand(width); Player.new(x, array[x]) }
39
47
  end
40
48
 
41
49
  def update(delta)
42
- event_runner.process!
50
+ @objects = objects
51
+ .map { |object| object.update delta }
52
+ .compact
43
53
 
44
- @entities
45
- .each { |entity| entity.update delta }
46
- .reject { |entity| terrain.fetch(entity.x, 0) < entity.y }
47
- .each { |entity| event_runner.publish Events::EntityDestroyed.new(entity) }
54
+ event_runner.publish Events::GameUpdate.new delta
55
+ event_runner.process!
48
56
  end
49
57
 
50
58
  def render(graphics)
51
59
  graphics.set_color color_palette.get('sky')
52
60
  graphics.fill_rect 0, 0, width, height
53
61
 
54
- entities.each do |entity|
55
- entity.draw graphics
56
- end
62
+ Renders::Mouse.new(mouse, current_player).call(graphics, color_palette)
57
63
 
58
- players.each do |player|
59
- player.draw graphics, terrain[player.x]
60
- end
64
+ objects.each { |object| Renders.find(object).call(graphics, color_palette) }
65
+ players.each { |player| Renders.find(player).call(graphics, color_palette) }
61
66
 
62
- mouse.draw graphics
63
-
64
- terrain.draw graphics
67
+ Renders::Map.new(array).call(graphics, color_palette)
65
68
  end
66
69
 
67
70
  def publish(event)
68
71
  event_runner.publish event
69
72
  end
70
73
 
71
- private
72
-
73
- def register_events
74
- event_runner.subscribe Events::MousePressed, &mouse.method(:mouse_pressed)
75
- event_runner.subscribe Events::MouseReleased, &mouse.method(:mouse_released)
76
- event_runner.subscribe Events::MouseMoved, &mouse.method(:mouse_moved)
77
- event_runner.subscribe(Events::GameEnding) { |event| event.time < Time.now ? setup : event_runner.publish(event) }
78
- event_runner.subscribe(Events::EntityCreated) { |event| entities << event.entity }
79
- event_runner.subscribe(Events::EntityDestroyed) { |event| entities.delete event.entity }
80
- event_runner.subscribe(Events::EntityDestroyed) do |event|
81
- radius = 50
82
- [event.entity]
83
- .select { |entity| entity.is_a? Shot }
84
- .select { |entity| entity.x < terrain.width && entity.x > 0 }
85
- .each { |entity| terrain.bite entity.x, radius }
86
- .each { |entity| event_runner.publish Events::EntityCreated.new(Explosion.new(entity.x, entity.y)) }
87
- .select { |entity| players.any? { |player| inside_radius? entity.x - player.x, 0, radius } }
88
- .each { event_runner.publish Events::GameEnding.new(Time.now + 0.25) }
89
- end
74
+ def current_player
75
+ players.first
90
76
  end
91
77
  end
92
78
  end
@@ -8,7 +8,6 @@ import java.awt.Dimension
8
8
  import javax.swing.JPanel
9
9
  import java.awt.Color
10
10
 
11
- require 'scorched_earth/game'
12
11
  require 'scorched_earth/events/mouse_pressed'
13
12
  require 'scorched_earth/events/mouse_released'
14
13
  require 'scorched_earth/events/mouse_moved'
@@ -20,7 +19,8 @@ module ScorchedEarth
20
19
 
21
20
  attr_reader :buffer_strategy, :canvas, :game
22
21
 
23
- def initialize(width, height)
22
+ def initialize(width, height, game)
23
+ @game = game
24
24
  @container = JFrame.new
25
25
  @canvas = Canvas.new
26
26
  @panel = @container.get_content_pane
@@ -44,8 +44,6 @@ module ScorchedEarth
44
44
  @canvas.set_ignore_repaint true
45
45
  @canvas.create_buffer_strategy 2
46
46
  @buffer_strategy = @canvas.get_buffer_strategy
47
-
48
- @game = ScorchedEarth::Game.new canvas.width, canvas.height
49
47
  end
50
48
 
51
49
  def run
@@ -58,9 +56,6 @@ module ScorchedEarth
58
56
  last_time = Time.now
59
57
  graphics = buffer_strategy.get_draw_graphics
60
58
 
61
- graphics.set_color Color.black
62
- graphics.fill_rect 0, 0, canvas.width, canvas.height
63
-
64
59
  game.update delta
65
60
  game.render graphics
66
61
 
@@ -41,6 +41,7 @@ module ScorchedEarth
41
41
  x**2 + y**2 < radius**2
42
42
  end
43
43
 
44
- module_function :angle, :circle, :inside_radius?, :radians_to_degrees, :degrees_to_radians, :normalize_degrees, :offset_x, :offset_y
44
+ module_function :angle, :circle, :inside_radius?, :radians_to_degrees,
45
+ :degrees_to_radians, :normalize_degrees, :offset_x, :offset_y
45
46
  end
46
47
  end
@@ -0,0 +1,17 @@
1
+ module ScorchedEarth
2
+ class Explosion
3
+ attr_reader :x, :y, :radius
4
+
5
+ def initialize(x, y, radius = 25)
6
+ @x = x
7
+ @y = y
8
+ @radius = radius
9
+
10
+ freeze
11
+ end
12
+
13
+ def update(_delta)
14
+ self.class.new(x, y, radius + 25) if radius < 125
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module ScorchedEarth
2
+ class Mouse
3
+ attr_reader :x, :y, :pressed_at
4
+
5
+ def initialize(x = nil, y = nil, pressed_at = nil)
6
+ @x = x
7
+ @y = y
8
+ @pressed_at = pressed_at
9
+
10
+ freeze
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module ScorchedEarth
2
+ class Player
3
+ attr_reader :x, :y
4
+
5
+ def initialize(x, y)
6
+ @x = x
7
+ @y = y
8
+
9
+ freeze
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ module ScorchedEarth
2
+ class Shot
3
+ class Trajectory < Array
4
+ def initialize(*args)
5
+ super
6
+
7
+ freeze
8
+ end
9
+
10
+ def update(*_args)
11
+ self
12
+ end
13
+ end
14
+
15
+ attr_reader :x, :y, :velocity_x, :velocity_y, :trajectory
16
+
17
+ def initialize(x, y, velocity_x, velocity_y, trajectory = Trajectory.new)
18
+ @x = x
19
+ @y = y
20
+ @velocity_x = velocity_x
21
+ @velocity_y = velocity_y
22
+ @trajectory = Trajectory.new trajectory + [[x, y]]
23
+
24
+ freeze
25
+ end
26
+
27
+ def update(delta)
28
+ self.class.new(
29
+ x + velocity_x * delta,
30
+ y + velocity_y * delta,
31
+ velocity_x,
32
+ velocity_y - gravity * delta,
33
+ trajectory
34
+ )
35
+ end
36
+
37
+ def gravity
38
+ 2000
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ module ScorchedEarth
2
+ module Renders
3
+ class Explosion
4
+ attr_reader :explosion
5
+
6
+ def initialize(explosion)
7
+ @explosion = explosion
8
+ end
9
+
10
+ def call(graphics, *_args)
11
+ height = graphics.destination.height
12
+ y = height - explosion.y - radius / 2
13
+
14
+ graphics.set_color color
15
+ graphics.fill_oval x, y, radius, radius
16
+ end
17
+
18
+ private
19
+
20
+ def color
21
+ Color::WHITE
22
+ end
23
+
24
+ def radius
25
+ explosion.radius
26
+ end
27
+
28
+ def x
29
+ explosion.x - radius / 2
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,76 @@
1
+ include Java
2
+
3
+ import java.awt.Transparency
4
+ import java.awt.Image
5
+
6
+ module ScorchedEarth
7
+ module Renders
8
+ class Map
9
+ module Cache
10
+ def to_image(graphics, color_palette)
11
+ cache(key) do
12
+ super
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def key
19
+ array.join
20
+ end
21
+
22
+ def cache(key)
23
+ @@cache ||= {}
24
+
25
+ if value = @@cache[key]
26
+ value
27
+ else
28
+ @@cache = {}
29
+
30
+ @@cache[key] ||= begin
31
+ yield
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ prepend Cache
38
+
39
+ attr_reader :array
40
+
41
+ def initialize(array)
42
+ @array = array
43
+ end
44
+
45
+ def call(graphics, color_palette)
46
+ graphics.draw_image to_image(graphics, color_palette), 0, 0, nil
47
+ end
48
+
49
+ private
50
+
51
+ def to_image(graphics, color_palette)
52
+ height = graphics.destination.height
53
+ color = color_palette.get(array.class.name)
54
+
55
+ image = graphics
56
+ .get_device_configuration
57
+ .create_compatible_image width, height, Transparency::TRANSLUCENT
58
+
59
+ image.set_acceleration_priority 1
60
+
61
+ array.each_with_index do |y, x|
62
+ image.graphics.tap do |image_graphics|
63
+ image_graphics.set_color color
64
+ image_graphics.draw_line x, height - y, x, height
65
+ end
66
+ end
67
+
68
+ image
69
+ end
70
+
71
+ def width
72
+ array.size
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,27 @@
1
+ include Java
2
+
3
+ import java.awt.BasicStroke
4
+
5
+ module ScorchedEarth
6
+ module Renders
7
+ class Mouse
8
+ attr_reader :mouse, :player
9
+
10
+ def initialize(mouse, player)
11
+ @mouse = mouse
12
+ @player = player
13
+ end
14
+
15
+ def call(graphics, color_palette)
16
+ return unless mouse.x && mouse.y
17
+
18
+ color = color_palette.get(player.x)
19
+ height = graphics.destination.height
20
+
21
+ graphics.set_color color
22
+ graphics.setStroke BasicStroke.new 3
23
+ graphics.draw_line mouse.x, mouse.y, player.x, height - player.y
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ module ScorchedEarth
2
+ module Renders
3
+ class Player
4
+ attr_reader :player
5
+
6
+ def initialize(player)
7
+ @player = player
8
+ end
9
+
10
+ def call(graphics, color_palette)
11
+ color = color_palette.get(player.x)
12
+ height = graphics.destination.height
13
+ y = height - player.y - radius / 2
14
+
15
+ graphics.set_color color
16
+ graphics.fill_oval x, y, radius, radius
17
+ end
18
+
19
+ private
20
+
21
+ def x
22
+ player.x - radius / 2
23
+ end
24
+
25
+ def radius
26
+ 25
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ include Java
2
+
3
+ import java.awt.Color
4
+ import java.awt.BasicStroke
5
+ import java.awt.geom.GeneralPath
6
+
7
+ require 'scorched_earth/renders/trajectory'
8
+
9
+ module ScorchedEarth
10
+ module Renders
11
+ class Shot
12
+ attr_reader :shot
13
+
14
+ def initialize(shot)
15
+ @shot = shot
16
+ end
17
+
18
+ def call(graphics, *_args)
19
+ ScorchedEarth::Renders::Trajectory.new(shot.trajectory).call(graphics, *_args)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ include Java
2
+
3
+ import java.awt.Color
4
+ import java.awt.BasicStroke
5
+ import java.awt.geom.GeneralPath
6
+
7
+ module ScorchedEarth
8
+ module Renders
9
+ class Trajectory
10
+ attr_reader :trajectory
11
+
12
+ def initialize(trajectory)
13
+ @trajectory = trajectory
14
+ end
15
+
16
+ def call(graphics, *_args)
17
+ height = graphics.destination.height
18
+ path = GeneralPath.new GeneralPath::WIND_NON_ZERO
19
+ first, *remaining = trajectory
20
+
21
+ path.move_to first[0], height - first[1]
22
+
23
+ remaining.each do |x, y|
24
+ path.line_to x, height - y
25
+ end
26
+
27
+ graphics.set_stroke BasicStroke.new 3.0, BasicStroke::CAP_ROUND, BasicStroke::JOIN_ROUND, 10.0, [10.0].to_java(:float), 0.0
28
+ graphics.set_color Color::WHITE
29
+
30
+ graphics.draw path
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ require 'scorched_earth/renders/explosion'
2
+ require 'scorched_earth/renders/mouse'
3
+ require 'scorched_earth/renders/player'
4
+ require 'scorched_earth/renders/shot'
5
+ require 'scorched_earth/renders/map'
6
+
7
+ module ScorchedEarth
8
+ module Renders
9
+ def self.find(object)
10
+ class_name = object.class.name.split('::').last
11
+ render_class = const_get class_name
12
+
13
+ render_class.new object
14
+ end
15
+ end
16
+ end
@@ -31,67 +31,67 @@ module ScorchedEarth
31
31
  delta_a = a_1 - a_2
32
32
  delta_b = b_1 - b_2
33
33
 
34
- c_1 = Math.sqrt((a_1 ** 2) + (b_1 ** 2))
35
- c_2 = Math.sqrt((a_2 ** 2) + (b_2 ** 2))
34
+ c_1 = Math.sqrt((a_1**2) + (b_1**2))
35
+ c_2 = Math.sqrt((a_2**2) + (b_2**2))
36
36
 
37
37
  delta_L = color_1[:L] - color_2[:L]
38
38
  delta_C = c_1 - c_2
39
39
 
40
- delta_H2 = (delta_a ** 2) + (delta_b ** 2) - (delta_C ** 2)
40
+ delta_H2 = (delta_a**2) + (delta_b**2) - (delta_C**2)
41
41
 
42
42
  s_L = 1
43
43
  s_C = 1 + k_1 * c_1
44
44
  s_H = 1 + k_2 * c_1
45
45
 
46
- composite_L = (delta_L / (k_L * s_L)) ** 2
47
- composite_C = (delta_C / (k_C * s_C)) ** 2
48
- composite_H = delta_H2 / ((k_H * s_H) ** 2)
46
+ composite_L = (delta_L / (k_L * s_L))**2
47
+ composite_C = (delta_C / (k_C * s_C))**2
48
+ composite_H = delta_H2 / ((k_H * s_H)**2)
49
49
 
50
50
  Math.sqrt(composite_L + composite_C + composite_H)
51
51
  end
52
52
 
53
53
  private
54
54
 
55
- def to_xyz(color, color_space = :sRGB)
56
- r, g, b = [ color.red, color.green, color.blue ].map { |v|
57
- if (v > 0.04045)
58
- (((v + 0.055) / 1.055) ** 2.4) * 100
55
+ def to_xyz(color, _color_space = :sRGB)
56
+ r, g, b = [color.red, color.green, color.blue].map do |v|
57
+ if v > 0.04045
58
+ (((v + 0.055) / 1.055)**2.4) * 100
59
59
  else
60
60
  (v / 12.92) * 100
61
61
  end
62
- }
62
+ end
63
63
 
64
64
  # Convert using the RGB/XYZ matrix at:
65
65
  # http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html#WSMatrices
66
66
  {
67
- :x => (r * 0.4124564 + g * 0.3575761 + b * 0.1804375),
68
- :y => (r * 0.2126729 + g * 0.7151522 + b * 0.0721750),
69
- :z => (r * 0.0193339 + g * 0.1191920 + b * 0.9503041)
67
+ x: (r * 0.4124564 + g * 0.3575761 + b * 0.1804375),
68
+ y: (r * 0.2126729 + g * 0.7151522 + b * 0.0721750),
69
+ z: (r * 0.0193339 + g * 0.1191920 + b * 0.9503041)
70
70
  }
71
71
  end
72
72
 
73
- def to_lab(color, color_space = :sRGB, reference_white = [ 95.047, 100.00, 108.883 ])
73
+ def to_lab(color, _color_space = :sRGB, reference_white = [95.047, 100.00, 108.883])
74
74
  xyz = to_xyz color
75
75
 
76
76
  xr = xyz[:x] / reference_white[0]
77
77
  yr = xyz[:y] / reference_white[1]
78
78
  zr = xyz[:z] / reference_white[2]
79
79
 
80
- epsilon = (216 / 24389.0)
81
- kappa = (24389 / 27.0)
80
+ epsilon = (216 / 24_389.0)
81
+ kappa = (24_389 / 27.0)
82
82
 
83
- fx, fy, fz = [ xr, yr, zr ].map do |t|
84
- if (t > (epsilon))
85
- t ** (1.0 / 3)
83
+ fx, fy, fz = [xr, yr, zr].map do |t|
84
+ if t > epsilon
85
+ t**(1.0 / 3)
86
86
  else # t <= epsilon
87
87
  ((kappa * t) + 16) / 116.0
88
88
  end
89
89
  end
90
90
 
91
91
  {
92
- :L => ((116 * fy) - 16),
93
- :a => (500 * (fx - fy)),
94
- :b => (200 * (fy - fz))
92
+ L: ((116 * fy) - 16),
93
+ a: (500 * (fx - fy)),
94
+ b: (200 * (fy - fz))
95
95
  }
96
96
  end
97
97
  end