redgreenblue 0.14.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- class RGB
1
+ class RGB::Color
2
2
 
3
3
  # Shuffles the object's red, green, and blue values.
4
4
  def shuffle!
@@ -6,9 +6,9 @@ class RGB
6
6
  self
7
7
  end
8
8
 
9
- # Creates a new RGB object with this object's red, green, and blue values shuffled.
9
+ # Creates a new RGB::Color with this object's red, green, and blue values shuffled.
10
10
  def shuffle
11
- RGB.new values.shuffle
11
+ RGB::Color.new values.shuffle
12
12
  end
13
13
 
14
14
  # Assigns random values to red, green, and blue.
@@ -17,9 +17,23 @@ class RGB
17
17
  self
18
18
  end
19
19
 
20
- # Creates a new RGB object with random red, green, and blue values.
20
+ # Creates a new RGB::Color with random red, green, and blue values.
21
21
  def self.rand
22
22
  new(Kernel::rand, Kernel::rand, Kernel::rand)
23
23
  end
24
24
 
25
25
  end
26
+
27
+
28
+ module RGB
29
+
30
+ class << self
31
+
32
+ # Creates a new RGB::Color with random red, green, and blue values.
33
+ def rand
34
+ Color.rand
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -1,4 +1,4 @@
1
- class RGB
1
+ class RGB::Color
2
2
 
3
3
  # Returns the color in 16-bit RGB565 format.
4
4
  def rgb565
@@ -15,7 +15,7 @@ class RGB
15
15
  self.b = ( ( v & 0x001f ) ) << 3
16
16
  end
17
17
 
18
- # Creates a new RGB color from 16-bit RGB565 data.
18
+ # Creates a new RGB::Color from 16-bit RGB565 data.
19
19
  def self.rgb565(rgb565_string)
20
20
  c = self.new
21
21
  c.rgb565 = rgb565_string
@@ -23,3 +23,17 @@ class RGB
23
23
  end
24
24
 
25
25
  end
26
+
27
+
28
+ module RGB
29
+
30
+ class << self
31
+
32
+ # Creates a new RGB::Color from 16-bit RGB565 data.
33
+ def rgb565(rgb565_string)
34
+ Color.rgb565(rgb565_string)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -1,4 +1,4 @@
1
- class RGB
1
+ class RGB::Color
2
2
 
3
3
  # With help from:
4
4
  # - https://gist.github.com/XVilka/8346728
@@ -1,7 +1,7 @@
1
- class RGB
1
+ module RGB
2
2
 
3
3
  # redgreenblue version.
4
- VERSION = '0.14.0'
4
+ VERSION = '0.17.0'
5
5
 
6
6
  # Returns RGB::VERSION.
7
7
  def self.version
@@ -1,19 +1,25 @@
1
- class RGB
1
+ class RGB::Color
2
2
 
3
- # Prints details for the RGB object, using multiple lines.
4
- def view
5
- puts _inspect_view
3
+ # Prints a color swatch and details for the RGB::Color object, using multiple lines.
4
+ #
5
+ # You can optionally supply a second color to be shown inside the swatch, for comparison.
6
+ def view(other=nil)
7
+ puts _inspect_view other
6
8
  end
7
9
 
8
10
  alias v view
9
11
 
10
12
  private
11
13
 
12
- def _inspect_view
14
+ def _inspect_view(other=nil)
13
15
  o = []
14
16
  o << 3.times.map { terminal_background + " \e[0m "}
15
17
  o << [ "#{_inspect_hex} ", '%-7.7s ' % color_space, ' ' ]
16
18
 
19
+ if other
20
+ o[0][1] = terminal_background + ' ' + other.terminal_background + ' ' + terminal_background + " \e[0m "
21
+ end
22
+
17
23
  o << components.map { |c| c.terminal_background + " \e[0m " }
18
24
  o << %w(R: G: B:)
19
25
  o << values.map { |v| '%1.5f ' % v }
@@ -1,59 +1,4 @@
1
- class RGB
2
-
3
- #----------------------------------------------------------------------#
4
- # Class Methods #
5
- #----------------------------------------------------------------------#
6
-
7
- class << self
8
-
9
- # Returns CSS named colors, as per CSS Color Module Level 4.
10
- #
11
- # Optional selector argument can be:
12
- # - String or Regexp (to select by name)
13
- # - RGB color (to select by color)
14
- # - Integer (to select by index).
15
- # Selection by name (string or regular expression) is case-insensitive by default.
16
- #
17
- # @example No Selector
18
- # # All colors
19
- # RGB.css
20
- #
21
- # # Pastels
22
- # RGB.css.select { |c| c.ostwald_cwk[1] > 0.6 }
23
- # @example Select by Name
24
- # # Exact name
25
- # RGB.css 'pink'
26
- #
27
- # # Regular expression
28
- # RGB.css /pink|rose/
29
- #
30
- # @example Select by RGB color
31
- # RGB.css RGB.hex('0ff')
32
- def css(selector=nil)
33
- @@css ||= load_gpl file: ( File.join File.dirname(__FILE__), 'palettes', 'css.gpl' ), freeze: true
34
- case selector
35
- when NilClass
36
- @@css
37
- when String
38
- n = selector.downcase
39
- @@css.select { |c| c.name == n }.first
40
- when Regexp
41
- r = Regexp.new selector.source, Regexp::IGNORECASE
42
- @@css.select { |c| c.name =~ r }
43
- when Integer
44
- @@css[selector]
45
- when self
46
- @@css.select { |c| c == selector }
47
- else
48
- raise ArgumentError, 'Unsupported selector'
49
- end
50
- end
51
-
52
- end
53
-
54
- #----------------------------------------------------------------------#
55
- # Instance Methods #
56
- #----------------------------------------------------------------------#
1
+ class RGB::Color
57
2
 
58
3
  # Returns the object's RGB value in hexadecimal notation as used in CSS.
59
4
  #
@@ -106,4 +51,61 @@ class RGB
106
51
  round ? contrast_ratio.round(8) : contrast_ratio
107
52
  end
108
53
 
54
+ # Returns true if this is one of the 216 so-called "web safe" colors, otherwise false.
55
+ def web_safe?
56
+ ( values - [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] ).empty?
57
+ end
58
+
59
+ end
60
+
61
+
62
+ module RGB
63
+
64
+ class << self
65
+
66
+ # Returns CSS named colors, as per CSS Color Module Level 4.
67
+ #
68
+ # Optional selector argument can be:
69
+ # - String or Regexp (to select by name)
70
+ # - RGB color (to select by color)
71
+ # - Integer (to select by index).
72
+ # Selection by name (string or regular expression) is case-insensitive by default.
73
+ #
74
+ # @example No Selector
75
+ # # All colors
76
+ # RGB.css
77
+ #
78
+ # # Pastels
79
+ # RGB.css.select { |c| c.ostwald_cwk[1] > 0.6 }
80
+ # @example Select by Name
81
+ # # Exact name
82
+ # RGB.css 'pink'
83
+ #
84
+ # # Regular expression
85
+ # RGB.css /pink|rose/
86
+ #
87
+ # @example Select by RGB color
88
+ # RGB.css RGB.hex('0ff')
89
+ def css(selector=nil)
90
+ @@css ||= load_gpl file: ( File.join File.dirname(__FILE__), 'palettes', 'css.gpl' ), freeze: true
91
+ case selector
92
+ when NilClass
93
+ @@css
94
+ when String
95
+ n = selector.downcase
96
+ @@css.select { |c| c.name == n }.first
97
+ when Regexp
98
+ r = Regexp.new selector.source, Regexp::IGNORECASE
99
+ @@css.select { |c| c.name =~ r }
100
+ when Integer
101
+ @@css[selector]
102
+ when RGB::Color
103
+ @@css.select { |c| c == selector }
104
+ else
105
+ raise ArgumentError, 'Unsupported selector'
106
+ end
107
+ end
108
+
109
+ end
110
+
109
111
  end
data/lib/redgreenblue.rb CHANGED
@@ -1,4 +1,23 @@
1
- class RGB
1
+ # The RGB module is the main namespace for redgreenblue.
2
+ #
3
+ # This module has many helper methods for creating RGB::Color objects.
4
+ # The example below shows seven ways to create an RGB::Color object for the exact same color.
5
+ # @example
6
+ # require 'redgreenblue'
7
+ #
8
+ # pink = RGB.new(1, 0.6, 0.8)
9
+ # pink = RGB.rgb(255, 153, 204)
10
+ # pink = RGB.rrggbb(65535, 39321, 52428)
11
+ # pink = RGB.hex('f9c')
12
+ # pink = RGB.hsl(330, 1, 0.8)
13
+ # pink = RGB.hsv(330, 0.4, 1)
14
+ # pink = RGB.at(16751052)
15
+ module RGB
16
+
17
+ # This class represents an RGB color.
18
+ class Color
19
+ end
20
+
2
21
  end
3
22
 
4
23
  %w(
@@ -15,7 +34,7 @@ end
15
34
 
16
35
  gamma
17
36
 
18
- cie_1931 cie_1976
37
+ cie_1931 cie_1976 cie_1994
19
38
 
20
39
  name
21
40
 
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.14.0
4
+ version: 0.17.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: 2021-05-03 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,6 +23,7 @@ files:
23
23
  - lib/redgreenblue/bgr24bit.rb
24
24
  - lib/redgreenblue/cie_1931.rb
25
25
  - lib/redgreenblue/cie_1976.rb
26
+ - lib/redgreenblue/cie_1994.rb
26
27
  - lib/redgreenblue/gamma.rb
27
28
  - lib/redgreenblue/gif.rb
28
29
  - lib/redgreenblue/gpl.rb
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
- rubygems_version: 3.1.4
78
+ rubygems_version: 3.3.11
78
79
  signing_key:
79
80
  specification_version: 4
80
81
  summary: A simple Ruby library for handling RGB colors.