‹ A Script that Rules the WorldWhitney Balls ›

Eco

2010-11-19 23:15:45 supercollider

clean-up #5:

An ecosystem as described in Gary William Flake's book - "The Computational Beauty of Nature" (page 191). I started coding it 1.5 years ago but never finished it until today.

eco
  • white = empty space
  • green = plant
  • red = herbivore
  • blue = carnivore
  • For every time step:
    • For every empty cell, e:
      • If e has three or more neighbours that are plants, then e will become a plant at the next time step (assuming it isn't trampled by a herbivore or carnivore).
    • For every herbivore, h (in random order):
      • Decrease energy reserves of h by a fixed amount.
      • If h has no more energy, then h dies and becomes an empty space.
      • Else, if there is a plant next to h, then h moves on top of the plant, eats it, and gains the plant's energy.
        • If h has sufficient energy reserves, then it will spawn a baby herbivore on the space that it just exited.
      • Else, h will move into a randomly selected empty space, if one exists, that is next to h's current location.
    • For every carnivore, c (in random order):
      • Decrease energy reserves of c by a fixed amount.
      • If c has no more energy, then c dies and becomes an empty space.
      • Else, if there is a herbivore next to c, then c moves on top of the herbivore, eats it, and gains the herbivore's energy.
        • If c has sufficient energy reserves, then it will spawn a baby carnivore on the space that it just exited.
      • Else, c will move into a randomly selected empty space that is next to c's current location. If there are no empty spaces, then c will move through plants.

The rules are fairly simple but the result is complex. Carnivores feed on herbivores that in turn feed on plants. Populations grow, get overpopulated and die out just like in nature. The SuperCollider code is a bit cryptic using a lot of nested arrays for efficiency reasons but near the top, there are user settings to play with.

Here's also a JavaScript version... /software/p5js/eco/, a version for Processing... /software/processing/eco/ and also a C++ version written in Cinder... /software/cinder/eco/.

Updates:

  • 180101: changed the file format from .rtf to .scd
  • 200727: ported to JavaScript
  • 200801: rebuilt and improved the C++ version for Cinder 0.9.2
Attachments:
eco.scd
eco.app.zip
‹ A Script that Rules the WorldWhitney Balls ›