Class: Wasko::Palette::Original
- Defined in:
- lib/wasko/palettes/original.rb
Overview
Since I change my mind pretty frequently on color schemes etc. Putting the actual logic in a class so it’s easier to extend.
Instance Method Summary collapse
- #ansi_colors? ⇒ Boolean
- #base_color_with_tint(color_name) ⇒ Object
-
#black ⇒ Object
Returns a ‘color`-instance of black.
-
#colors ⇒ Object
Hash of the color palette TODO: attr_accessible.
-
#colors! ⇒ Object
Creates a palette based on the ‘@base`-color.
- #dark_base_color? ⇒ Boolean
-
#inverse_brightness ⇒ Object
To calculate colors that will fit our base color we need to find out to brighten them, or darken them.
-
#mix_base_with(color_name, mix_value = 50, brightness = 30) ⇒ Object
Just a utility method that mixes colors, for more info on this check the docs of the ‘color`-gem.
-
#opposite_color ⇒ Object
Checks the brightness of the base color and returns the appropriate opposite color.
-
#white ⇒ Object
Returns a ‘color`-instance of white.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Wasko::Palette::Base
Instance Method Details
#ansi_colors? ⇒ Boolean
20 21 22 |
# File 'lib/wasko/palettes/original.rb', line 20 def ansi_colors? p.colors[:yellow] end |
#base_color_with_tint(color_name) ⇒ Object
84 85 86 87 |
# File 'lib/wasko/palettes/original.rb', line 84 def base_color_with_tint(color_name) brightness = inverse_brightness * @contrast mix_base_with(color_name, 80, brightness) end |
#black ⇒ Object
Returns a ‘color`-instance of black
16 17 18 |
# File 'lib/wasko/palettes/original.rb', line 16 def black Wasko::Color.color_from_string("black") end |
#colors ⇒ Object
Hash of the color palette TODO: attr_accessible
46 47 48 |
# File 'lib/wasko/palettes/original.rb', line 46 def colors @colors end |
#colors! ⇒ Object
Creates a palette based on the ‘@base`-color. This generates a color palette which has taken a good look at [Solarized](ethanschoonover.com/solarized) The plus side is you can use any base color, the downside is, the colors won’t be picked as well as when using [Solarized](ethanschoonover.com/solarized) so if that’s what you need, check it out.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wasko/palettes/original.rb', line 56 def colors! p = {} p[:base] = @base p[:foreground] = @base.mix_with(opposite_color, @contrast + 0) p[:bold] = @base.mix_with(opposite_color, @contrast + 5) p[:selection] = @base.adjust_brightness inverse_brightness * @contrast p[:selected] = p[:bold] p[:cursor] = p[:foreground] # ANSI Colors p[:red] = mix_base_with("red", 50, inverse_brightness * @contrast) p[:green] = mix_base_with("green", 50, inverse_brightness * @contrast) p[:yellow] = mix_base_with("yellow", 50, inverse_brightness * @contrast) p[:white] = mix_base_with("white", 35, inverse_brightness * @contrast) p[:black] = mix_base_with("black", 35, inverse_brightness * @contrast) p[:blue] = mix_base_with("blue", 50, inverse_brightness * (@contrast)) p[:magenta] = mix_base_with("#CA1F7B", 35, inverse_brightness * @contrast) p[:cyan] = mix_base_with("#00FFFF", 50, inverse_brightness * (@contrast - 20)) @colors = p end |
#dark_base_color? ⇒ Boolean
40 41 42 |
# File 'lib/wasko/palettes/original.rb', line 40 def dark_base_color? @base.brightness < 0.5 end |
#inverse_brightness ⇒ Object
To calculate colors that will fit our base color we need to find out to brighten them, or darken them
36 37 38 |
# File 'lib/wasko/palettes/original.rb', line 36 def inverse_brightness @base.brightness > 0.5 ? -1 : 1 end |
#mix_base_with(color_name, mix_value = 50, brightness = 30) ⇒ Object
Just a utility method that mixes colors, for more info on this check the docs of the ‘color`-gem.
79 80 81 |
# File 'lib/wasko/palettes/original.rb', line 79 def mix_base_with(color_name, mix_value = 50, brightness = 30) @base.mix_with(Wasko::Color.color_from_string(color_name), mix_value).adjust_brightness(brightness) end |
#opposite_color ⇒ Object
Checks the brightness of the base color and returns the appropriate opposite color.
For example black will return white, white will return black.
29 30 31 |
# File 'lib/wasko/palettes/original.rb', line 29 def opposite_color @base.brightness > 0.5 ? black : white end |
#white ⇒ Object
Returns a ‘color`-instance of white
11 12 13 |
# File 'lib/wasko/palettes/original.rb', line 11 def white Wasko::Color.color_from_string("white") end |