Module: Chroma
- Defined in:
- lib/chroma.rb,
lib/chroma/color.rb,
lib/chroma/errors.rb,
lib/chroma/version.rb,
lib/chroma/harmonies.rb,
lib/chroma/color_modes.rb,
lib/chroma/rgb_generator.rb,
lib/chroma/color/modifiers.rb,
lib/chroma/converters/base.rb,
lib/chroma/palette_builder.rb,
lib/chroma/color/attributes.rb,
lib/chroma/helpers/bounders.rb,
lib/chroma/color/serializers.rb,
lib/chroma/rgb_generator/base.rb,
lib/chroma/rgb_generator/from_hsl.rb,
lib/chroma/rgb_generator/from_hsv.rb,
lib/chroma/rgb_generator/from_rgb.rb,
lib/chroma/converters/hsl_converter.rb,
lib/chroma/converters/hsv_converter.rb,
lib/chroma/converters/rgb_converter.rb,
lib/chroma/rgb_generator/from_string.rb,
lib/chroma/rgb_generator/from_hsl_values.rb,
lib/chroma/rgb_generator/from_hsv_values.rb,
lib/chroma/rgb_generator/from_rgb_values.rb,
lib/chroma/rgb_generator/from_hex_string_values.rb
Overview
The main module.
Defined Under Namespace
Modules: ColorModes, Converters, Errors, Helpers, RgbGenerator Classes: Color, Harmonies, PaletteBuilder
Constant Summary collapse
- VERSION =
'0.2.0'
Class Method Summary collapse
-
.define_palette(name, &block) ⇒ Symbol, String
Defines a custom palette for use by Color#palette.
-
.hex_from_name(name) ⇒ String?
Returns the hexadecimal string representation of a named color and nil if no match is found.
-
.name_from_hex(hex) ⇒ String?
Returns the color name of a hexadecimal color if available and nil if no match is found.
-
.paint(input) ⇒ Color
Returns a new instance of color.
Class Method Details
.define_palette(name, &block) ⇒ Symbol, String
Defines a custom palette for use by Chroma::Color#palette. Uses a DSL inside
block
that mirrors the methods in Chroma::Color::Modifiers.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/chroma.rb', line 110 def define_palette(name, &block) if Harmonies.method_defined? name raise Errors::PaletteDefinedError, "Palette `#{name}' already exists" end palette_evaluator = PaletteBuilder.build(&block) Harmonies.send(:define_method, name) do palette_evaluator.evaluate(@color) end end |
.hex_from_name(name) ⇒ String?
Returns the hexadecimal string representation of a named color and nil if no match is found. Favors 3-character hexadecimal if possible.
73 74 75 |
# File 'lib/chroma.rb', line 73 def hex_from_name(name) named_colors_map[name] end |
.name_from_hex(hex) ⇒ String?
Returns the color name of a hexadecimal color if available and nil if no match is found. Requires 3-character hexadecimal input for applicable colors.
88 89 90 |
# File 'lib/chroma.rb', line 88 def name_from_hex(hex) hex_named_colors_map[hex] end |