| 1 |
// Package charmtone contains an API for the CharmTone color palette. |
| 2 |
package charmtone |
| 3 |
|
| 4 |
import ( |
| 5 |
"fmt" |
| 6 |
"image/color" |
| 7 |
"slices" |
| 8 |
|
| 9 |
expcolor "github.com/charmbracelet/x/exp/color" |
| 10 |
"github.com/lucasb-eyer/go-colorful" |
| 11 |
) |
| 12 |
|
| 13 |
var _ color.Color = Key(0) |
| 14 |
|
| 15 |
// Key is a type for color keys. |
| 16 |
type Key int |
| 17 |
|
| 18 |
// Available colors. |
| 19 |
const ( |
| 20 |
Cumin Key = iota |
| 21 |
Tang |
| 22 |
Yam |
| 23 |
Paprika |
| 24 |
Bengal |
| 25 |
Uni |
| 26 |
Sriracha |
| 27 |
Coral |
| 28 |
Salmon |
| 29 |
Chili |
| 30 |
Cherry |
| 31 |
Tuna |
| 32 |
Macaron |
| 33 |
Pony |
| 34 |
Cheeky |
| 35 |
Flamingo |
| 36 |
Dolly |
| 37 |
Blush |
| 38 |
Urchin |
| 39 |
Mochi |
| 40 |
Lilac |
| 41 |
Prince |
| 42 |
Violet |
| 43 |
Mauve |
| 44 |
Grape |
| 45 |
Plum |
| 46 |
Orchid |
| 47 |
Jelly |
| 48 |
Charple |
| 49 |
Hazy |
| 50 |
Ox |
| 51 |
Sapphire |
| 52 |
Guppy |
| 53 |
Oceania |
| 54 |
Thunder |
| 55 |
Anchovy |
| 56 |
Damson |
| 57 |
Malibu |
| 58 |
Sardine |
| 59 |
Zinc |
| 60 |
Turtle |
| 61 |
Lichen |
| 62 |
Guac |
| 63 |
Julep |
| 64 |
Bok |
| 65 |
Mustard |
| 66 |
Citron |
| 67 |
Zest |
| 68 |
Pepper |
| 69 |
BBQ |
| 70 |
Charcoal |
| 71 |
Iron |
| 72 |
Oyster |
| 73 |
Squid |
| 74 |
Smoke |
| 75 |
Ash |
| 76 |
Salt |
| 77 |
Butter |
| 78 |
|
| 79 |
// Diffs: additions. The brightest color in this set is Julep, defined |
| 80 |
// above. |
| 81 |
Pickle |
| 82 |
Gator |
| 83 |
Spinach |
| 84 |
|
| 85 |
// Diffs: deletions. The brightest color in this set is Cherry, defined |
| 86 |
// above. |
| 87 |
Pom |
| 88 |
Steak |
| 89 |
Toast |
| 90 |
|
| 91 |
// Provisional. |
| 92 |
NeueGuac |
| 93 |
NeueZinc |
| 94 |
) |
| 95 |
|
| 96 |
// RGBA returns the red, green, blue, and alpha values of the color. It |
| 97 |
// satisfies the color.Color interface. |
| 98 |
func (k Key) RGBA() (r, g, b, a uint32) { |
| 99 |
c, err := colorful.Hex(k.Hex()) |
| 100 |
if err != nil { |
| 101 |
panic(fmt.Sprintf("invalid color key %d: %s: %v", k, k.String(), err)) |
| 102 |
} |
| 103 |
return c.RGBA() |
| 104 |
} |
| 105 |
|
| 106 |
// String returns the official CharmTone name of the color. It satisfies the |
| 107 |
// fmt.Stringer interface. |
| 108 |
func (k Key) String() string { |
| 109 |
return map[Key]string{ |
| 110 |
Cumin: "Cumin", |
| 111 |
Tang: "Tang", |
| 112 |
Yam: "Yam", |
| 113 |
Paprika: "Paprika", |
| 114 |
Bengal: "Bengal", |
| 115 |
Uni: "Uni", |
| 116 |
Sriracha: "Sriracha", |
| 117 |
Coral: "Coral", |
| 118 |
Salmon: "Salmon", |
| 119 |
Chili: "Chili", |
| 120 |
Cherry: "Cherry", |
| 121 |
Tuna: "Tuna", |
| 122 |
Macaron: "Macaron", |
| 123 |
Pony: "Pony", |
| 124 |
Cheeky: "Cheeky", |
| 125 |
Flamingo: "Flamingo", |
| 126 |
Dolly: "Dolly", |
| 127 |
Blush: "Blush", |
| 128 |
Urchin: "Urchin", |
| 129 |
Mochi: "Crystal", |
| 130 |
Lilac: "Lilac", |
| 131 |
Prince: "Prince", |
| 132 |
Violet: "Violet", |
| 133 |
Mauve: "Mauve", |
| 134 |
Grape: "Grape", |
| 135 |
Plum: "Plum", |
| 136 |
Orchid: "Orchid", |
| 137 |
Jelly: "Jelly", |
| 138 |
Charple: "Charple", |
| 139 |
Hazy: "Hazy", |
| 140 |
Ox: "Ox", |
| 141 |
Sapphire: "Sapphire", |
| 142 |
Guppy: "Guppy", |
| 143 |
Oceania: "Oceania", |
| 144 |
Thunder: "Thunder", |
| 145 |
Anchovy: "Anchovy", |
| 146 |
Damson: "Damson", |
| 147 |
Malibu: "Malibu", |
| 148 |
Sardine: "Sardine", |
| 149 |
Zinc: "Zinc", |
| 150 |
Turtle: "Turtle", |
| 151 |
Lichen: "Lichen", |
| 152 |
Guac: "Guac", |
| 153 |
Julep: "Julep", |
| 154 |
Bok: "Bok", |
| 155 |
Mustard: "Mustard", |
| 156 |
Citron: "Citron", |
| 157 |
Zest: "Zest", |
| 158 |
Pepper: "Pepper", |
| 159 |
BBQ: "BBQ", |
| 160 |
Charcoal: "Charcoal", |
| 161 |
Iron: "Iron", |
| 162 |
Oyster: "Oyster", |
| 163 |
Squid: "Squid", |
| 164 |
Smoke: "Smoke", |
| 165 |
Salt: "Salt", |
| 166 |
Ash: "Ash", |
| 167 |
Butter: "Butter", |
| 168 |
|
| 169 |
// Diffs: additions. |
| 170 |
Pickle: "Pickle", |
| 171 |
Gator: "Gator", |
| 172 |
Spinach: "Spinach", |
| 173 |
|
| 174 |
// Diffs: deletions. |
| 175 |
Pom: "Pom", |
| 176 |
Steak: "Steak", |
| 177 |
Toast: "Toast", |
| 178 |
|
| 179 |
// Provisional. |
| 180 |
NeueGuac: "Neue Guac", |
| 181 |
NeueZinc: "Neue Zinc", |
| 182 |
}[k] |
| 183 |
} |
| 184 |
|
| 185 |
// Hex returns the hex value of the color. |
| 186 |
func (k Key) Hex() string { |
| 187 |
return map[Key]string{ |
| 188 |
Cumin: "#BF976F", |
| 189 |
Tang: "#FF985A", |
| 190 |
Yam: "#FFB587", |
| 191 |
Paprika: "#D36C64", |
| 192 |
Bengal: "#FF6E63", |
| 193 |
Uni: "#FF937D", |
| 194 |
Sriracha: "#EB4268", |
| 195 |
Coral: "#FF577D", |
| 196 |
Salmon: "#FF7F90", |
| 197 |
Chili: "#E23080", |
| 198 |
Cherry: "#FF388B", |
| 199 |
Tuna: "#FF6DAA", |
| 200 |
Macaron: "#E940B0", |
| 201 |
Pony: "#FF4FBF", |
| 202 |
Cheeky: "#FF79D0", |
| 203 |
Flamingo: "#F947E3", |
| 204 |
Dolly: "#FF60FF", |
| 205 |
Blush: "#FF84FF", |
| 206 |
Urchin: "#C337E0", |
| 207 |
Mochi: "#EB5DFF", |
| 208 |
Lilac: "#F379FF", |
| 209 |
Prince: "#9C35E1", |
| 210 |
Violet: "#C259FF", |
| 211 |
Mauve: "#D46EFF", |
| 212 |
Grape: "#7134DD", |
| 213 |
Plum: "#9953FF", |
| 214 |
Orchid: "#AD6EFF", |
| 215 |
Jelly: "#4A30D9", |
| 216 |
Charple: "#6B50FF", |
| 217 |
Hazy: "#8B75FF", |
| 218 |
Ox: "#3331B2", |
| 219 |
Sapphire: "#4949FF", |
| 220 |
Guppy: "#7272FF", |
| 221 |
Oceania: "#2B55B3", |
| 222 |
Thunder: "#4776FF", |
| 223 |
Anchovy: "#719AFC", |
| 224 |
Damson: "#007AB8", |
| 225 |
Malibu: "#00A4FF", |
| 226 |
Sardine: "#4FBEFE", |
| 227 |
Zinc: "#10B1AE", |
| 228 |
Turtle: "#0ADCD9", |
| 229 |
Lichen: "#5CDFEA", |
| 230 |
Guac: "#12C78F", |
| 231 |
Julep: "#00FFB2", |
| 232 |
Bok: "#68FFD6", |
| 233 |
Mustard: "#F5EF34", |
| 234 |
Citron: "#E8FF27", |
| 235 |
Zest: "#E8FE96", |
| 236 |
Pepper: "#201F26", |
| 237 |
BBQ: "#2d2c35", |
| 238 |
Charcoal: "#3A3943", |
| 239 |
Iron: "#4D4C57", |
| 240 |
Oyster: "#605F6B", |
| 241 |
Squid: "#858392", |
| 242 |
Smoke: "#BFBCC8", |
| 243 |
Ash: "#DFDBDD", |
| 244 |
Salt: "#F1EFEF", |
| 245 |
Butter: "#FFFAF1", |
| 246 |
|
| 247 |
// Diffs: additions. |
| 248 |
Pickle: "#00A475", |
| 249 |
Gator: "#18463D", |
| 250 |
Spinach: "#1C3634", |
| 251 |
|
| 252 |
// Diffs: deletions. |
| 253 |
Pom: "#AB2454", |
| 254 |
Steak: "#582238", |
| 255 |
Toast: "#412130", |
| 256 |
|
| 257 |
// Provisional. |
| 258 |
NeueGuac: "#00b875", |
| 259 |
NeueZinc: "#0e9996", |
| 260 |
}[k] |
| 261 |
} |
| 262 |
|
| 263 |
// Keys returns a slice of all CharmTone color keys. |
| 264 |
func Keys() []Key { |
| 265 |
return []Key{ |
| 266 |
Cumin, |
| 267 |
Tang, |
| 268 |
Yam, |
| 269 |
Paprika, |
| 270 |
Bengal, |
| 271 |
Uni, |
| 272 |
Sriracha, |
| 273 |
Coral, |
| 274 |
Salmon, |
| 275 |
Chili, |
| 276 |
Cherry, |
| 277 |
Tuna, |
| 278 |
Macaron, |
| 279 |
Pony, |
| 280 |
Cheeky, |
| 281 |
Flamingo, |
| 282 |
Dolly, |
| 283 |
Blush, |
| 284 |
Urchin, |
| 285 |
Mochi, |
| 286 |
Lilac, |
| 287 |
Prince, |
| 288 |
Violet, |
| 289 |
Mauve, |
| 290 |
Grape, |
| 291 |
Plum, |
| 292 |
Orchid, |
| 293 |
Jelly, |
| 294 |
Charple, |
| 295 |
Hazy, |
| 296 |
Ox, |
| 297 |
Sapphire, |
| 298 |
Guppy, |
| 299 |
Oceania, |
| 300 |
Thunder, |
| 301 |
Anchovy, |
| 302 |
Damson, |
| 303 |
Malibu, |
| 304 |
Sardine, |
| 305 |
Zinc, |
| 306 |
Turtle, |
| 307 |
Lichen, |
| 308 |
Guac, |
| 309 |
Julep, |
| 310 |
Bok, |
| 311 |
Mustard, |
| 312 |
Citron, |
| 313 |
Zest, |
| 314 |
Pepper, |
| 315 |
BBQ, |
| 316 |
Charcoal, |
| 317 |
Iron, |
| 318 |
Oyster, |
| 319 |
Squid, |
| 320 |
Smoke, |
| 321 |
Ash, |
| 322 |
Salt, |
| 323 |
Butter, |
| 324 |
|
| 325 |
// XXX: additions and deletions are not included, yet. |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
// IsPrimary indicates which colors are part of the core palette. |
| 330 |
func (k Key) IsPrimary() bool { |
| 331 |
return slices.Contains([]Key{ |
| 332 |
Charple, |
| 333 |
Dolly, |
| 334 |
Julep, |
| 335 |
Zest, |
| 336 |
Butter, |
| 337 |
}, k) |
| 338 |
} |
| 339 |
|
| 340 |
// IsSecondary indicates which colors are part of the secondary palette. |
| 341 |
func (k Key) IsSecondary() bool { |
| 342 |
return slices.Contains([]Key{ |
| 343 |
Hazy, |
| 344 |
Blush, |
| 345 |
Bok, |
| 346 |
}, k) |
| 347 |
} |
| 348 |
|
| 349 |
// IsTertiary indicates which colors are part of the tertiary palette. |
| 350 |
func (k Key) IsTertiary() bool { |
| 351 |
return slices.Contains([]Key{ |
| 352 |
Turtle, |
| 353 |
Malibu, |
| 354 |
Violet, |
| 355 |
Tuna, |
| 356 |
Coral, |
| 357 |
Uni, |
| 358 |
}, k) |
| 359 |
} |
| 360 |
|
| 361 |
// Blend returns a slice of colors blended between the given Keys. Blending is |
| 362 |
// done as Hcl to stay in gamut. |
| 363 |
func Blend(size int, keys ...Key) []color.Color { |
| 364 |
colors := make([]color.Color, len(keys)) |
| 365 |
for i, k := range keys { |
| 366 |
colors[i] = color.Color(k) |
| 367 |
} |
| 368 |
return expcolor.Blend(size, colors...) |
| 369 |
} |