PixCell

Challenge

Create a simulation of pixels that survive, reproduce, and evolve over time into an ecosystem that resembles a target image.

Solution

PixCell has 3 steps that are repeated for an indefinite amount of generations, resulting in a population of pixels closely resembling the target image.

  1. New Generation
    Each cell has a genome encoded in a 64-bit integer containing their attributes and information. This consists of the color of the cell, which direction it moves in, how long it travels for, if it will reverse direction, when it will reverse direction, and its age. Initially, 3000 cells with each attribute completely randomized are generated randomly over the entire canvas.

  2. Selection
    During the duration of each generation, the cells move around based on their direction and movement attributes. At the generation's end, each cell is scored based on how close its color is to the color of the pixel at the image's corresponding location. The cells whose color differs by the image pixel's color by 15% or less are kept for reproduction in future generations, and the rest are killed off.

  3. Crossover and Mutation
    At the end of each generation, the surviving cells reproduce by breeding with the partner cell closest to them by distance. Each pair's offspring consists of some random weighted distribution of their parent's genome. There is also a 0.1% chance that any one of the attributes in the offspring's genome undergo mutation, resulting in a randomly generated value for that specific attribute as opposed to an inherited value from the parents.