Fast Evolution

High energy extraction results in fast evolution. Best rendered with flat RGB colours to see how evolutionary lineage develops over time.

Slow Life

Low energy extraction long lives is best rendered with agent energy affecting colour brightness. Here colour starts bright at start of life and is darkest when each agent divides creating two new agents.

Faster Life

Rending fewer generations speeds up the visuals. Here I start with a quick burst of evolution to smooth out the diversity before lowering extraction rate.

First Installation

Installation using Rasberry Pi 3, Button SHIM, charity shop projector and picture frame.

Button Demo

Button 3 increases the energy extraction rate, quickens time to reproduction and speeds up evolution. Button 2 changes render texturing mode and button 1 changes render colouring mode.

LED Window Installation

The simulation playing on position-mapped LED strings in a window display for Window Wanderland 2020. (Spot the broken LED!)

How it Works

World and Energy

Loki is a one-dimensional grid world where each grid location can provide energy where each grid location has an unlimited amount of energy. Living at each location is an agent with a genetically-determined colour (and a genetic key).

Agents extract energy from their location in order to multiply. Each world location has its own lock (typically 3 numbers, a bit like a required PIN) that guards the energy and each agent uses its genetically-defined key (like its own PIN) to access the energy.

It's not an all-or-nothing thing - the better the key matches the lock the more energy the agent can extract at each time step.

Agents also evolve the degree to which their key is specialised, i.e. how accurate it needs to be. Highly specialised keys unlock more energy but are not so tolerant to mismatches. So there's a trade-off; the balance depends on the type of environment. If locks vary considerably across adjacent positions in the world (a rough landscape) then generalist agents can populate neighbouring spaces easier than specialists. Specialists do better if neighbouring areas are similar (see below).


When any agent's energy reaches its threshold for replication it spawns an offspring that occupies a neighbouring location, remvoving the previous occupant. The offspring inherits a variation of their parent's genetic colour and key.

The parent's energy is shared equally between the two. Colour mutation is minimal so related agents can be identified over time by slowly evolving colour.

In 1D the screen shows a scrolling down history of the living agents in the 1D world. The agents live on a line running across the top of the screen. After each agent has been updated the history is scrolled down and the new agent states written to the top row. Running evolution fast (by increasing the rate of energy extraction) is a pretty way to see agent evolution.

When evolution is slowed down and agent energy level shown as their brightness you can see individual agent replication events taking place.

The keys and locks in these runs have 3 values each so we can visualise then as RGB colours. Here the top row is showing the lock values across the world. It forms a simple a greyscale gradient here; although they can mutate over time. You can see that the agent keys have evolved to roughly match the gradient. Agent keys vary more wildy than their colours because key mutation uses a different type of mutation noise.

I haven't been able to produce any particularly pretty visuals with 2D worlds. Might be a case of finding the right parameters. If you find some settings that work then let me know.

A Touch of Science

I wondered if generalist agents would be the more successful agents in a rugged landscape (a world where locks varied wildly) because they would have the ability to colonise unfamiliar territory. To test this out I ran two experiments; one with random locks across the world and the other with locks that varied gradually across the world. A rugged landscape vs a smooth landscape.

Here each world location has been assigned a random lock. The three lock values at each location are shown as RGB across the top, hence the random colours on the top row. For an agent to be able to successfully colonise a neighbouring location it needs to be a bit of a generalist. The columns and hard boundries here illustrate how agent evolution is constrained within local areas.

Here the three lock values at each location vary smoothly from 0 on the left to 1 on the right of the world, shown as a grey gradient. Specialising generates more energy (therefore faster replication) and does not hamper the agents' ability to colonise the local area as its locks are similar. There smoother colour variation and lack of vertical boundaries colour show how single genotypes can replicate across wide areas.

This graph illustrates the difference in generalisation vs specialisatoin. Sigma is the genetic parameter that agents can evolve to control their specialisation. The agents in the rough landscape evolve a higher sigma, i.e less discerning. As locks evolve, so the landscape changes and in turn agents will evolve to match their keys and tune their specialisation/generalistion to match the ruggedness.

  • Rough landscapes promotes generalists
  • Smooth landscapes produce prettier patterns

Running Loki

Project, instructions, configuration, and open source python all on GitHub.

It runs windowed, fullscreen, headless, as a streaming web server or frame-storing mode to make videos.

DIY Standalone Installation

Loki running headless, starting fullscreen on boot and using hardware SHIM buttons to change modes.


  • Raspberry Pi 3B+ - £30
  • Pibow Rainbow case - £13
  • Button SHIM - £7
  • 3.5mm composite video cable - £4
  • Mini composite video projector - £20 (charity shop)
  • Picture frame - £4 (charity shop)