Visualising Networks

Had a bit of fun playing with the protovis library today and came up with this. The data came from analysing a text file and mapping each word to the word that preceded it. The words then become the nodes and the black line represents the relationship between the nodes. Turned out gathering the data was the time consuming bit compared to getting to grips with the library!

Mancala Part 2

I’ve uploaded a working version of my mancala game . Got a lot of the functionality I wanted, although Im not to happy about with the timing of events. Ive tested it in firefox and chrome and all seemed fine but if you notice anything mental let me know! My next step is going to be trying to get this working on the iPhone and clean up some of the code…

Mancala Part 1

I’m building the classic game Mancala at the moment, using HTML5, CSS3, Javascript and a (little) bit of jQuery. I made a simple Java version a couple of years ago when I was learning how to make GUI’s with Swing but never got round finishing it off. So when I found the old files I thought this would make for a nice project to show off some of the new things I’ve been learning since graduating and a chance to improve my old code.

Here’s a rough overview of how it will (hopefully) end up.

Vext

Yet another PHP Markov chain text generator! This is my first project using PHP and the first time Id sat down to learn more about it and how it works. Its a pretty straight forward application that reads through a bunch of text files in the application folder reading in each word to a markov chain. Once all text files have been analysed the markov chain then generates words based on the transitions of the words its seen.

To make it a bit more interesting for me to build and so that I can eventually stick it up as a small standalone website (once Ive sorted out my server) the markov chain can work at any order, the outputted text starts at the beginning of a sentence and ends at the end of a sentence and generates a title!


#The Markov Chain Object
class Markov {

var $order;
var $probs;
var $input;
var $outpt;

function __construct($order) {
$this->order = $order;
$this->probs = array();
$this->input = array();
$this->outpt = array();
}

function analysis($state) {
array_push($this->input, $state);
if(count($this->input) > $this->order) {
$this->update();
array_shift($this->input);
}
}

function generate() {
if( empty($this->outpt) or
isset($this->probs[join('|',$this->outpt)])==false) {
$this->outpt = explode('|',array_rand($this->probs));
}
$state = $this->random_element($this->probs[join('|',$this->outpt)]);
array_push($this->outpt,$state);
if (count($this->outpt) > $this->order) { array_shift($this->outpt); }
return $state;
}

private function update() {
$state = end($this->input);
$key = join('|',array_slice($this->input,0,count($this->input)-1));
if(isset($this->probs[$key])) { array_push($this->probs[$key],$state); }
else { $this->probs[$key] = array($state); }
}

function random_element($list){ return $list[array_rand($list,1)]; }

function probs(){ print_r($this->probs); }
}

Scanline Synthesis

This is a live clip from a Max/MSP/Jitter patch I made in 2010.

The patch uses a scan line from a video to fill a buffer which is then played back by a granular synthesiser. The sound is used to create a NURBS object in OpenGL and then textured with the original video.

The patch works by taking a row of pixels from each frame of a video, the scanline, the row of pixels is a four-plane char matrix with dimensions of 320 x 1. For the matrix to be useful as a waveform it will need to be converted from four dimensions to one dimension.

This is done using the jit.rgb2luma object which converts ARGB matrices to monochrome using the equation:

L = (0.299*R) + (0.587*G) + (0.114*B)

The values are then converted from char (0 – 255) to float32 (0.0 – 1.0).

Before the matrix is poked into a buffer the matrix is copied, inverted (-1.0 – 0.0) and concatenated with the original matrix using the jit.concat object. This new matrix, now 640 x 1, is then poked into a buffer using jit.buffer~.

This is done so that when the waveform is played back there will be silence for a solid black frame and a square wave for a solid white frame.

The buffer is played back using overlapped pulse grain generators as shown in this pure data patch here.

The NURBS object is created using the Catch Nurbs patch described in the jitter recipes book 2 with the sound generated from the overlapping pulse grain generators.

“Our audio is converted to 1-D matrices by the jit.catch~ object and then downsampled and passed along to a matrix using “dstdim” messages (see TimeScrubber). The resulting matrix is then downsampled further, sliced into 3 columns and packed into a 3-plane named matrix.

From there, we use jit.slide to smooth the movement, and jit.op to scale the values to the desired range. This is then given to the jit.gl.nurbs object as a “ctlmatrix”.”

To create a more interesting shape the NURBS object is textured with the orginal scanline that was used to create the waveform (before it was converted to monochrome).

Particle System

I have been experimenting with particle systems recently and have made an example of a 50000 particle system running in real-time using Processing and OpenGL. My next step is to get this system to react to sound…

Statconcat

Statconcat was completed as my undergraduate disertation for Creative Computing at Goldsmiths, University of London. It looked at the use of a markov chain as part of a unit selection algorithm for concatenative synthesis. As a project, I’m not 100% with the outcomes, but really enjoyed doing it and it gave me a greater understanding of Digital Signal Processing. The project is made up of a Pure Data patch with some Java external objects, I’ve attached all the relevant files. Here’s a litte taster:

This is the first statistical Concatenative Synthesis system implemented and documented in Pure Data using the Pure Data for Java external. Pure Data is a free, graphical, and cross platform programming environment, giving open accessibility to this work.

Concatenative Synthesis is a method of synthesising sound through the use of a database of sounds split into small fragments (units). This system allows users to retrieve units of sounds, which are concatenated – joined together – to create new sounds. The statistical approach to sound synthesis was through the use of a Markov Chain as part of a unit selection algorithm.

A working prototype Pure Data patch has been created capable of producing interesting and intriguing sounds that can be saved to the users computer or played back in Pure Data.

Significant improvements can still be made as this area of research as it is at its infancy. The system contains a bug and is slow at concatenation. It has limited functionality however it demonstrates that combining Concatenative Synthesis , K-means clustering and Markov Chains is achievable.

This area of research has exciting possibilities for musicians, producers and researchers into sound manipulation.

Statconcat.zip

Copter 3D

This game was created as part of a university module in Advanced Graphics & Animation where we had to create an interactive 3D scene using OpenGL. I decided to use Processing to carry out the project and picked my all time favourite game to base the project on.

The Processing sketch is made up by four different components the valley, the helicopter, the obstacles and the score.

The valley is generated by using a height map. At the start of the sketch a large matrix is created by ….. . At each frame in the sketch the next stage in this height map is drawn using each cell in the matrix as a vertex. This gives the effect of flying through the valley.

void heightMap2normals()
{
for(int i=0; i < polys-1; i++)
{
for(int j=terrain_offset; j < terrain_offset+polys-1; j++)
{
PVector a = new PVector(i*spacing,theBigMap[i][j],j*spacing);
PVector b = new PVector(i*spacing,theBigMap[i][j+1],(j+1)*spacing);
PVector c = new PVector((i+1)*spacing,theBigMap[i+1][j+1],(j+1)*spacing);
normals[i] [j-terrain_offset] = calculateANormal(b,a,c);
}
}
}

PVector calculateANormal(PVector a, PVector b, PVector c)
{
PVector v1 = new PVector();
PVector v2 = new PVector();
PVector n = new PVector();
v1 = v1.sub(b,a);
v2 = v2.sub(c,a);
n = v1.cross(v2);
n.normalize();
return n;
}

The Helecopter is an *.obj object taken from http://www.turbosquid.com then loaded into Processing using Saito’s OBJ Loader. The intercactivity comes into play as the user is able to move the helicopter left and right (the obj object is translated by a certain amount left and a certain amount right). Placed in the middle of the sketch and used as the focal point in a third person perspective gives the impression that the user is controlling the helicopter as it flys through the valley.

The obstacles are drawn into the sketch as rectangular blocks and appear from the far end and translated towards the helicopter.

Nebat

Nebat is an interactive composition patch created in Pure Data. It aims to explore computer improvisation and algorithmic composition. The idea was to create a composition system that would allow the user to record a basic idea into the system and have that idea expanded upon by the computer in a style that would make sense to what was recorded into it.

Requirements

You will need to download pd-extended 0.41.4, PDJ (java external for pure data) and to bear in mind I have only tested this on a mac. Somethings may not work on other computers.

Download

nebat-1.0

Compression

As part of a module in Data Compression I had to write a program that would compress a text file that contained a matrix of integers ranging between -256 to 256.

I wrote a program that randomly generated an input matrix, which is then written to a text file. The text file is read back into the program, compressed by various compression algorithms which I implemented, then written back to a text file.

When compressed text files are created they are then analysed and a compression ratio is calculated as well as average code length and entropy.

I got the best results from the Shannon-Fanu algorithm, which built prefix codes of the integers from the input matrix.

Input Matrix
[[-185, -185, -118, -94, -23]
[ 53, 17, -185, 225, -23]
[ 53, -173, -110, -152, -23]
[ 6, 95, -173, -76, -23]
[ -23, 6, 212, -185, -23]]
Entropy: 3.4634655
File Size: 101.0

Prefix Code
[[ 010, 010, 11101, 11001, 00]
[ 011, 10100, 010, 1111, 00]
[ 011, 1001, 11000, 1011, 00]
[ 1000, 11100, 1001, 10101, 00]
[ 00, 1000, 1101, 010, 00]]
Average Code Length: 3.52
Entropy: 3.4634655
File Size: 59.0
Ratio: 0.5841584

Follow

Get every new post delivered to your Inbox.