Class: Wasko::Palette::TheOriginal
- Inherits:
-
Object
- Object
- Wasko::Palette::TheOriginal
- Defined in:
- lib/wasko/palette.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
-
#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
-
#initialize(color_string, contrast = 0) ⇒ TheOriginal
constructor
Takes a valid css color string and an optional contrast argument.
-
#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.
Constructor Details
#initialize(color_string, contrast = 0) ⇒ TheOriginal
Takes a valid css color string and an optional contrast argument. The contrast is useful to tweak the output of things.
It sets a base color ‘@base` and creates a color palette derived from the base color using the `colors!` method.
16 17 18 19 20 21 22 |
# File 'lib/wasko/palette.rb', line 16 def initialize(color_string, contrast = 0) @colors = {} @base = Wasko::Color.color_from_string(color_string) @base = white unless @base @contrast = 30 + contrast colors! end |
Instance Method Details
#black ⇒ Object
Returns a ‘color`-instance of black
30 31 32 |
# File 'lib/wasko/palette.rb', line 30 def black Wasko::Color.color_from_string("black") end |
#colors ⇒ Object
Hash of the color palette TODO: attr_accessible
56 57 58 |
# File 'lib/wasko/palette.rb', line 56 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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wasko/palette.rb', line 66 def colors! p = {} p[:base] = @base p[:foreground] = @base.mix_with(opposite_color, @contrast + 18) p[:bold] = @base.mix_with(opposite_color, @contrast + 19.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
50 51 52 |
# File 'lib/wasko/palette.rb', line 50 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
46 47 48 |
# File 'lib/wasko/palette.rb', line 46 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.
89 90 91 |
# File 'lib/wasko/palette.rb', line 89 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.
39 40 41 |
# File 'lib/wasko/palette.rb', line 39 def opposite_color @base.brightness > 0.5 ? black : white end |
#white ⇒ Object
Returns a ‘color`-instance of white
25 26 27 |
# File 'lib/wasko/palette.rb', line 25 def white Wasko::Color.color_from_string("white") end |