A Simulation of Something

Screen Shot 2013-12-04 at 7.33.02 PM

I’ve updated and elaborated my “eat/mate/die” simulation. In the previous version, creatures would eat food, mate, reproduce, and eventually die of starvation or old age. My new version has a number of new features, including social class, private property, farming, and an online mode that runs indefinitely.

You can see the new version at tinyurl.com/samsim. This version is seeded from code that’s running indefinitely on a node.js server. Multiple users can connect at the same and they should see the same thing.

You can also take a look at an “offline” version here: tinyurl.com/samsim2. The offline version let’s you refresh the page to generate a new simulation.

The code is over on github.

How the world works

  • Each creature is born into a social class, “worker”, “owner” or “enforcer”.
  • Social classes are rigid and strictly enforced. Creatures cannot leave their class, nor can they mate with creatures in different classes.
  • Workers are gray. They farm the land and produce food (the green circles). They plant seeds along a predetermined path, generated by Perlin noise.
  • All the bright green food on the left side of the screen is owned by the owner class. Workers are not allowed to eat this food. The muddier food on the right side of the screen is up for grabs – anyone can eat it.
  • Enforcers are red. They enforce the law by protecting the property rights of owners. They hunt down and kill workers if they catch them eating food that belongs to the owners.
  • Owners are green. They hang around, mating, eating and producing art (art-making is not implemented yet).
  • When creatures are full they begin a mating dance and reproduce. The different social classes practice different mating dances.
  • The social class of children is inherited from the parents.
  • Each creature has a first name and a last name. The first names are chosen at random from a list of the most popular American baby names from 1880. The system generates last names by appending syllables of parents’ first names.
  • Most important events are logged and displayed on the right side of the screen.

Controlling the world

  • Mouse over the creatures to view their names, desires, ages and hunger levels, or cycle through them with the j and k keys.
  • Hit the space bar to zoom in and follow a creature.
  • The i key reveals info for all creatures.
  • Finally, and most importantly, use arrow keys to change the social class of the creature you’re inspecting.

Online and offline

I ported my original Processing code to javascript with p5js to allow the simulation to run in the browser. Then I split the code into a client and server application in node.js. Now the simulation runs indefinitely online with hosting from nodejitsu. When you connect to tinyurl.com/samsim, the client downloads the current state of the simulation from the server, and then receives periodic updates. There are still some issues with syncing – you may notice the simulation “jumps” periodically as it’s re-synced.

Leave a Reply

Your email address will not be published. Required fields are marked *