Cool Visualization

Hey guys,

I ran across this project and really like its functionality. I’m trying to mess with the source code to develop something similar myself but maybe with different shapes and reactions. We will see how it goes. Anyway its a really cool simple idea that I could see growing and developing into something interesting. As it stands now it functions very well and is fun to play with. I keep wanting to combine applets like this with music to create a music visualization that is possible interactive in some way. I will try to embed this applet, hope it works, so you guys can see it. Otherwise just copy the source code into processing and it will run. All credits to the author of the code, Daniel Winkler.

If this embed doesn’t work, just see this link here http://www.openprocessing.org/visuals/?visualID=3148

Source Code:

// 2009 Daniel Winkler http://www.phyloa.com

Particle[] parts = new Particle[300];
PVector O = new PVector();

void setup()
{
size( 800, 600, P3D );
frameRate( 30 );
for( int i = 0; i < parts.length; i++ )
{
parts[i] = new Particle();
}
noStroke();
smooth();
fill( 30, 200, 255 );
}

void draw()
{
O.set( mouseX, mouseY, -500 );
background( 0 );
lights();
for( int i = 0; i < parts.length; i++ )
{
parts[i].update();
}
}

int size = 7;

public class Particle
{
PVector loc = new PVector( random( 0, width ), random( 0, height ), random( -300, -700 ) );
PVector speed = new PVector();

public Particle()
{

}

public void update()
{
if( mousePressed )
{
PVector dir = new PVector( mouseX, mouseY, -500 );
dir.sub( loc );
dir.normalize();
speed.add( dir );
}
else
{
speed.mult( .9 );
}
loc.add( speed );
pushMatrix();
translate( loc.x, loc.y, loc.z );
rotateToFace( loc );

beginShape( QUADS );
vertex( -size, -size, 0 );
vertex( size, -size, 0 );
vertex( size, size, 0 );
vertex( -size, size, 0 );
endShape();
popMatrix();
}
}

// O is your object's position
// P is the position of the object to face
// U is the nominal "up" vector (typically Vector3.Y)
// Note: this does not work when O is straight below or straight above P
PVector U = new PVector( 0, 1, 0 );
void rotateToFace( PVector P )
{
PVector D = new PVector( );
D.set( O );
D.sub( P );
PVector Right = U.cross( D );
Right.normalize();
PVector Backwards = Right.cross( U );
Backwards.normalize();
PVector Up = Backwards.cross( Right );
applyMatrix(Right.x, Right.y, Right.z, 0, Up.x, Up.y, Up.z, 0, Backwards.x, Backwards.y, Backwards.z, 0, 0, 0, 0, 1);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s