Module: Abachrome::ColorMixins::Harmonies
- Defined in:
- lib/abachrome/color_mixins/harmonies.rb
Instance Method Summary collapse
-
#analogous(angle: 30, space: :oklch) ⇒ Array<Abachrome::Color>
Generates an analogous color harmony.
-
#complementary(space: :oklch) ⇒ Array<Abachrome::Color>
Generates a complementary color harmony.
-
#split_complementary(space: :oklch) ⇒ Array<Abachrome::Color>
Generates a split-complementary color harmony.
-
#tetradic(space: :oklch) ⇒ Array<Abachrome::Color>
Generates a tetradic (square) color harmony.
-
#triadic(space: :oklch) ⇒ Array<Abachrome::Color>
Generates a triadic color harmony.
Instance Method Details
#analogous(angle: 30, space: :oklch) ⇒ Array<Abachrome::Color>
Generates an analogous color harmony. Analogous colors are adjacent to each other on the color wheel, typically within ±30 degrees. This creates a harmonious, cohesive palette.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/abachrome/color_mixins/harmonies.rb', line 35 def analogous(angle: 30, space: :oklch) original_space = color_space # Convert to the specified space for hue manipulation color_in_space = space == color_space.id ? self : to_color_space(space) l, c, h = color_in_space.coordinates # Generate analogous colors by rotating hue color_minus = create_harmony_color(l, c, h - angle, space) color_plus = create_harmony_color(l, c, h + angle, space) # Convert back to original color space [ color_minus.to_color_space(original_space.id), self, color_plus.to_color_space(original_space.id) ] end |
#complementary(space: :oklch) ⇒ Array<Abachrome::Color>
Generates a complementary color harmony. Complementary colors are opposite each other on the color wheel (180° apart). They create maximum contrast and vibrant combinations.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/abachrome/color_mixins/harmonies.rb', line 60 def complementary(space: :oklch) original_space = color_space # Convert to the specified space for hue manipulation color_in_space = space == color_space.id ? self : to_color_space(space) l, c, h = color_in_space.coordinates # Generate complementary color by rotating hue 180° complement = create_harmony_color(l, c, h + 180, space) # Convert back to original color space [ self, complement.to_color_space(original_space.id) ] end |
#split_complementary(space: :oklch) ⇒ Array<Abachrome::Color>
Generates a split-complementary color harmony. Split-complementary uses the base color plus two colors adjacent to its complement (at 150° and 210° from the base). This creates strong visual contrast while being more subtle than a pure complementary scheme.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/abachrome/color_mixins/harmonies.rb', line 136 def split_complementary(space: :oklch) original_space = color_space # Convert to the specified space for hue manipulation color_in_space = space == color_space.id ? self : to_color_space(space) l, c, h = color_in_space.coordinates # Generate split-complementary colors at 150° and 210° (complement ± 30°) color_1 = create_harmony_color(l, c, h + 150, space) color_2 = create_harmony_color(l, c, h + 210, space) # Convert back to original color space [ self, color_1.to_color_space(original_space.id), color_2.to_color_space(original_space.id) ] end |
#tetradic(space: :oklch) ⇒ Array<Abachrome::Color>
Generates a tetradic (square) color harmony. Tetradic colors are evenly spaced around the color wheel at 90° intervals. They create rich, varied palettes with multiple complementary pairs.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/abachrome/color_mixins/harmonies.rb', line 108 def tetradic(space: :oklch) original_space = color_space # Convert to the specified space for hue manipulation color_in_space = space == color_space.id ? self : to_color_space(space) l, c, h = color_in_space.coordinates # Generate tetradic colors by rotating hue 90°, 180°, and 270° color_1 = create_harmony_color(l, c, h + 90, space) color_2 = create_harmony_color(l, c, h + 180, space) color_3 = create_harmony_color(l, c, h + 270, space) # Convert back to original color space [ self, color_1.to_color_space(original_space.id), color_2.to_color_space(original_space.id), color_3.to_color_space(original_space.id) ] end |
#triadic(space: :oklch) ⇒ Array<Abachrome::Color>
Generates a triadic color harmony. Triadic colors are evenly spaced around the color wheel at 120° intervals. They create vibrant, balanced palettes with good contrast.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/abachrome/color_mixins/harmonies.rb', line 83 def triadic(space: :oklch) original_space = color_space # Convert to the specified space for hue manipulation color_in_space = space == color_space.id ? self : to_color_space(space) l, c, h = color_in_space.coordinates # Generate triadic colors by rotating hue 120° and 240° color_1 = create_harmony_color(l, c, h + 120, space) color_2 = create_harmony_color(l, c, h + 240, space) # Convert back to original color space [ self, color_1.to_color_space(original_space.id), color_2.to_color_space(original_space.id) ] end |