redgreenblue 0.11.0 → 0.12.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.
- checksums.yaml +4 -4
- data/lib/redgreenblue.rb +6 -2
- data/lib/redgreenblue/base.rb +1 -1
- data/lib/redgreenblue/{cie.rb → cie_1931.rb} +15 -9
- data/lib/redgreenblue/cie_1976.rb +105 -0
- data/lib/redgreenblue/gpl.rb +70 -9
- data/lib/redgreenblue/hsb.rb +6 -6
- data/lib/redgreenblue/hsl.rb +6 -6
- data/lib/redgreenblue/hsv.rb +6 -6
- data/lib/redgreenblue/hsx_shared.rb +6 -6
- data/lib/redgreenblue/inspect.rb +7 -3
- data/lib/redgreenblue/misc.rb +13 -0
- data/lib/redgreenblue/name.rb +13 -0
- data/lib/redgreenblue/palettes/css.gpl +164 -0
- data/lib/redgreenblue/version.rb +1 -1
- data/lib/redgreenblue/view.rb +34 -0
- data/lib/redgreenblue/web.rb +55 -0
- metadata +7 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 28b5f73bd443540e199b93625df5c7447491b502573abe5aa14089f895fd2700
         | 
| 4 | 
            +
              data.tar.gz: c0a3c77946d5a4d0e6c43d5769385a6c5b72df52c9f7a4cfb52d09bdc50a5153
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 20b4959b4e82fdf67b48dbff3a0c82713a960c56a5bed7e32a78782cab40f1fb9d0f71c2d2fe93cef887a3c97a2590133a85d68b8d57912d7ec0bc4a0817febe
         | 
| 7 | 
            +
              data.tar.gz: bdc13584341d62b90586cf768cd114079e223e64424e0e9e6c24e4398ae74746f2530ed7e2c7540071cf99a4df4afe3a2e7bdadd7c2d0d3dbc6e5d595047d7f7
         | 
    
        data/lib/redgreenblue.rb
    CHANGED
    
    
    
        data/lib/redgreenblue/base.rb
    CHANGED
    
    
| @@ -5,15 +5,18 @@ class RGB | |
| 5 5 | 
             
              # Based on:
         | 
| 6 6 | 
             
              # - http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html
         | 
| 7 7 | 
             
              # - https://en.wikipedia.org/wiki/CIE_1931_color_space
         | 
| 8 | 
            -
              # sRGB to XYZ matrix for D65 reference white by Bruce Lindbloom:
         | 
| 9 | 
            -
              # - http://www.brucelindbloom.com/ | 
| 10 | 
            -
              def cie_xyz
         | 
| 8 | 
            +
              # sRGB to XYZ matrix for D65 reference white calculated with Javascript by Bruce Lindbloom:
         | 
| 9 | 
            +
              # - http://www.brucelindbloom.com/ColorCalculator.html
         | 
| 10 | 
            +
              def cie_xyz(round: true)
         | 
| 11 11 | 
             
                r, g, b = linear_values
         | 
| 12 | 
            +
             | 
| 12 13 | 
             
                [
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  r * 0. | 
| 15 | 
            -
                  r * 0. | 
| 16 | 
            -
             | 
| 14 | 
            +
             | 
| 15 | 
            +
                  r * 0.4124_5643_9090 + g * 0.3575_7607_7644 + b * 0.1804_3748_3266,
         | 
| 16 | 
            +
                  r * 0.2126_7285_1406 + g * 0.7151_5215_5288 + b * 0.0721_7499_3307,
         | 
| 17 | 
            +
                  r * 0.0193_3389_5582 + g * 0.1191_9202_5881 + b * 0.9503_0407_8536
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                ].map { |v| round ? v.round(8) : v }
         | 
| 17 20 | 
             
              end
         | 
| 18 21 |  | 
| 19 22 | 
             
              alias xyz cie_xyz
         | 
| @@ -25,12 +28,15 @@ class RGB | |
| 25 28 | 
             
              # - http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_xyY.html
         | 
| 26 29 | 
             
              # - https://ninedegreesbelow.com/photography/xyz-rgb.html
         | 
| 27 30 | 
             
              def cie_xyy
         | 
| 28 | 
            -
                x, y, z =  | 
| 31 | 
            +
                x, y, z = cie_xyz(round: false)
         | 
| 32 | 
            +
             | 
| 29 33 | 
             
                [
         | 
| 34 | 
            +
             | 
| 30 35 | 
             
                  x / ( x + y + z ),
         | 
| 31 36 | 
             
                  y / ( x + y + z ),
         | 
| 32 37 | 
             
                  y
         | 
| 33 | 
            -
             | 
| 38 | 
            +
             | 
| 39 | 
            +
                ].map { |v| v.round(8) }
         | 
| 34 40 | 
             
              end
         | 
| 35 41 |  | 
| 36 42 | 
             
              alias xyy cie_xyy
         | 
| @@ -0,0 +1,105 @@ | |
| 1 | 
            +
            class RGB
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              # Returns CIE 1976 L*a*b* (CIELAB) values for the RGB object.
         | 
| 4 | 
            +
              def cie_lab(round: true)
         | 
| 5 | 
            +
                cie_lab_luv(round: round, type: :lab)
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              alias lab cie_lab
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              # Returns CIE 1976 LCHab values for the RGB object, derived from L*a*b* (CIELAB).
         | 
| 11 | 
            +
              #
         | 
| 12 | 
            +
              # When C is 0, H is nil.
         | 
| 13 | 
            +
              def cie_lch_ab
         | 
| 14 | 
            +
                cie_lch_ab_uv(type: :lab)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              # Returns CIE 1976 L*u*v* (CIELUV) values for the RGB object.
         | 
| 18 | 
            +
              def cie_luv(round: true)
         | 
| 19 | 
            +
                cie_lab_luv(round: round, type: :luv)
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              alias luv cie_luv
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              # Returns CIE 1976 LCHuv values for the RGB object, derived from L*u*v* (CIELUV).
         | 
| 25 | 
            +
              #
         | 
| 26 | 
            +
              # When C is 0, H is nil.
         | 
| 27 | 
            +
              def cie_lch_uv
         | 
| 28 | 
            +
                cie_lch_ab_uv(type: :luv)
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              # Returns the object's color distance from another RGB object, according to the CIE 1976 delta E formula.
         | 
| 32 | 
            +
              #
         | 
| 33 | 
            +
              # Based on:
         | 
| 34 | 
            +
              # - http://www.brucelindbloom.com/Eqn_DeltaE_CIE76.html
         | 
| 35 | 
            +
              # - https://en.wikipedia.org/wiki/Color_difference
         | 
| 36 | 
            +
              def delta_e_cie_1976(another)
         | 
| 37 | 
            +
                l , a , b  =         cie_lab(round: false)
         | 
| 38 | 
            +
                l2, a2, b2 = another.cie_lab(round: false)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                Math.sqrt( (l - l2) ** 2 + (a - a2) ** 2 + (b - b2) ** 2 ).round(8)
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              alias de76 delta_e_cie_1976
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              private
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              # Returns either CIE 1976 L*a*b* (CIELAB) or CIE 1976 L*u*v* (CIELUV) values for the RGB object.
         | 
| 48 | 
            +
              #
         | 
| 49 | 
            +
              # L*a*b* formula based on:
         | 
| 50 | 
            +
              # - http://www.brucelindbloom.com/Eqn_XYZ_to_Lab.html
         | 
| 51 | 
            +
              # - https://en.wikipedia.org/wiki/CIELAB_color_space
         | 
| 52 | 
            +
              # With peeking at:
         | 
| 53 | 
            +
              # - https://github.com/halostatue/color/blob/master/lib/color/rgb.rb
         | 
| 54 | 
            +
              #
         | 
| 55 | 
            +
              # L*u*v* formula based on:
         | 
| 56 | 
            +
              # - http://www.brucelindbloom.com/Eqn_XYZ_to_Luv.html
         | 
| 57 | 
            +
              # - https://en.wikipedia.org/wiki/CIELUV
         | 
| 58 | 
            +
              def cie_lab_luv(round: true, type: :lab)
         | 
| 59 | 
            +
                x , y , z  =           cie_xyz(round: false)
         | 
| 60 | 
            +
                xr, yr, zr = RGB.white.cie_xyz(round: false)
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                f = [ x / xr, y / yr, z / zr ].map { |v|
         | 
| 63 | 
            +
                  if v > ( 216.0 / 24389 )
         | 
| 64 | 
            +
                    v ** ( 1.0 / 3 ) # cube root
         | 
| 65 | 
            +
                  else
         | 
| 66 | 
            +
                    ( 24389.0 / 27 * v + 16 ) / 116.0
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
                }
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                if type == :luv
         | 
| 71 | 
            +
                  [
         | 
| 72 | 
            +
                    l = 116 * f[1] - 16,
         | 
| 73 | 
            +
                    13 * l * ( ( 4 * x ) / ( x + 15 * y + 3 * z ) - ( 4 * xr ) / ( xr + 15 * yr + 3 * zr ) ),
         | 
| 74 | 
            +
                    13 * l * ( ( 9 * y ) / ( x + 15 * y + 3 * z ) - ( 9 * yr ) / ( xr + 15 * yr + 3 * zr ) )
         | 
| 75 | 
            +
                  ]
         | 
| 76 | 
            +
                else
         | 
| 77 | 
            +
                  [
         | 
| 78 | 
            +
                    116 *  f[1] - 16,
         | 
| 79 | 
            +
                    500 * (f[0] - f[1]),
         | 
| 80 | 
            +
                    200 * (f[1] - f[2])
         | 
| 81 | 
            +
                  ]
         | 
| 82 | 
            +
                end.map { |v| v.nan? ? 0.0 : ( round ? v.round(8) : v ) }
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              # Returns either CIE 1976 LCHab or CIE 1976 LCHuv values for the RGB object.
         | 
| 86 | 
            +
              #
         | 
| 87 | 
            +
              # Based on:
         | 
| 88 | 
            +
              # - http://www.brucelindbloom.com/Eqn_Lab_to_LCH.html
         | 
| 89 | 
            +
              # - http://www.brucelindbloom.com/Eqn_Luv_to_LCH.html
         | 
| 90 | 
            +
              # - https://en.wikipedia.org/wiki/CIELAB_color_space
         | 
| 91 | 
            +
              def cie_lch_ab_uv(type: :lab)
         | 
| 92 | 
            +
                if type == :luv
         | 
| 93 | 
            +
                  l, v1, v2 = cie_luv(round: false)
         | 
| 94 | 
            +
                else
         | 
| 95 | 
            +
                  l, v1, v2 = cie_lab(round: false)
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                [
         | 
| 99 | 
            +
                  l.round(8),
         | 
| 100 | 
            +
                  c = ( ( v1 ** 2 + v2 ** 2) ** ( 1.0 / 2 ) ).round(8),
         | 
| 101 | 
            +
                  c == 0 ? nil : ( Math.atan2(v2, v1) * 180.0 / Math::PI ).modulo(360).round(8)
         | 
| 102 | 
            +
                ]
         | 
| 103 | 
            +
              end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
            end
         | 
    
        data/lib/redgreenblue/gpl.rb
    CHANGED
    
    | @@ -1,11 +1,69 @@ | |
| 1 1 | 
             
            class RGB
         | 
| 2 2 |  | 
| 3 | 
            -
               | 
| 4 | 
            -
              # | 
| 5 | 
            -
               | 
| 3 | 
            +
              #----------------------------------------------------------------------#
         | 
| 4 | 
            +
              #                            Class Methods                             #
         | 
| 5 | 
            +
              #----------------------------------------------------------------------#
         | 
| 6 6 |  | 
| 7 7 | 
             
              class << self
         | 
| 8 8 |  | 
| 9 | 
            +
                # Creates a new RGB object from a line of gpl (Gimp color palette) input. Returns nil if not successful.
         | 
| 10 | 
            +
                #
         | 
| 11 | 
            +
                # @example
         | 
| 12 | 
            +
                #  RGB.gpl "255 153 204\tpink"
         | 
| 13 | 
            +
                def gpl(line)
         | 
| 14 | 
            +
                  if line.chomp.match( /^\s*(?<r>\d{1,3})\s+(?<g>\d{1,3})\s+(?<b>\d{1,3})(\s+(?<name>.*))?/ )
         | 
| 15 | 
            +
                    color = RGB.rgb $~[:r].to_i, $~[:g].to_i, $~[:b].to_i
         | 
| 16 | 
            +
                    color.name = $~[:name] if $~[:name]
         | 
| 17 | 
            +
                    color
         | 
| 18 | 
            +
                  else
         | 
| 19 | 
            +
                    nil
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                # Loads a gpl (Gimp color palette) source and returns an array of RGB objects.
         | 
| 24 | 
            +
                #
         | 
| 25 | 
            +
                # Options:
         | 
| 26 | 
            +
                # - file: Path to a .gpl file to be loaded.
         | 
| 27 | 
            +
                # - url: URL for a .gpl source to be loaded.
         | 
| 28 | 
            +
                # - compact: Defaults to true. If set to false, returns nil for each line that can not be parsed to an RGB color.
         | 
| 29 | 
            +
                # - freeze: Defaults to false. If set to true, returns a frozen array of frozen objects.
         | 
| 30 | 
            +
                #
         | 
| 31 | 
            +
                # @example String
         | 
| 32 | 
            +
                #  RGB.load_gpl "255 0 0\tred\n255 153 204\tpink\n"
         | 
| 33 | 
            +
                # @example File
         | 
| 34 | 
            +
                #  RGB.load_gpl file: '/path/to/palette.gpl'
         | 
| 35 | 
            +
                #  RGB.load_gpl file: '/path/to/palette.gpl', compact: false
         | 
| 36 | 
            +
                # @example URL
         | 
| 37 | 
            +
                #  RGB.load_gpl url: 'https://lospec.com/palette-list/yuko-tomita-time.gpl'
         | 
| 38 | 
            +
                def load_gpl(source=nil, file: nil, url: nil, compact: true, freeze: false)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  if ! source
         | 
| 41 | 
            +
                    if file
         | 
| 42 | 
            +
                      source = File.open file
         | 
| 43 | 
            +
                    elsif url
         | 
| 44 | 
            +
                      require 'open-uri'
         | 
| 45 | 
            +
                      source = URI.open url
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  if source.respond_to? :each_line
         | 
| 50 | 
            +
                    list = source.each_line.map { |line| RGB.gpl(line) }
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                    if compact
         | 
| 53 | 
            +
                      list.compact!
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    if freeze
         | 
| 57 | 
            +
                      list.freeze
         | 
| 58 | 
            +
                      list.each &:freeze
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                    list
         | 
| 62 | 
            +
                  else
         | 
| 63 | 
            +
                    raise ArgumentError, 'Not a valid source'
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 9 67 | 
             
                private
         | 
| 10 68 |  | 
| 11 69 | 
             
                # Reverse-engineered from:
         | 
| @@ -18,13 +76,16 @@ class RGB | |
| 18 76 |  | 
| 19 77 | 
             
              end
         | 
| 20 78 |  | 
| 21 | 
            -
               | 
| 22 | 
            -
              # | 
| 23 | 
            -
               | 
| 79 | 
            +
              #----------------------------------------------------------------------#
         | 
| 80 | 
            +
              #                           Instance Methods                           #
         | 
| 81 | 
            +
              #----------------------------------------------------------------------#
         | 
| 24 82 |  | 
| 25 | 
            -
              # Returns the color in the format used in .gpl files (Gimp color palettes) | 
| 26 | 
            -
               | 
| 27 | 
            -
             | 
| 83 | 
            +
              # Returns the color in the format used in .gpl files (Gimp color palettes), including its name (if present).
         | 
| 84 | 
            +
              #
         | 
| 85 | 
            +
              # You can optionally supply a name as argument.
         | 
| 86 | 
            +
              def gpl(gpl_name=name)
         | 
| 87 | 
            +
                ( "%3d %3d %3d" % rgb ) +
         | 
| 88 | 
            +
                ( gpl_name.to_s.size != 0 ? "\t#{gpl_name}" : '' )
         | 
| 28 89 | 
             
              end
         | 
| 29 90 |  | 
| 30 91 | 
             
            end
         | 
    
        data/lib/redgreenblue/hsb.rb
    CHANGED
    
    | @@ -2,9 +2,9 @@ require 'redgreenblue/hsv' | |
| 2 2 |  | 
| 3 3 | 
             
            class RGB
         | 
| 4 4 |  | 
| 5 | 
            -
               | 
| 6 | 
            -
              # | 
| 7 | 
            -
               | 
| 5 | 
            +
              #----------------------------------------------------------------------#
         | 
| 6 | 
            +
              #                            Class Methods                             #
         | 
| 7 | 
            +
              #----------------------------------------------------------------------#
         | 
| 8 8 |  | 
| 9 9 | 
             
              class << self
         | 
| 10 10 |  | 
| @@ -13,9 +13,9 @@ class RGB | |
| 13 13 |  | 
| 14 14 | 
             
              end
         | 
| 15 15 |  | 
| 16 | 
            -
               | 
| 17 | 
            -
              # | 
| 18 | 
            -
               | 
| 16 | 
            +
              #----------------------------------------------------------------------#
         | 
| 17 | 
            +
              #                           Instance Methods                           #
         | 
| 18 | 
            +
              #----------------------------------------------------------------------#
         | 
| 19 19 |  | 
| 20 20 | 
             
              # Returns color as HSB:
         | 
| 21 21 | 
             
              # hue (0..360), saturation (0..1), brightness (0..1).
         | 
    
        data/lib/redgreenblue/hsl.rb
    CHANGED
    
    | @@ -3,9 +3,9 @@ require 'redgreenblue/math' | |
| 3 3 |  | 
| 4 4 | 
             
            class RGB
         | 
| 5 5 |  | 
| 6 | 
            -
               | 
| 7 | 
            -
              # | 
| 8 | 
            -
               | 
| 6 | 
            +
              #----------------------------------------------------------------------#
         | 
| 7 | 
            +
              #                            Class Methods                             #
         | 
| 8 | 
            +
              #----------------------------------------------------------------------#
         | 
| 9 9 |  | 
| 10 10 | 
             
              class << self
         | 
| 11 11 |  | 
| @@ -23,9 +23,9 @@ class RGB | |
| 23 23 |  | 
| 24 24 | 
             
              end
         | 
| 25 25 |  | 
| 26 | 
            -
               | 
| 27 | 
            -
              # | 
| 28 | 
            -
               | 
| 26 | 
            +
              #----------------------------------------------------------------------#
         | 
| 27 | 
            +
              #                           Instance Methods                           #
         | 
| 28 | 
            +
              #----------------------------------------------------------------------#
         | 
| 29 29 |  | 
| 30 30 | 
             
              # Returns color as HSL:
         | 
| 31 31 | 
             
              # hue (0..360), saturation (0..1), lightness (0..1).
         | 
    
        data/lib/redgreenblue/hsv.rb
    CHANGED
    
    | @@ -3,9 +3,9 @@ require 'redgreenblue/math' | |
| 3 3 |  | 
| 4 4 | 
             
            class RGB
         | 
| 5 5 |  | 
| 6 | 
            -
               | 
| 7 | 
            -
              # | 
| 8 | 
            -
               | 
| 6 | 
            +
              #----------------------------------------------------------------------#
         | 
| 7 | 
            +
              #                            Class Methods                             #
         | 
| 8 | 
            +
              #----------------------------------------------------------------------#
         | 
| 9 9 |  | 
| 10 10 | 
             
              class << self
         | 
| 11 11 |  | 
| @@ -23,9 +23,9 @@ class RGB | |
| 23 23 |  | 
| 24 24 | 
             
              end
         | 
| 25 25 |  | 
| 26 | 
            -
               | 
| 27 | 
            -
              # | 
| 28 | 
            -
               | 
| 26 | 
            +
              #----------------------------------------------------------------------#
         | 
| 27 | 
            +
              #                           Instance Methods                           #
         | 
| 28 | 
            +
              #----------------------------------------------------------------------#
         | 
| 29 29 |  | 
| 30 30 | 
             
              # Returns color as HSV:
         | 
| 31 31 | 
             
              # hue (0..360), saturation (0..1), value (0..1).
         | 
| @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            class RGB
         | 
| 2 2 |  | 
| 3 | 
            -
               | 
| 4 | 
            -
              # | 
| 5 | 
            -
               | 
| 3 | 
            +
              #----------------------------------------------------------------------#
         | 
| 4 | 
            +
              #                            Class Methods                             #
         | 
| 5 | 
            +
              #----------------------------------------------------------------------#
         | 
| 6 6 |  | 
| 7 7 | 
             
              class << self
         | 
| 8 8 |  | 
| @@ -48,9 +48,9 @@ class RGB | |
| 48 48 |  | 
| 49 49 | 
             
              end
         | 
| 50 50 |  | 
| 51 | 
            -
               | 
| 52 | 
            -
              # | 
| 53 | 
            -
               | 
| 51 | 
            +
              #----------------------------------------------------------------------#
         | 
| 52 | 
            +
              #                           Instance Methods                           #
         | 
| 53 | 
            +
              #----------------------------------------------------------------------#
         | 
| 54 54 |  | 
| 55 55 | 
             
              private
         | 
| 56 56 |  | 
    
        data/lib/redgreenblue/inspect.rb
    CHANGED
    
    | @@ -3,11 +3,11 @@ class RGB | |
| 3 3 | 
             
              private
         | 
| 4 4 |  | 
| 5 5 | 
             
              def _inspect_default(prefix='RGB')
         | 
| 6 | 
            -
                "#{prefix}  | 
| 6 | 
            +
                "#{prefix} #{_inspect_hex} (red=%1.5f green=%1.5f blue=%1.5f)" % [red, green, blue] + ( name ? ' ' + name : '' )
         | 
| 7 7 | 
             
              end
         | 
| 8 8 |  | 
| 9 9 | 
             
              def _inspect_hex
         | 
| 10 | 
            -
                 | 
| 10 | 
            +
                (self == snap ? '#' : '~') + hex
         | 
| 11 11 | 
             
              end
         | 
| 12 12 |  | 
| 13 13 | 
             
              def _inspect_swatch
         | 
| @@ -15,13 +15,17 @@ class RGB | |
| 15 15 | 
             
              end
         | 
| 16 16 |  | 
| 17 17 | 
             
              def _inspect_short
         | 
| 18 | 
            -
                _inspect_swatch  | 
| 18 | 
            +
                "#{_inspect_swatch} #{_inspect_hex}"
         | 
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 21 | 
             
              def _inspect_simple
         | 
| 22 22 | 
             
                _inspect_default _inspect_swatch
         | 
| 23 23 | 
             
              end
         | 
| 24 24 |  | 
| 25 | 
            +
              def _inspect_name
         | 
| 26 | 
            +
                _inspect_swatch + ( name ? ' ' + name : '' )
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 25 29 | 
             
              public
         | 
| 26 30 |  | 
| 27 31 | 
             
              # Returns a programmer-friendly representation of the object.
         | 
    
        data/lib/redgreenblue/misc.rb
    CHANGED
    
    | @@ -36,4 +36,17 @@ class RGB | |
| 36 36 | 
             
                RGB.new(v[0].red, v[1].green, v[2].blue)
         | 
| 37 37 | 
             
              end
         | 
| 38 38 |  | 
| 39 | 
            +
              # Returns the euclidean distance between this color and another color.
         | 
| 40 | 
            +
              #
         | 
| 41 | 
            +
              # When you imagine a color as a point in a 3-dimensional space,
         | 
| 42 | 
            +
              # the dimensions being red, green, and blue,
         | 
| 43 | 
            +
              # this is the distance between two colors.
         | 
| 44 | 
            +
              def distance(another)
         | 
| 45 | 
            +
                (
         | 
| 46 | 
            +
                  ( (another.red   - red  ) ** 2) +
         | 
| 47 | 
            +
                  ( (another.green - green) ** 2) +
         | 
| 48 | 
            +
                  ( (another.blue  - blue ) ** 2)
         | 
| 49 | 
            +
                ) ** (1/2.0)
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
             | 
| 39 52 | 
             
            end
         | 
| @@ -0,0 +1,164 @@ | |
| 1 | 
            +
            GIMP Palette
         | 
| 2 | 
            +
            Name: CSS Named Colors
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            # As per CSS Color Module Level 4, Editor's Draft, 19 August 2020.
         | 
| 5 | 
            +
            #   - source: https://drafts.csswg.org/css-color/#named-colors
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
            # Notes: 
         | 
| 8 | 
            +
            #  "Don't cite this document other than as work in progress."
         | 
| 9 | 
            +
            #
         | 
| 10 | 
            +
            #  "CSS defines a large set of named colors, so that 
         | 
| 11 | 
            +
            #   common colors can be written and read more easily."
         | 
| 12 | 
            +
            #
         | 
| 13 | 
            +
            #  "[...] all of these keywords are ASCII case-insensitive."
         | 
| 14 | 
            +
            #
         | 
| 15 | 
            +
            #  "The names resolve to colors in sRGB."
         | 
| 16 | 
            +
            #
         | 
| 17 | 
            +
            240 248 255	aliceblue
         | 
| 18 | 
            +
            250 235 215	antiquewhite
         | 
| 19 | 
            +
              0 255 255	aqua
         | 
| 20 | 
            +
            127 255 212	aquamarine
         | 
| 21 | 
            +
            240 255 255	azure
         | 
| 22 | 
            +
            245 245 220	beige
         | 
| 23 | 
            +
            255 228 196	bisque
         | 
| 24 | 
            +
              0   0   0	black
         | 
| 25 | 
            +
            255 235 205	blanchedalmond
         | 
| 26 | 
            +
              0   0 255	blue
         | 
| 27 | 
            +
            138  43 226	blueviolet
         | 
| 28 | 
            +
            165  42  42	brown
         | 
| 29 | 
            +
            222 184 135	burlywood
         | 
| 30 | 
            +
             95 158 160	cadetblue
         | 
| 31 | 
            +
            127 255   0	chartreuse
         | 
| 32 | 
            +
            210 105  30	chocolate
         | 
| 33 | 
            +
            255 127  80	coral
         | 
| 34 | 
            +
            100 149 237	cornflowerblue
         | 
| 35 | 
            +
            255 248 220	cornsilk
         | 
| 36 | 
            +
            220  20  60	crimson
         | 
| 37 | 
            +
              0 255 255	cyan
         | 
| 38 | 
            +
              0   0 139	darkblue
         | 
| 39 | 
            +
              0 139 139	darkcyan
         | 
| 40 | 
            +
            184 134  11	darkgoldenrod
         | 
| 41 | 
            +
            169 169 169	darkgray
         | 
| 42 | 
            +
              0 100   0	darkgreen
         | 
| 43 | 
            +
            169 169 169	darkgrey
         | 
| 44 | 
            +
            189 183 107	darkkhaki
         | 
| 45 | 
            +
            139   0 139	darkmagenta
         | 
| 46 | 
            +
             85 107  47	darkolivegreen
         | 
| 47 | 
            +
            255 140   0	darkorange
         | 
| 48 | 
            +
            153  50 204	darkorchid
         | 
| 49 | 
            +
            139   0   0	darkred
         | 
| 50 | 
            +
            233 150 122	darksalmon
         | 
| 51 | 
            +
            143 188 143	darkseagreen
         | 
| 52 | 
            +
             72  61 139	darkslateblue
         | 
| 53 | 
            +
             47  79  79	darkslategray
         | 
| 54 | 
            +
             47  79  79	darkslategrey
         | 
| 55 | 
            +
              0 206 209	darkturquoise
         | 
| 56 | 
            +
            148   0 211	darkviolet
         | 
| 57 | 
            +
            255  20 147	deeppink
         | 
| 58 | 
            +
              0 191 255	deepskyblue
         | 
| 59 | 
            +
            105 105 105	dimgray
         | 
| 60 | 
            +
            105 105 105	dimgrey
         | 
| 61 | 
            +
             30 144 255	dodgerblue
         | 
| 62 | 
            +
            178  34  34	firebrick
         | 
| 63 | 
            +
            255 250 240	floralwhite
         | 
| 64 | 
            +
             34 139  34	forestgreen
         | 
| 65 | 
            +
            255   0 255	fuchsia
         | 
| 66 | 
            +
            220 220 220	gainsboro
         | 
| 67 | 
            +
            248 248 255	ghostwhite
         | 
| 68 | 
            +
            255 215   0	gold
         | 
| 69 | 
            +
            218 165  32	goldenrod
         | 
| 70 | 
            +
            128 128 128	gray
         | 
| 71 | 
            +
              0 128   0	green
         | 
| 72 | 
            +
            173 255  47	greenyellow
         | 
| 73 | 
            +
            128 128 128	grey
         | 
| 74 | 
            +
            240 255 240	honeydew
         | 
| 75 | 
            +
            255 105 180	hotpink
         | 
| 76 | 
            +
            205  92  92	indianred
         | 
| 77 | 
            +
             75   0 130	indigo
         | 
| 78 | 
            +
            255 255 240	ivory
         | 
| 79 | 
            +
            240 230 140	khaki
         | 
| 80 | 
            +
            230 230 250	lavender
         | 
| 81 | 
            +
            255 240 245	lavenderblush
         | 
| 82 | 
            +
            124 252   0	lawngreen
         | 
| 83 | 
            +
            255 250 205	lemonchiffon
         | 
| 84 | 
            +
            173 216 230	lightblue
         | 
| 85 | 
            +
            240 128 128	lightcoral
         | 
| 86 | 
            +
            224 255 255	lightcyan
         | 
| 87 | 
            +
            250 250 210	lightgoldenrodyellow
         | 
| 88 | 
            +
            211 211 211	lightgray
         | 
| 89 | 
            +
            144 238 144	lightgreen
         | 
| 90 | 
            +
            211 211 211	lightgrey
         | 
| 91 | 
            +
            255 182 193	lightpink
         | 
| 92 | 
            +
            255 160 122	lightsalmon
         | 
| 93 | 
            +
             32 178 170	lightseagreen
         | 
| 94 | 
            +
            135 206 250	lightskyblue
         | 
| 95 | 
            +
            119 136 153	lightslategray
         | 
| 96 | 
            +
            119 136 153	lightslategrey
         | 
| 97 | 
            +
            176 196 222	lightsteelblue
         | 
| 98 | 
            +
            255 255 224	lightyellow
         | 
| 99 | 
            +
              0 255   0	lime
         | 
| 100 | 
            +
             50 205  50	limegreen
         | 
| 101 | 
            +
            250 240 230	linen
         | 
| 102 | 
            +
            255   0 255	magenta
         | 
| 103 | 
            +
            128   0   0	maroon
         | 
| 104 | 
            +
            102 205 170	mediumaquamarine
         | 
| 105 | 
            +
              0   0 205	mediumblue
         | 
| 106 | 
            +
            186  85 211	mediumorchid
         | 
| 107 | 
            +
            147 112 219	mediumpurple
         | 
| 108 | 
            +
             60 179 113	mediumseagreen
         | 
| 109 | 
            +
            123 104 238	mediumslateblue
         | 
| 110 | 
            +
              0 250 154	mediumspringgreen
         | 
| 111 | 
            +
             72 209 204	mediumturquoise
         | 
| 112 | 
            +
            199  21 133	mediumvioletred
         | 
| 113 | 
            +
             25  25 112	midnightblue
         | 
| 114 | 
            +
            245 255 250	mintcream
         | 
| 115 | 
            +
            255 228 225	mistyrose
         | 
| 116 | 
            +
            255 228 181	moccasin
         | 
| 117 | 
            +
            255 222 173	navajowhite
         | 
| 118 | 
            +
              0   0 128	navy
         | 
| 119 | 
            +
            253 245 230	oldlace
         | 
| 120 | 
            +
            128 128   0	olive
         | 
| 121 | 
            +
            107 142  35	olivedrab
         | 
| 122 | 
            +
            255 165   0	orange
         | 
| 123 | 
            +
            255  69   0	orangered
         | 
| 124 | 
            +
            218 112 214	orchid
         | 
| 125 | 
            +
            238 232 170	palegoldenrod
         | 
| 126 | 
            +
            152 251 152	palegreen
         | 
| 127 | 
            +
            175 238 238	paleturquoise
         | 
| 128 | 
            +
            219 112 147	palevioletred
         | 
| 129 | 
            +
            255 239 213	papayawhip
         | 
| 130 | 
            +
            255 218 185	peachpuff
         | 
| 131 | 
            +
            205 133  63	peru
         | 
| 132 | 
            +
            255 192 203	pink
         | 
| 133 | 
            +
            221 160 221	plum
         | 
| 134 | 
            +
            176 224 230	powderblue
         | 
| 135 | 
            +
            128   0 128	purple
         | 
| 136 | 
            +
            102  51 153	rebeccapurple
         | 
| 137 | 
            +
            255   0   0	red
         | 
| 138 | 
            +
            188 143 143	rosybrown
         | 
| 139 | 
            +
             65 105 225	royalblue
         | 
| 140 | 
            +
            139  69  19	saddlebrown
         | 
| 141 | 
            +
            250 128 114	salmon
         | 
| 142 | 
            +
            244 164  96	sandybrown
         | 
| 143 | 
            +
             46 139  87	seagreen
         | 
| 144 | 
            +
            255 245 238	seashell
         | 
| 145 | 
            +
            160  82  45	sienna
         | 
| 146 | 
            +
            192 192 192	silver
         | 
| 147 | 
            +
            135 206 235	skyblue
         | 
| 148 | 
            +
            106  90 205	slateblue
         | 
| 149 | 
            +
            112 128 144	slategray
         | 
| 150 | 
            +
            112 128 144	slategrey
         | 
| 151 | 
            +
            255 250 250	snow
         | 
| 152 | 
            +
              0 255 127	springgreen
         | 
| 153 | 
            +
             70 130 180	steelblue
         | 
| 154 | 
            +
            210 180 140	tan
         | 
| 155 | 
            +
              0 128 128	teal
         | 
| 156 | 
            +
            216 191 216	thistle
         | 
| 157 | 
            +
            255  99  71	tomato
         | 
| 158 | 
            +
             64 224 208	turquoise
         | 
| 159 | 
            +
            238 130 238	violet
         | 
| 160 | 
            +
            245 222 179	wheat
         | 
| 161 | 
            +
            255 255 255	white
         | 
| 162 | 
            +
            245 245 245	whitesmoke
         | 
| 163 | 
            +
            255 255   0	yellow
         | 
| 164 | 
            +
            154 205  50	yellowgreen
         | 
    
        data/lib/redgreenblue/version.rb
    CHANGED
    
    
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            class RGB
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              # Prints details for the RGB object, using multiple lines.
         | 
| 4 | 
            +
              def view
         | 
| 5 | 
            +
                puts _inspect_view
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              alias v view
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              private
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def _inspect_view
         | 
| 13 | 
            +
                o = []
         | 
| 14 | 
            +
                o << 3.times.map { terminal_background + "      \e[0m "}
         | 
| 15 | 
            +
                o << [ "#{_inspect_hex} ", '%-7.7s ' % color_space, '        ' ]
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                o << components.map { |c| c.terminal_background + "  \e[0m " }
         | 
| 18 | 
            +
                o << %w(R: G: B:)
         | 
| 19 | 
            +
                o << values.map { |v| '%1.5f ' % v }
         | 
| 20 | 
            +
                o << rgb.map { |v| '%3d ' % v }
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                o << %w(H: S: L:)
         | 
| 23 | 
            +
                o << hsl.map { |v| v ? ('%7.3f ' % v) : '  -     ' }
         | 
| 24 | 
            +
                o << %w(H: S: B:)
         | 
| 25 | 
            +
                o << hsb.map { |v| v ? ('%7.3f ' % v) : '  -     ' }
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                o << 3.times.map { (ostwald_color ? ostwald_color.terminal_background + "  \e[0m " : '   ') }
         | 
| 28 | 
            +
                o << %w(C: W: K:)
         | 
| 29 | 
            +
                o << ostwald_cwk.map { |v| '%1.3f ' % v }
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                o.transpose.map(&:join).join("\n")
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            end
         | 
    
        data/lib/redgreenblue/web.rb
    CHANGED
    
    | @@ -1,5 +1,60 @@ | |
| 1 1 | 
             
            class RGB
         | 
| 2 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 | 
            +
              #----------------------------------------------------------------------#
         | 
| 57 | 
            +
             | 
| 3 58 | 
             
              # Returns the object's RGB value in hexadecimal notation as used in CSS.
         | 
| 4 59 | 
             
              #
         | 
| 5 60 | 
             
              # Shortens to 3 digits when possible.
         | 
    
        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.12.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: 2020- | 
| 11 | 
            +
            date: 2020-09-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: 
         | 
| 14 14 | 
             
            email: 
         | 
| @@ -21,7 +21,8 @@ files: | |
| 21 21 | 
             
            - lib/redgreenblue/48bit.rb
         | 
| 22 22 | 
             
            - lib/redgreenblue/base.rb
         | 
| 23 23 | 
             
            - lib/redgreenblue/bgr24bit.rb
         | 
| 24 | 
            -
            - lib/redgreenblue/ | 
| 24 | 
            +
            - lib/redgreenblue/cie_1931.rb
         | 
| 25 | 
            +
            - lib/redgreenblue/cie_1976.rb
         | 
| 25 26 | 
             
            - lib/redgreenblue/gamma.rb
         | 
| 26 27 | 
             
            - lib/redgreenblue/gif.rb
         | 
| 27 28 | 
             
            - lib/redgreenblue/gpl.rb
         | 
| @@ -36,14 +37,17 @@ files: | |
| 36 37 | 
             
            - lib/redgreenblue/math.rb
         | 
| 37 38 | 
             
            - lib/redgreenblue/misc.rb
         | 
| 38 39 | 
             
            - lib/redgreenblue/mix.rb
         | 
| 40 | 
            +
            - lib/redgreenblue/name.rb
         | 
| 39 41 | 
             
            - lib/redgreenblue/opt/philipshue.rb
         | 
| 40 42 | 
             
            - lib/redgreenblue/os.rb
         | 
| 41 43 | 
             
            - lib/redgreenblue/os/mac.rb
         | 
| 42 44 | 
             
            - lib/redgreenblue/ostwald.rb
         | 
| 45 | 
            +
            - lib/redgreenblue/palettes/css.gpl
         | 
| 43 46 | 
             
            - lib/redgreenblue/random.rb
         | 
| 44 47 | 
             
            - lib/redgreenblue/rgb565.rb
         | 
| 45 48 | 
             
            - lib/redgreenblue/terminal.rb
         | 
| 46 49 | 
             
            - lib/redgreenblue/version.rb
         | 
| 50 | 
            +
            - lib/redgreenblue/view.rb
         | 
| 47 51 | 
             
            - lib/redgreenblue/web.rb
         | 
| 48 52 | 
             
            homepage: https://github.com/lllisteu/redgreenblue
         | 
| 49 53 | 
             
            licenses:
         |