redgreenblue 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redgreenblue/inspect.rb +11 -0
- data/lib/redgreenblue/math.rb +11 -0
- data/lib/redgreenblue/mix.rb +39 -3
- data/lib/redgreenblue/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7bd0c8570ea98fb428ff9b0213cbdbcfb406a7ec93174e71152b367221091a8
|
4
|
+
data.tar.gz: 802d9d4c8fba0af75a7d1095f24ae81f23d5e5338674b68a69ba0b023cd092bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8af18bacea35e6b732330b7d0a9d907ed90d41951c932307474bffef02e8d6965230441c2322d188314d4280ebbe678b0e56780ede151b5e0a61db2f1f41dc0
|
7
|
+
data.tar.gz: 6b749f770956cada8c6e7fa82c5ec8255ee6081ee98746bac71182572fd5d67ae83c069db4798b2b920c3d5d01c4e39c0cf1ad5b16e5c92a7ae9956d97923f90
|
data/lib/redgreenblue/inspect.rb
CHANGED
@@ -26,6 +26,17 @@ class RGB::Color
|
|
26
26
|
_inspect_swatch + ( name ? ' ' + name : '' )
|
27
27
|
end
|
28
28
|
|
29
|
+
def _inspect_wilhelm
|
30
|
+
_inspect_short +
|
31
|
+
if h = hsl_h
|
32
|
+
" (H:%7.3f %s \e[0m" % [h, ostwald_color.terminal_background]
|
33
|
+
else
|
34
|
+
' (H: - '
|
35
|
+
end +
|
36
|
+
' C:%5.3f W:%5.3f K:%5.3f)' % cwk +
|
37
|
+
( name ? ' ' + name : '' )
|
38
|
+
end
|
39
|
+
|
29
40
|
public
|
30
41
|
|
31
42
|
# Returns a programmer-friendly representation of the object.
|
data/lib/redgreenblue/math.rb
CHANGED
@@ -2,6 +2,17 @@ class RGB::Color
|
|
2
2
|
|
3
3
|
private
|
4
4
|
|
5
|
+
# Returns shortest angle of travel (rotation)
|
6
|
+
# to move between 2 points on a circle.
|
7
|
+
#
|
8
|
+
# Some discussions here:
|
9
|
+
# - https://stackoverflow.com/questions/9505862/
|
10
|
+
# - https://stackoverflow.com/questions/7428718/
|
11
|
+
def angle_of_travel(source, destination)
|
12
|
+
angle = destination - source
|
13
|
+
(angle.abs > 180) ? (angle + (angle.negative? ? 360 : -360)) : angle
|
14
|
+
end
|
15
|
+
|
5
16
|
def zip_add(a,b)
|
6
17
|
a.zip(b).map { |ab| ( ab[0] || 0 ) + ab[1] }
|
7
18
|
end
|
data/lib/redgreenblue/mix.rb
CHANGED
@@ -39,10 +39,9 @@ class RGB::Color
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
# Returns a
|
42
|
+
# Returns a number of colors, gradually changing from this color to another color.
|
43
43
|
#
|
44
|
-
# The resulting colors are spaced evenly in the RGB color space
|
45
|
-
# You will likely experience these colors as not exactly evenly spaced.
|
44
|
+
# The resulting colors are spaced evenly in the RGB color space.
|
46
45
|
def steps(another,step_count=1,include_begin=false)
|
47
46
|
# origin (self, optional)
|
48
47
|
( include_begin ? [self.dup] : [] ) +
|
@@ -52,6 +51,22 @@ class RGB::Color
|
|
52
51
|
[another.dup]
|
53
52
|
end
|
54
53
|
|
54
|
+
# Returns a number of colors, gradually changing from this color to another color.
|
55
|
+
#
|
56
|
+
# The resulting colors are spaced evenly by their HSL values (hue, saturation, and lightness).
|
57
|
+
def steps_hsl(another,step_count=1,include_begin=false)
|
58
|
+
steps_hsx(another,step_count,include_begin, :hsl)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns a number of colors, gradually changing from this color to another color.
|
62
|
+
#
|
63
|
+
# The resulting colors are spaced evenly by their HSV values (hue, saturation, and value).
|
64
|
+
def steps_hsv(another,step_count=1,include_begin=false)
|
65
|
+
steps_hsx(another,step_count,include_begin, :hsv)
|
66
|
+
end
|
67
|
+
|
68
|
+
alias steps_hsb steps_hsv
|
69
|
+
|
55
70
|
private
|
56
71
|
|
57
72
|
def mix_values(some_values, portion)
|
@@ -62,4 +77,25 @@ class RGB::Color
|
|
62
77
|
( blue * (1 - portion) ) + ( some_values[2] * portion )
|
63
78
|
]
|
64
79
|
end
|
80
|
+
|
81
|
+
def steps_hsx(another,step_count=1,include_begin=false,type)
|
82
|
+
raise NotImplementedError unless [:hsl, :hsv].include? type
|
83
|
+
src_hsx = self.send(type)
|
84
|
+
dest_hsx = another.send(type)
|
85
|
+
|
86
|
+
# Take care of achromatic origin/destination
|
87
|
+
src_hsx[0] = ( dest_hsx[0] || 0 ) unless src_hsx[0]
|
88
|
+
dest_hsx[0] = ( src_hsx[0] || 0 ) unless dest_hsx[0]
|
89
|
+
|
90
|
+
step = [angle_of_travel(src_hsx[0], dest_hsx[0]), dest_hsx[1]-src_hsx[1], dest_hsx[2]-src_hsx[2] ].map { |v| v/step_count }
|
91
|
+
|
92
|
+
# origin (self, optional)
|
93
|
+
( include_begin ? [self.dup] : [] ) +
|
94
|
+
# ...plus intermediate colors
|
95
|
+
(1..step_count-1).map { |c| RGB.send(type, zip_add(src_hsx, step.map { |v| v*c })) } +
|
96
|
+
# ...plus destination color
|
97
|
+
[another.dup]
|
98
|
+
|
99
|
+
end
|
100
|
+
|
65
101
|
end
|
data/lib/redgreenblue/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redgreenblue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lllist.eu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|