Let's use a genetic algorithm to find complementary colors!
Why?
😶
- Generate ten random palettes
- Calculate the fitness of each palette
- Breed the top six palettes in pairs (and calculate fitness of offspring)
- Mutate one of top six palettes (and calculate its fitness)
- Mutate one of bottom four palettes (and calculate its fitness)
- Select the top ten most fit palettes
- Repeat steps 2-6 until the steady state is reached
- Each palette is composed of two colors
- The fitness function prefers complementary colors
- The algorithm terminates after 400 loops (There is no steady state!)
Needs improvement! 😞
Breeding two palettes means that each color from one palette has its hue, saturation, and lightness mixed with a color from the other palette.
Needs improvement! 😞
Right now, mutation simply generates a new, random palette. Clearly, this could use some more thought.
The 💪 fitness of a palette is a function of its colors's hues, saturations, and lightnesses. Specifically,
- The fitness is 0 if either color is too light or too dark
- The fitness is 0 if either color is too unsaturated
- Otherwise, the fitness is the minimum squared angle between the two hues
Todo
This just returns false
right now.
Oops. 😁
Currently, we only visualize the “most fit” palette once the algorithm is finished.
I would really love to visualize the evolution of a color palette. I have two ideas on how to do this. (I am more partial to the first.)
Keep a record (probs a queue) of the algorithm's state at the beginning of its main loop.
We can then use that queue to animate the evolution of our colors.
Asynchronously step through genetic algorithm.
Abstract the genetic algorithm into an object that contains both the state of the algorithm and a #tick
-like method (which simply runs through steps 2-6 of the algorithm). Then, we can space out each tick
by a set amount of time, and we visualize the state of the algorithm after each call to tick
.
I'd love to talk to someone about how to construct some alternative fitness functions for this here algorithm.
A collection of links to influential stuff and things.
- Color scheme theory
- Color Schemer (Twitter Bot)
- Chroma