Coder Social home page Coder Social logo

colors-and-stuff's Introduction

Is this 🎨?

Let's use a genetic algorithm to find complementary colors!

Why?

😢

View the demo!

The Algorithm

  1. Generate ten random palettes
  2. Calculate the fitness of each palette
  3. Breed the top six palettes in pairs (and calculate fitness of offspring)
  4. Mutate one of top six palettes (and calculate its fitness)
  5. Mutate one of bottom four palettes (and calculate its fitness)
  6. Select the top ten most fit palettes
  7. Repeat steps 2-6 until the steady state is reached

The Current Implementation

  • Each palette is composed of two colors
  • The fitness function prefers complementary colors
  • The algorithm terminates after 400 loops (There is no steady state!)

The Breeding

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.

The Mutation

Needs improvement! 😞

Right now, mutation simply generates a new, random palette. Clearly, this could use some more thought.

The Fitness

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

The Steady State

Todo ⚠️

This just returns false right now.

Oops. 😁

The Visualization of The Algorithm

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.)

Idea 1: A state queue

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.

Idea 2: Asynchronous processing

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.

πŸ‘‹ Hey! Get in touch!

I'd love to talk to someone about how to construct some alternative fitness functions for this here algorithm.

✨ The spark list

A collection of links to influential stuff and things.

colors-and-stuff's People

Contributors

brettimus avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

colors-and-stuff's Issues

Fitness only evaluates hue

Because the fitness function ignores saturation and lightness, we can have two colors whose hues are complementary, but one of them might look white, black, or gray. (E.g., one of them might have 100% lightness and actually look white.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.