Posts Tagged ‘Lines’

Mandelbrot Player

Wednesday, November 5th, 2008

The mandelbrot before audio playback commencesI’ve built on my previous Frequency Mandelbrot to add basic audio playback controls to it. It no longer starts automatically upon loading, you now have to press ‘P‘ on your keyboard to begin playback and there are a number of other hot keys for different playback options.

An audio file can be played, paused, rewound, and fast-forwarded. The left and right audio channels as well as beats and the overall volume are taken and used to colour a mandelbrot fractal. The left and right audio channels generate a series of lines that change speed and direction based on the audio peaks. The centre of the fractal has a constraint on it based on the beats, so as the amount of beats increase, it will freeze and stay still while the outer area of the fractal, which appears as a background continues to animate around it. And yes, it is meant to have the lines through it.

The keyboard controls for playback are:

Play: P
Pause: S
Fast-Forward: F
Rewind: R
Restart: H
Stop: Q

Mandelbrot during audio playbackA note on these playback options, at the moment, ‘Q‘ will actually close the link to the song file, so this should not be used unless it is needed. Attempting to start the song again with ‘P‘ after ‘Q‘ has been used will cause Processing to error. I haven’t gotten around this as of yet unfortunately.

To replay a song from the start, press ‘H‘ and this will return the play head to the start of the file.

Rewind ‘R‘ and fast forward ‘F‘ skip the track back and forward by 500 milliseconds, so ‘R‘ should be used in place of ‘H‘ if you don’t want to return to the start of the song.

The source code is a little bit different to previous versions as I have added a class for keyPressed to determine what to do if the control keys are pressed:


// Create the controls.
void keyPressed()
{
if ( key == 'p' ) song.play(); // Press P to play the song.
if ( key == 's' ) song.pause(); // Press S to pause playing.
if ( key == 'h' ) song.rewind(); // Press H to reset to the start.
if ( key == 'f' ) song.skip(500); // Press F to fast forward.
if ( key == 'r' ) song.skip(-500); // Press R to rewind.
if ( key == 'q' ) song.close(); // Press Q to quit playing.
}

It’s all fairly straight forward, the Minim library is very simple to use and there are some great tools in it that you can play with. I highly recommend it if you are working with audio in Processing.

You can have a look at it in action here. The song used in this piece is “Freedom (Waking Mix)” by vo1k1 2008 – Licensed under Creative Commons Attribution Noncommercial (3.0).

This is fairly CPU intensive, so many computers will have trouble running this, it is also about 9mb to load so you probably don’t want to try it on a low speed connection.

The full source code is available from the same page as the applet, or you can see it after the jump:

(more…)

Frequency Mandelbrot

Sunday, September 21st, 2008

Frequency Mandelbrot 1Where I had been experimenting with just the outsides of the mandelbrot before, I’ve started having a look at modifying the inside of the fractal as well. I’ve continued to use the frequency spectrum for the effects simply because it goes with the frequency spectrum used in the background.

import ddf.minim.*;
import ddf.minim.analysis.*;

FFT fft;

AudioPlayer song;
BeatDetect beat;

float fSize;

void setup()
{
size(300, 300);

// always start Minim first!
Minim.start(this);

// specify 512 for the length of the sample buffers
// the default buffer size is 1024
song = Minim.loadFile("freedom.mp3", 512);
song.play();
beat = new BeatDetect();

float fSize = 20;
// an FFT needs to know how
// long the audio buffers it will be analyzing are
// and also needs to know
// the sample rate of the audio it is analyzing is
fft = new FFT(song.bufferSize(), song.sampleRate());
}

void draw()
{
background(0);
// first perform a forward fft on one of song's buffers
// I'm using the mix buffer
//  but you can use any one you like
fft.forward(song.mix);
fill(255);

loadPixels();

// Maximum number of iterations for each point on the complex plane
float maxiterations = 200;
float xmin = -2.5;
float ymin = -2;
float wh = 2;

beat.detect(song.mix);
if ( beat.isOnset() ) fSize += 0.1;

fSize = constrain(fSize, -10, 10);

ymin = -1;
xmin = -1.5;

maxiterations = maxiterations + fSize;

// x goes from xmin to xmax
float xmax = xmin + wh;
// y goes from ymin to ymax
float ymax = ymin + wh;

// Calculate amount we increment x,y for each pixel
float dx = (xmax - xmin) / (width);
float dy = (ymax - ymin) / (height);

// Start y
float y = ymin;
for(int j = 0; j < height; j++) {
// Start x
float x = xmin;
for(int i = 0;  i < width; i++) {

// Now we test, as we iterate z = z^2 + cm does z tend towards infinity?
float a = x;
float b = y;
int n = 0;
while (n < maxiterations) {
float aa = a * a;
float bb = b * b;
float twoab = 2.0 * a * b;
a = aa - bb + x;
b = twoab + y;
// Infinty in our finite world is simple, let's just consider it 16
if(aa + bb > 16.0f) {
break;         }
n++;
}

// We color each pixel based on how long it takes to get to infinity
// If we never got there, let's pick the color black
if (n == maxiterations) pixels[i+j*width] = 0;
else pixels[i+j*width] = color(n*(song.right.get(i)*50) % 255, n*(song.left.get(i)*50) % 200, n*(song.right.get(i)*30));
x += dx;
}
y += dy;
}
updatePixels();
}

void stop()
{
song.close();
super.stop();
}

Frequency Mandelbrot 2In this version I have used the BeatDetect class and another variable, fSize with a constraint on it and then added to the maximum iterations. This allows the frequency spectrum to spread through the mandelbrot fractal, or appear to anyway. It is actually just using the frequency spectrum to colour the fractal, and this makes it appear like spectrum is forming the fractal.

You can have a look at it in action here. The song used in this piece is “Freedom (Waking Mix)” by vo1k1 2008 – Licensed under Creative Commons Attribution Noncommercial (3.0).

This is fairly CPU intensive, so many computers will have trouble running this, it is also about 13mb to load so you probably don’t want to try it on a low speed connection.

Using The Output of Minim in Processing

Wednesday, September 17th, 2008

After following the quick start guide on the Minim website, I put together a little waveform generator that produces a waveform for the left and right channels based on the input of an audio file along with a frequency spectrum running over the top of it. The instructions are pretty easy to follow, and the additional functionality of Minim seems fairly simply to harness to do something useful with.

Minim Output 4I’ve since taken the code from that guide and combined it with a mandelbrot fractal from the Processing tutorials and references. At the moment, the mandelbrot doesn’t really do anything near like what I want it to do, but I am making some progress in figuring out what I can do with Minim and how I can use it for what I want to do.

Initially I took the frequency spectrum and used it to colour parts of the mandelbrot. To start with I only manipulated the red colouring of the fractal to see what would happen which gave me this (you may need to scroll to the right in some places sorry):

import ddf.minim.*;
import ddf.minim.analysis.*;

AudioPlayer song;
FFT fft;

float xmin = -2.5;
float ymin = -2;
float wh = 4;

void setup()
{
size(300, 300);

// always start Minim first!
Minim.start(this);

// specify 512 for the length of the sample buffers
// the default buffer size is 1024
song = Minim.loadFile("song.mp3", 512);
song.play();

// an FFT needs to know how
// long the audio buffers it will be analyzing are
// and also needs to know
// the sample rate of the audio it is analyzing is
fft = new FFT(song.bufferSize(), song.sampleRate());
}

void draw()
{
background(0);
// first perform a forward fft on one of song's buffers
// I'm using the mix buffer
//  but you can use any one you like
fft.forward(song.mix);

loadPixels();

// Maximum number of iterations for each point on the complex plane
int maxiterations = 200;

// x goes from xmin to xmax
float xmax = xmin + wh;
// y goes from ymin to ymax
float ymax = ymin + wh;

// Calculate amount we increment x,y for each pixel
float dx = (xmax - xmin) / (width);
float dy = (ymax - ymin) / (height);

// Start y
float y = ymin;
for(int j = 0; j < height; j++) {
// Start x
float x = xmin;
for(int i = 0;  i < width; i++) {

// Now we test, as we iterate z = z^2 + cm does z tend towards infinity?
float a = x;
float b = y;
int n = 0;
while (n < maxiterations) {
float aa = a * a;
float bb = b * b;
float twoab = 2.0 * a * b;
a = aa - bb + x;
b = twoab + y;
// Infinty in our finite world is simple, let's just consider it 16
if(aa + bb > 16.0f) {
break;  // Bail
}
n++;
}

// We color each pixel based on how long it takes to get to infinity
// If we never got there, let's pick the color black
if (n == maxiterations) pixels[i+j*width] = 0;
else pixels[i+j*width] =
color(n*(song.right.get(i)*50) % 255, n*16 % 200, n*16 % 100);
x += dx;
}
y += dy;
}
updatePixels();
}

void stop()
{
song.close();
super.stop();
}

To make the above work, you’ll need to put an MP3 or Wav audio file in a “data” directory within the sketch folder for this sketch and change song.mp3 to the name of your audio file. You can see it in action here. The song used in this piece is “Freedom (Waking Mix)” by vo1k1 2008 – Licensed under Creative Commons Attribution Noncommercial (3.0).

Minim Output 5aIt will run a series of lines of various lengths and thicknesses at varying speeds based on the input of the audio file.

Considering how cool this was looking, I decided to add the left audio channel for the green colouring to see what would happened, so I modified the colouring to the following:

if (n == maxiterations) pixels[i+j*width] = 0;
else pixels[i+j*width] = color(n*(song.right.get(i)*50) % 255, n*(song.left.get(i)*50) % 200, n*16 % 100);

Minim Output 5cThis is actually really cool, if you run an audio track through it that has a distinctively different left and right channel you get much more variation in the colouring and it appears to be synced more with the music.

If you try the above, you’ll get reds coming through for the right channel, greens coming through for the left and yellows where they overlap. Since you have two different sets of lines, you can see them change with each channel, rather than only with one channel, this is why it seems to be synced up better, and the colour changes help with this since the colours match the left and right mix. You can see it in action here. The song used in this piece is “Freedom (Waking Mix)” by vo1k1 2008 – Licensed under Creative Commons Attribution Noncommercial (3.0).

Adding the second colouring control in also makes colour variations immediately around the main parts of the mandelbrot more prominent, and as they change it makes the fractal appear to be behaving like it is encircled with flames.

Minim Output 7aThis does make the background blue though rather than grey which I don’t like too much since the fractal doesn’t stand out as much with the blue background as it did grey.

I decided to change the colouring again slightly, this time using the audio mix to control the blue colouring. I used the right audio channel again, no particular reason really. So this is what my colouring looks like now:

if (n == maxiterations) pixels[i+j*width] = 0;
else pixels[i+j*width] = color(n*(song.right.get(i)*50) % 255, n*(song.left.get(i)*50) % 200, n*(song.right.get(i)*30));

Minim Output 7e
Minim Output 7c

You can see it in action here. The song used in this piece is “Freedom (Waking Mix)” by vo1k1 2008 – Licensed under Creative Commons Attribution Noncommercial (3.0).

This has the same left and right channel variation and effects as the previous version, but it changes the colours slightly, the lines are now variations or predominately green and purple with a black background. This makes the mandelbrot stand out much more than before, but it also makes the appearance of flames around the fractal much more prominent as they are now blue closest to the fractal and shades of purple the further out you go. This looks really cool and makes the flames even more realistic (except for the colouring of course) and the flames now appear to reach out further making them stand and their variations stand out more.

Walking Lines 3 – Processing

Thursday, August 21st, 2008

Walking Lines 3, joining lines.I received some feedback on my earlier versions of the walking lines in the form of a trackback from Alex.

The feedback was part of a practice peer review, but he went into some detail on how i could fix up my current code so that the lines follow on from each other and how to reduce the load on the CPU per cycle with the same effect. The advice is greatly appreciated.

View the new version online here.

The changes and source code are after the jump.

(more…)

Fractals and Influences

Tuesday, August 12th, 2008

Fractals have always particularly appealed to me. They seem chaotic and yet orderly. I actually focussed on this concept in year 12 for my major art work which was selected to be featured in 5 galleries across NSW.

One of my fractals

If you look at my Deviant Art account at all, you’ll notice that it is absolutely full of fractal stills. I also had some big A1 and A2 fractal prints on exhibition, as well as an animation, at a recent inter-university festival between QUT and UQ. So I can easily say that fractals are definitely where my love in art is at. Since I first began experimenting with fractals, there has been one particularly big influence in my work, and that has been the work of Scott Draves aka Spot.

Spot’s work has been of interest to me basically since I began working with fractals and it continues to do so.

He has done a lot of work in fractals and started the Flam3, Electric Sheep and Dreams in High Fidelity projects, all of which are quite influential on my work, both in fractals and in other computational arts.

Not all of his work has been focused on fractals, but many of his idea’s share similarities with them. One example of this are his Dub Visuals which take chaotic still images and morph them, to form other still images in a flow similar to that of the evolution of his fractal animations.

I have previously done fractal animations where they are synced with music, both music performed by another artist and music that I have composed myself. However, this hasn’t been done in real time and has been a long process to setup each portion of the animation and sync it up with the music. Ultimately, I would love to develop a way of rendering fractals, even low quality or low resolution fractals in real-time based on audio input. Basically this would be combining the work I have done previously with the basic concepts of what I did for KKB210 where I did a series of lines and boxes that responded to audio input. The lines one was probably getting close, though ultimately no where near as detailed as I would like it to be, and definitely nowhere near as chaotic and fractal-like as I want.

That is my aim though and hopefully I will get to it sooner or later.