Archive for the 'Processing' Category

Virtual Ribbons

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to FurlAdd to Newsvine

This artwork allows the user to experience an augmented reality in which the flow of ribbons and particles can be controlled. It works by capturing a colour from an object (in this case, a green glove and the light from my mobile phone) and then using this object to drag the ribbons around the screen.

I won’t be releasing the full source code for this but I have released the source of the two key elements used in this sketch. These are the colour detection and the 2D Ribbons. In my opinion this is the best way to share code for larger projects. Smaller context specific code snippets are far easier to look through and experiment with than entire projects. And if people want to build the final artwork, stitching together the various pieces and adding their own code is a great learning experience.

2D Ribbons

2D Ribbons

I’ve been toying around with Eric Natzke’s Ribbon code and have managed to port it over to Processing in 2D form. Although the result and code are both very different to that of Natzke, it retains the original technique for building the ribbons. You can play with it and download the source here.

More ribbons can be added by changing the ribbonAmount variable. The colours are chosen from an image, in this case, “rothko_01.jpg”. This must be kept in the same folder as the pde files or there will be an error.

Colour detection in Processing

This is part of a Processing project I’m currently working on. This sketch allows the user to select colours from webcam input. The input is then analysed and a rectangle is drawn around all pixels close to the chosen colour. Up to 2 colours can be used for this sketch. This is similar to the getColorBoundsRect() method in the BitmapData class in Flash.

Click here to see the video on Vimeo

You can download the source code below:

colour_detection.pde, CoordsCalc.pde

Be aware though that in order to use it you should be in a well lit room with a good quality webcam. You might also need to fine tune your webcam settings. To select a colour, place your object in the red box in the bottom right hand corner of the frame and press 1 or 2.


p to view the rectangles
1 to select the first colour
2 to select the second colour
0 to reset colours

Motion Trails v01

This is the first experiment in a webcam study I am doing using Processing. Movement results in circles of colour taken from the webcam footage. More movement results in fewer, larger circles and vice versa.

Click here to see the video on Vimeo

Click here to download the source code

In order to use this code you need to install WinVDIG 1.01. This can be obtained from Dan Shiffman’s site. I would recommend a good quality webcam in a well lit room (I’m using the Logitech Quickcam Pro 5000). Also a powerful machine is required for the best results.

The FrameDifferencing code by Golan Levin was used as a basis for this sketch. This can be found in the Processing examples.

Prisoner’s Dilemma Visualisation

I recently read Richard Dawkins’ The Selfish Gene and was fascinated with his discussion of Prisoners Dilemma (PD), a classic example of game theory, in relation to evolution. On the lookout for inspiration for my first Processing project, I decided to use this idea to create a visualisation of the game in progress.

First a brief explanation. PD involves two players and a banker. Each player has the choice to either cooperate or defect and are awarded points for the various outcomes of the game. If they both cooperate they each get 3 points, if they both defect, they each get 1 point and if one cooperates and the other defects, the defector gets 5 points and the cooperator gets no points. Iterated PD is where this game is played a number of times. The winner is the player with the most points after the last game has been played. For more detailed information click here.

Within my Processing sketch, there are 8 different “animals”. Each uses a classic PD strategy. They are as follows:

Green = Tit-For-Tat – Always begin by cooperating then copy the last move of the opposition.
Blue = Tit-For-Two-Tats – Like Tit-For-Tat but the opponent must defect twice before the player retaliates.
Red = Always Defect.
Yellow = Random. Each play has a 50% probability.
Purple = Always Cooperate.
Turquoise = Grudger – The player cooperates every move until the opponent defects once. The Grudger defects every move after this.
Orange = Naive Prober – Tit-For-Tat but with random defection.
Grey = Adaptive – Starts with c,c,c,c,c,c,d,d,d,d,d and then makes each choice by calculating the best average scores for defection and cooperation.

Each time two animals come into contact with each other, they have 40 games of Iterated PD. The scores of these games are gathered and once an animal scores over 250 points, it reproduces. Each animal is given a limited lifespan at birth which depends upon the amount of animals. As the amount goes up, the given lifespans decrease. This “disease” avoids overcrowding by limiting the population to 600-800.

Click here to see the full size video on Vimeo


This visualisation differs from the original experiments in that the games are not played in an organised structure but through random interactions. However, the results are quite similar to reports from the original scenario. The more negative strategies, “Always defect”, “Random Prober” and “Random” are always the first to go. These are usually followed by “Always cooperate” and “Adaptive”. The last three “Tit-For-Tat”, “Tit-For-Two-Tats” and “Grudger” (who always cooperate with each other regardless) tend to hold the top 3 positions in a random order.


Flickr Photos