scorched_earth 5.0.3.pre-java → 5.0.4.pre-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e08b161ae03a1b6d480480d02a82ea3b96d3e2c
4
- data.tar.gz: 4dc441be041a996401460c20f75b683a84a3702e
3
+ metadata.gz: f00d9340bc3c2def8581c5632ff80cfb2c9a1c7b
4
+ data.tar.gz: 628dff9384fc39729eaa311a7c5377e5857bb606
5
5
  SHA512:
6
- metadata.gz: 72e9f1fbe7c1fe49415813e7b6451c3d4c0b36c4d4b7604b542ab5cb5cf839e995e7a802ed89b0a4ad22e1139dbde7a89184b328f11ff04989025638ca06102f
7
- data.tar.gz: a0d47c9e26eab3b41aad86d5ab12dc03312433d6531e9edfa107a9f17e15fac28ce771479ba13cb523c69ae183044fc06e505e430961f05766a5c1784e6fe0b4
6
+ metadata.gz: 6d50a62e49990eb185ff5a7c2b22d6e4d7ecc43efbb45b30a901496b30c12fdf19434c249e6752837ed3d8344e126e1d1f413000838cb8a041c65f12b25f2ccd
7
+ data.tar.gz: cb23c05a6f96ac3f4a82903331c5918f01e46e9b11b2ba77e18eeae7066abc0192cf75d8ca819070c5c3350ac8d3b9c44ec2e0e7db5c6b50cf1185804cc6f5dc
@@ -2,6 +2,8 @@ include Java
2
2
 
3
3
  import java.awt.Color
4
4
 
5
+ require 'scorched_earth/services/cie94'
6
+
5
7
  module ScorchedEarth
6
8
  class ColorPalette
7
9
  include Enumerable
@@ -25,7 +27,17 @@ module ScorchedEarth
25
27
 
26
28
  loop do
27
29
  color = strategy.color colors
28
- yield color
30
+ unless already_exists?(color)
31
+ yield color
32
+ end
33
+ end
34
+ end
35
+
36
+ def already_exists?(color)
37
+ cache.values.any? do |color2|
38
+ delta_e94 = Services::CIE94.new.call color, color2
39
+
40
+ delta_e94 < 1000
29
41
  end
30
42
  end
31
43
 
@@ -0,0 +1,99 @@
1
+ include Java
2
+
3
+ import java.awt.Color
4
+
5
+ module ScorchedEarth
6
+ module Services
7
+ # https://github.com/halostatue/color/blob/master/lib/color/rgb.rb
8
+ class CIE94
9
+ def call(color_1, color_2, weighting_type = :graphic_arts)
10
+ color_1 = to_lab(color_1)
11
+ color_2 = to_lab(color_2)
12
+
13
+ case weighting_type
14
+ when :graphic_arts
15
+ k_1 = 0.045
16
+ k_2 = 0.015
17
+ k_L = 1
18
+ when :textiles
19
+ k_1 = 0.048
20
+ k_2 = 0.014
21
+ k_L = 2
22
+ else
23
+ raise ArgumentError, "Unsupported weighting type #{weighting_type}."
24
+ end
25
+
26
+ k_C = k_H = 1
27
+
28
+ l_1, a_1, b_1 = color_1.values_at(:L, :a, :b)
29
+ l_2, a_2, b_2 = color_2.values_at(:L, :a, :b)
30
+
31
+ delta_a = a_1 - a_2
32
+ delta_b = b_1 - b_2
33
+
34
+ c_1 = Math.sqrt((a_1 ** 2) + (b_1 ** 2))
35
+ c_2 = Math.sqrt((a_2 ** 2) + (b_2 ** 2))
36
+
37
+ delta_L = color_1[:L] - color_2[:L]
38
+ delta_C = c_1 - c_2
39
+
40
+ delta_H2 = (delta_a ** 2) + (delta_b ** 2) - (delta_C ** 2)
41
+
42
+ s_L = 1
43
+ s_C = 1 + k_1 * c_1
44
+ s_H = 1 + k_2 * c_1
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)
49
+
50
+ Math.sqrt(composite_L + composite_C + composite_H)
51
+ end
52
+
53
+ private
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
59
+ else
60
+ (v / 12.92) * 100
61
+ end
62
+ }
63
+
64
+ # Convert using the RGB/XYZ matrix at:
65
+ # http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html#WSMatrices
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)
70
+ }
71
+ end
72
+
73
+ def to_lab(color, color_space = :sRGB, reference_white = [ 95.047, 100.00, 108.883 ])
74
+ xyz = to_xyz color
75
+
76
+ xr = xyz[:x] / reference_white[0]
77
+ yr = xyz[:y] / reference_white[1]
78
+ zr = xyz[:z] / reference_white[2]
79
+
80
+ epsilon = (216 / 24389.0)
81
+ kappa = (24389 / 27.0)
82
+
83
+ fx, fy, fz = [ xr, yr, zr ].map do |t|
84
+ if (t > (epsilon))
85
+ t ** (1.0 / 3)
86
+ else # t <= epsilon
87
+ ((kappa * t) + 16) / 116.0
88
+ end
89
+ end
90
+
91
+ {
92
+ :L => ((116 * fy) - 16),
93
+ :a => (500 * (fx - fy)),
94
+ :b => (200 * (fy - fz))
95
+ }
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,3 +1,3 @@
1
1
  module ScorchedEarth
2
- VERSION = '5.0.3.pre'.freeze
2
+ VERSION = '5.0.4.pre'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorched_earth
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.3.pre
4
+ version: 5.0.4.pre
5
5
  platform: java
6
6
  authors:
7
7
  - James Moriarty
@@ -113,6 +113,7 @@ files:
113
113
  - lib/scorched_earth/helpers.rb
114
114
  - lib/scorched_earth/mouse.rb
115
115
  - lib/scorched_earth/player.rb
116
+ - lib/scorched_earth/services/cie94.rb
116
117
  - lib/scorched_earth/shot.rb
117
118
  - lib/scorched_earth/terrain.rb
118
119
  - lib/scorched_earth/version.rb