Plant Evolution Simulation

This projects aims to model plant evolution through natural selection. It does this by simulating an environment in which plant like entities grow and reproduce, while competing for light and space.

In normal genetic algorithms there are distinct stages or generations:

  1. Generate a random population.
  2. Test them all using a fitness function.
  3. Select a fit portion of the population, based on the fitness function.
  4. Create the next generation from the fit individuals, usually by copying them and adding small mutations to some.

In this program however there is no fitness function and there are no set generations. Instead the fitness of an individual can be considered to be how many offspring it manages to have. There is no equivalent to generations because, as in real life, some plants will outlive others and successfully have offspring before or after each other.

In any situation where you have variation in a population, inheritable traits, mutation and variable survival you will get evolution, it is unavoidable and can be applied in any situation in which those traits all exist together.

Try it yourself: Evolving-Plants.jar

Source code (MIT License): Github

View Image View Image View Image
  • Create custom genomes and save them for use in the simulation.
  • Select plants and view their genome, modify it, plant some of their offspring.
  • Leave it to run with different starting configurations and see how it affects the evolution of the plants.
  • Observe how small population sizes can lead to sub optimal design due to genetic drift.
  • Observe how niches can be formed by large plants, a thick canopy can lead to small plants that cannot survive in direct light.
  • Observe how a high mutation rate leads to a population of mangled forms, ill suited for their environment.


If you are having trouble running the program, please try this quick guide.

What Am I Looking At?

Each plant is represented by lines and circles. Each line is a stem and the circle is a leaf. Light shines directly down from the top of the simulation and if shown, casts shadows beneath the plant.

The light is coloured and depending on the colour of the leaf, only certain colours of light will be blocked by the leaf. A red leaf casts a red shadow, meaning that it has absorbed all of the green and blue light, any plants trying to grow in a red shadow need to be able to absorb red light to survive, as there is no blue or green light left.

Plants start as seeds, these will germinate if there is enough space for them and grow into a full grown plant. Once fully grown, any excess energy a plant has goes into making more seeds, which it will drop from its leaves.

As plants age they use up more energy, their metabolism increases. This leaves less excess energy for creating more seeds and eventually causes the plant to die, creating space in the simulation for new seeds to germinate.

The Genetics

A plant's genes are represented by a string of characters, each of which is a single instruction. To decide the shape of a plant each instruction is read in turn, these instructions create a node tree which is 'crawled' by a 'robot'. The robot can crawl up and down the tree, from node to node, and each instruction that is read out is applied to the node that the robot is currently at.

At the end of the instructions, any nodes which don't have any children become leaves.

Each of the instructions is listed below:

  • ^ : Make the current node grow up one unit.
  • v : Make the current node grow down one unit.
  • < : Make the current node grow left one unit
  • > : Make the current node grow right one unit.
  • N : Create a new node, whose parent is the current node and crawl to it.
  • S : Toggle whether the current node can produce seeds.
  • + : Crawl up the node tree to the youngest child node.
  • - : Crawl down the node tree to the parent node.
  • | : Ignore all further instructions.

For example, for the genes: '^ N < - N >'

  1. All plants start as a one unit tall stem with a leaf.
  2. Grow up, making the plant two units tall
  3. Create a new node, which increases the height to three units and leaves a parent node one unit below it.
  4. Grow Left, making the current node grow one to the left, note this doesn't move the node below it.
  5. Crawl back down the tree to the parent node.
  6. Create a new node, this will grow up a unit leaving the parent node below it.
  7. Grow right, this moves the newest node one unit to the right, leaving a plant that is three units high with two leaves at the top, one to the left and one to the right.

The Interface

A run through of what each button does:

Simulation Speed menu:

  • Warp Speed: This doesn't change how the simulation works, it simply causes multiple steps of the simulation to be calculated between each time it is drawn. It greatly increases the speed at which the simulation progresses.
  • Playback Speed: The simulation works by knowing how many seconds have passed between each step, this option allows you to tweak this number, telling the simulation that half, or twice as many seconds have gone past. This information is used to calculate how much a plant should have grown since the last step, how far a seed should have fallen. Warning: if your computer is very slow and this value is high, strange things can happen in the simulation. A seed can germinate, grow and die in a single step, because the simulation thinks so much time has passed. This can lead to extinction as plants do not have enough time to produce seeds before dying.
  • Reset Simulation: Clears all plants and filters from the simulation, does not change simulation settings.

Interactions menu:

  • Select Plants: Allows the user to click on a leaf to select a plant, the plant is then highlighted. At this time there is no further use for this feature.
  • Plant Seeds: Allows the user to place seeds in the simulation. They are based on the current genes, or the default genes if no other genes have been extracted or loaded.
  • Extract Genes: Allows the user to get genes from a plant, by clicking on one of its leaves, which then can be saved or used with the plant seeds option.
  • Kill Plants: Allows the user to remove a plants from the simulation by clicking on a plant's leaf or clicking and dragging through multiple plant leaves.
  • Move Filters: Allows the user to move a light filter, by clicking and dragging on one of its handles. (See Filter Options menu below)
  • Delete Filters: Allows the user to remove a light filter, by clicking on one of its handles. (See Filter Options menu below)

Plant Options menu:

  • Leaf Size: Leaf size is set for a plant when it germinates, leaves will grow to be as large as this setting.
  • Stalk Length: This denotes the size of each growth unit. A plant that grows three units tall will be three stalk lengths high. (See 'The Genetics' above for details on what a unit means.)
  • Chance of Mutant Offspring (%): When a plant produces a seed the DNA it passes on is identical to its own, unless it is mutated. This setting is the chance of a seed inheriting mutated DNA.
  • Damage to Mutant DNA (%): This represents the proportion of DNA which will be affected by mutation. DNA with 50 instructions exposed to a 10% mutation will on average gain 5 mutations.
  • Plant is [size] if Bigger Than: These are shown by dotted lines across the screen, a plant's size category is decided purely by its height. You can easily tell a plant's height category by seeing which line it is growing above.
  • [size] plant Spacing: For a seed to germinate it needs space. A large seed will only germinate if it is far away enough from all other large plants. The distance a seed needs to be from other plants of its own size category is decided here.

Light Options menu:

  • Show Light: This option pauses the simulation and gives a graphical representation of the light levels and colours in the simulation. Here you can observe shadows cast by plants and light filters.
  • Light Intensity: These sliders allow you to control how much of each colour of light enters the simulation. Removing all blue light from the simulation can tend to lead towards the evolution of blue leaved plants, i.e. plants that absorb and use all colours except blue, however other factors can influence leaf colour.
  • Leaf Transparency: When set to 0, leaves remove all light they can and cast a shadow of the same colour as their leaves. At 100 the leaves still collect the same energy from the light they are receiving but they do not cast shadows.

Filter Options menu:

  • Filter Width: The width of a filter can be anywhere between 0 and the width of the entire simulation.
  • Colour Sliders: The colour shadow that a filter will produce is decided by these sliders.
  • Create Filter: Creates a filter with the settings denoted by the above sliders, the filter is placed in the simulation at half the height starting at the leftmost point of the simulation currently being observed..

Gene Options menu:

  • Text Box: Enter the name you'd like to use when saving genes.
  • Save Current Genes: The genes currently loaded, or most recently extracted from a plant are saved using the name denoted above.
  • Saved Genes: A list of icons with names represents the genes that you currently have saved.
  • Load Genes: When this option is selected, clicking on an existing set of saved genes, listed above, will make them the current genes which then be used with the plant seeds option.
  • Delete Genes: When this option is selected, clicking on an existing set of saved genes, listed above, will delete them from your computer.
  • Open Folder: This opens the folder in which all genes are being saved.

Preset Options menu:

  • Text Box: Enter the name you'd like to use when saving presets.
  • Save Current Settings: The position of all sliders, which denote things like stem length, light intensity e.t.c are saved into a file.
  • Saved Presets: A list of icons with names represents the settings that you currently have saved.
  • Load Presets: When this option is selected each of the sliders are set to the positions that are in the save file.
  • Delete Presets: When this option is selected, clicking on an existing set of saved presets, listed above, will delete them from your computer.
  • Open Folder: This opens the folder in which all presets are being saved.

Development log

~ August 2014 ~

I've always thought that the older versions, while slow and full of unnecessary features, managed to capture something that the newer program did not. The new program has to be run at ridiculously high speeds in order to observe evolution happening and then it is usually very stochastic and leads to very boring shapes emerging.

For that reason I've revisited one of the older programs, the one that simulates recombination of genetic material from two parents

So far the progress has mostly been updating it to use a newer version of my interface library and removing a few features that don't add anything to the simulation.

Try it yourself: Plants.jar

View Image

~ February 2014 ~

I've been playing around with the way that genes work and the result is this new branch of the program. It is based on 2.0 but completely changes the way that genes work. The genes still define the exact shape that the plant will grow into but they are far more simple and complex at the same time.

The idea is that some characters in a gene stand for a whole load of others, perhaps even more of itself, this means that when 'C' unpacks to 'aCa' if you unpack it again you get 'aaCaa'. If you were to unpack this genome 5 times, you'd end up with 'aaaaaCaaaaa' when the plant was only born with the Genome 'C'. This means that a small mutation in a seeds genome can lead to a radically different unpacked genome, therefore a radically different plant.

As real plants use a similar mechanism as they grow, I hope that this will lead to more interesting plant shapes evolving.

Try it yourself: Plants.jar

View Image View Image View Image

Key features of this build are:

  • Recursive genes which 'unpack' themselves into a longer set of instructions.
  • Modified gene editor which allows you to edit the new genes.

~ May 2013 ~

The shapes that plants evolve into still appear limited, though they simply take a long time to evolve. Branching forms require a long genome, the standard genome length is 0 (grow up once). This means that it takes time for longer genomes to evolve, and once they have, time for branching to appear.

The gene editor is finished, so you can now create a genome and see what it would grow into at the same time

Try it yourself: Plants.jar

View Image View Image View Image

Key features of this build are:

  • Gene Editor implemented.
  • Markers to indicate plant size boundaries.

~ April 2013 ~

Work on v2.0 is progressing, the gene editor is being implemented and the ability to save and load genes and simulation settings has been implemented.

I've also implemented different size classes of plants, my hope is that it will encourage a larger variety of forms, small bushy forms under the canopy and tall stemmed, branching forms making the canopy.

While interesting plant shapes are certainly possible, I've noticed that plants tend towards a tall, single stemmed shape. This could be caused by a few things but the way the genes work is a likely culprit, it might require too much order to maintain a branched structure, which is easily lost leading to far inferior offspring. In evolution you can be as fit for the environment as you like, but if most of your children are unfit, your genes are likely to die out.

Try it yourself: Plants.jar

View Image View Image

Key features of this build are:

  • A new Save/Load feature for plant genes.
  • A new Save/Load feature for simulation settings.
  • Plants can fall into one of three categories; large, medium or small. Plants from different categories do not compete for space when germinating.
  • The simulation width can be set between 800 and 5000, simulations wider than 800 have a scrollbar so the whole simulation can be observed and interacted with..

~ March 2013 ~

After some tinkering with different ways to calculate lighting and also experimenting with set plant shape being set exactly by the genetics, I have built a prototype for Evolving Plants 2.0.

So far it is very basic but it looks promising and leads to some interesting shapes emerging, which are definitely plant like.

Try it yourself: Plants.jar

View Image

Key features of this build are:

  • Lighting is done using a buffer which stores shadow information, much more efficient than colliding hundreds of photons every step.
  • Genes construct a plant's shape by directing a robot which can crawl up and down existing stems and grow new ones from its current position.
  • Simulation width can be much bigger than 800 pixels allowing for a larger gene pool to develope and hopefully therefore more variation.

~ November 2012 ~

The efficiency of the program has been increased dramatically however I'm still not entirely pleased with the result, I'm thinking about starting from scratch. If I do I'd like to experiment with exact genetics, i.e. the genes that a plant inherit denote exactly what shape it will grow into.

Try it yourself: Plants.jar

View Image View Image View Image

Key features of this build are:

  • Speed of the simulation can be increased by pressing the '+' key and slowed using the '-' key.
  • The interface has been tidied and more options have been added.
  • The idea of graphs, used to display how closely plants are related in the other version, have been borrowed and applied to other traits.
  • Graphs of genetic traits now appear above plants, when they are being altered, to show how the gene compares in the rest of the population.
  • All plants sharing a grandparent with the selected plant can be re-coloured to clearly show relationships between different groups.

~ June 2012 ~

I have copied the program and tweaked it slightly so that plants reproduce sexually, i.e. they exchange genetic information and their offspring is based on both parents. Plants won't breed with each other unless they are vaguely related allowing for speciation to occur.

Try it yourself: Plants.jar

View Image

Key features of this build are:

  • Plants reproduce sexually (if possible), with other members of their own species.
  • A plants species is kept track of using a string of digits, a member of the same species is counted as an individual whose species digits only have a small number of differences.

~ April 2012 ~

This project is my first published program, it models the growth and reproduction of plants. Each plant has a set of genes which dictate how it will grow and it passes these onto its offspring, with a chance for mutations to occur. It is a genetic algorithm where the fitness function isn't a direct calculation, instead the fitness of a plant can be considered to be the number of descendants it has, much like real life.

The genes don't absolutely describe the shape that the plant will grow into, they're just a set of rules that the plant follows as it grows, namely how long to grow stems and how many branches to grow at each level of the plant.

The plants compete for light, which falls from the sky as photons, and for space, a seed cannot germinate if it is too close to another plant.

The runnable version and the image are slightly different versions.

Try it yourself: Plants.jar

View Image

Key features of this build are:

  • Simulation split into two halves in which parameters can be individually modified.
  • Plants grow and reproduce, competing for light and space.
  • Plants can be selected, their genes can be modified, they can be removed and seeds can be planted.