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.

Project Ideas

I’m really interested in working with (and possibly on) P5.js, a new port of Processing to Javascript. Here are some ideas I have for P5.js projects.

A persistent simulation, visualized with P5.js
I’d like to continue working on my “eat/mate/die” sketch, expanding on three or four aspects of the project.

1) Add more simulated behaviors:

  • Eating
  • Mating
  • Passing on traits and evolution
  • Familial bonding
  • Death, mourning
  • Farming, resources
  • Building
  • Property relations
  • Conflict, police

2) Use the behaviors to tell stories in text. I’m already logging important life events for each creature, so I would just need to expand on this feature.

3) Create a persistent world by sticking all the code on a Node.js or Meteor server, and then write a client app in P5.js. The server and the client could share code since they’d both be written in Javascript. Ideally the server would run the script indefinitely, continually evolving the world.

4) If possible I’d also like to add the ability for users to interact with the world, likely by manipulating the environment to either help or hinder its inhabitants. Individual users would wield powers over the world in a kind of pantheistic sense – each in charge and able to manipulate a different a aspect of simulated life.

A library of important (to me) texts, illustrated with animated gifs.
I started this off already with this sketch of the Communist Manifest. I’d like to continue the project, by 1) porting my code to P5.js so that it can live online and 2) gif-ifying other texts, but with a different look and feel for each one. Possible texts by: Kafka, Spinoza, Foucault, Artaud etc.

Port The Nature of Code to P5.js
It would be great to port over all the examples from Nature of Code to P5.js.

Communist Manifesto illustrated with animated gifs

Here’s a little program that:

    1. splits up a text into individual words
    2. searches for an animated gif for each word
    3. displays the original text alongside the animated gifs

I’m using the giphy api to source the images, and the Communist Manifest as the text.

I broke the work up into two scripts: one that breaks apart the text, finds the images and then creates a csv file of the words associated with image urls. The second program reads the csv file and displays the images/text. I wanted to use animated gifs rather than static images. To get this working in processing used the gifAnimation library. The only problem with this library is that the images load one at a time, which blocks the sketch from running smoothly – so I implemented some threading to make the library load the gifs asynchronously.

My code is here on github: https://github.com/antiboredom/gif-to-text

UPDATE: html version here.

Memento Mori – mostly finished

Here’s some video documentation of my Memento Mori project. Pushing a button opens a box which then provides a highly specific fortune.

I’m using a standard servo screwed to the bottom right side of the box to open the lid (I had to upgrade from a micro servo which wasn’t powerful enough). Once the box opens a fortune prints out using a thermal printer.

My initial goal was to have hundreds if not thousands of fortunes, stored on an SD card. Unfortunately I had some difficulty in getting the card reader working with Arduino, so I resorted to using the flash memory of the microcontroller itself – a technique I learned here.

My other challenge was hooking up enough power to the system. I wanted to power everything with batteries, but was having trouble providing enough current for the thermal printer to output anything. I tried connecting some 9V batteries in parallel but it didn’t quite do the trick and also made the batteries dangerously hot. This is definitely an amateur issue… I ended up powering the printer with an adapter and the arduino with a 9V.

I sourced the fortunes from New York Times obituaries. I wrote a little script using NodeBox’s Linguistics library that alters texts by switching sentences from third to second person, and changes tense from past to future. I edited the results to produce the fortunes:

fortunes

The arduino code for the project is here on github: https://github.com/antiboredom/memento-mori-box