Wednesday, September 30, 2009

Noface



Been playing around with some more maths. This app plots attractors of the Logistic Equation (with a bit of symmetry thrown in for good measure). The maths is straight forward and explained in the excellent book Symmetry in Chaos: A Search for Pattern in Mathematics, Art and Nature by Michael Field and Martin. Keys a-z have preset values for drawing images from the book. I think you'll need a fairly powerful PC to run the app.


b e n
  

Wednesday, September 2, 2009

Oh no, not another Julia Set generator!!!

Been busy studying... but it's been great following everybody else's blogs! Anyway, at last... got to the last unit of M337 - The Mandelbrot Set. This Processing app draws the Julia set associated with points in the Mandelbrot set. It was great to see for myself that the maths in the unit actually does work!

b e n


A

Friday, June 12, 2009

Eclipse



Updated now... looks more like an eclipse!

b e n



//
// Eclipse v1.1.
//

int kWidth = 480 ;
int kHeight = 480 ; // 320 ;

int kMoonRadius = kHeight / 3 ;
int kSpeed = 8 ;

//
// Dimensions of texture.
// For fast PCs reduce or remove the denominator.
//
int kTextureWidth = kWidth ;
int kTextureHeight = kHeight ;

//
// Define a history buffer.
//
PImage history = createImage( kTextureWidth, kTextureHeight, RGB ) ;


void setup()
{
size( kWidth, kHeight ) ;
colorMode( RGB, 1.0 ) ;

smooth() ;
}

void draw()
{
float t = frameCount * 0.01 ;

//
// Draw the radiation.
//
// background( 0.0 ) ;


image( history, -kSpeed*0.5, -kSpeed*0.5, kWidth + kSpeed, kHeight + kSpeed ) ;

noStroke() ;
fill( 0.0, 0.02 ) ;
rect( 0, 0, kWidth, kHeight ) ;


//
// Draw the seed for the radiation.
//.
// This is just an outlined circle and the roughness in the circle
// seeds the structure in the radiation.
//
// Colour and radius varied to add a bit of variation to the radiation.
//
// Also add some random spots to create flares in the radiation.
//
pushMatrix() ;

translate( kWidth/2, kHeight/2 ) ;

stroke( noise( t ) ) ;
noFill() ;

float radius = kMoonRadius * ( 0.9 + 0.1 * sin( t ) ) ;
ellipse( 0.0, 0.0, radius, radius ) ;

noStroke() ;
fill( 1.0 ) ;

//
// Sources for flares.
//
for ( int i = 0 ; i < 8 ; ++ i )
ellipse( ( 0.5 - noise(t, 0, i ) ) * kMoonRadius * 0.8, ( 0.5 - noise( t, 1, i ) ) * kMoonRadius * 0.8, 4, 4 ) ;

//
// Source for spikes.
//
stroke( 1.0 ) ;
noFill() ;
for ( int i = 0 ; i < 2 ; ++ i )
ellipse( kMoonRadius * 0.3 * sin( 2.0 * PI * i / 2 ), kMoonRadius * 0.3 * cos( 2.0 * PI * i / 2 ), 8, 8 ) ;


//
// Draw a comet.
//
float r = 150 * cos( t * 0.1 ) ;
noStroke() ;
fill( 0.9, 1.0, 0.9 ) ;

ellipse( r*sin(t), r*cos(t), 2, 2 ) ;

popMatrix() ;

//
// Use the current frame as the texture for the
// radiation in the next frame.
//
history.copy( get(), 0, 0, kWidth, kHeight, 0, 0, kTextureWidth, kTextureHeight ) ;

//
// Now draw the Moon.
// The radius is enlarged to cover the outlined circle.
//
pushMatrix() ;

translate( kWidth/2, kHeight/2 ) ;

stroke( 0.0 ) ;
fill( 0.0 ) ;
ellipse( 0.0, 0.0, kMoonRadius+1.0, kMoonRadius+1.0 ) ;

popMatrix() ;
}

Thursday, May 28, 2009

Attack Ships on Fire Off the Shoulder of Orion



Or should it be black ink drops in muddy water!

ß e n



/**
* asofotsoo v1.0
*/

//
// Dimensions of screen.
//
int kWidth = 640 ; //480 ;
int kHeight = 480 ; // 480 ; // 320 ;

//
// Dimensions of texture.
// For fast PCs reduce or remove the denominator.
//
int kTextureWidth = kWidth ;
int kTextureHeight = kHeight ;

//
// Define a history buffer.
//
PImage history = createImage( kTextureWidth, kTextureHeight, RGB ) ;


void setup()
{
size( kWidth, kHeight, JAVA2D ) ;

colorMode( RGB, 1.0 ) ;

// smooth() ;
}

void draw()
{
//
// Animation based on the frame count this time!
//
float t = frameCount * 0.01 ;

pushMatrix() ;

translate( width/2, height/2 ) ;
rotate( t * 0.006* sin(t*5) ) ;
scale( 1.04 ) ;

image( history, -width/2, -height/2, kWidth, kHeight ) ;
popMatrix() ;

//
// Create the nebula effect - use 8 colour patches as seeds.
//
for ( int j = 0 ; j < 8 ; ++ j )
{
pushMatrix() ;

translate( width/2 + width*0.020*sin(t), height/2 + height*0.020*sin(t*1.37) ) ;

rotate( 2.0*PI*j/8.0 ) ;
translate( width * 0.01, 0.0 ) ;


noStroke() ;
fill( noise(t,0,j), noise(t,1,j), noise(t,2,j), 0.1 ) ;

beginShape() ;

for ( int i = 0 ; i < 100 ; ++ i )
{
float x = width * 0.25 * ( 0.5 - 1.0 * noise( t, 1.5 + 0, i * 0.01 ) ) ;
float y = height * 0.25 * ( 0.5 - 1.0 * noise( t, 1.5 + 1, i * 0.01 ) ) ;

vertex( x, y ) ;
}

endShape() ;

popMatrix() ;
}

//
// Attack ships on fire!
//
float range = width * 0.25 * ( 1.4 + sin(t*0.1) ) ;

pushMatrix() ;

translate( width/2, height/2 ) ;

for ( int i = 0 ; i < 10 ; ++ i )
{

fill( 0.0, 0.0, 0.0, 0.55 ) ;

// fill( noise(t,0), noise(t,1), noise(t,2), 0.5 ) ;
float dx = range * ( 0.5 - noise( t, 0, i*0.1 ) ) ;
float dy = range * ( 0.5 - noise( t, 1, i*0.1 ) ) ;

ellipse( dx, dy, 3, 3 ) ;
}

popMatrix() ;

//
// Use the current frame as the texture for the
// mirror in the next frame.
//
history.copy( get(), 0, 0, width, height, 0, 0, kTextureWidth, kTextureHeight ) ;
}

Sojudy



Not one for Martin!

ß e n



/**
* sojudy v1.0
*/

//
// Dimensions of screen.
//
int kWidth = 640 ; //480 ;
int kHeight = 480 ; // 480 ; // 320 ;

//
// Dimensions of texture.
//
int kTextureWidth = kWidth ;
int kTextureHeight = kHeight ;

//
// Define a history buffer of screen textures.
//
PImage history = createImage( kTextureWidth, kTextureHeight, RGB ) ;


void setup()
{
size( kWidth, kHeight, JAVA2D ) ;

colorMode( RGB, 1.0 ) ;
}

void draw()
{
float t = millis() * 0.001 ;

//
// Feedback!
//
pushMatrix() ;

translate( width/2, height/2 ) ;
rotate( t * 0.0003* sin(t) ) ;
scale( 1.04 ) ;

image( history, -width/2, -height/2, kWidth, kHeight ) ;
popMatrix() ;

//
// Colour blast.
//
for ( int j = 0 ; j < 8 ; ++ j )
{
pushMatrix() ;

if ( true )
{
translate( width/2 + width*0.020*sin(t), height/2 + height*0.020*sin(t*1.37) ) ;

rotate( 2.0*PI*j/8.0 ) ;
translate( width * 0.05, 0.0 ) ;
}
else
{
float dx = width* 0.25 * ( 0.5 - noise(t,0, j ) ) ;
float dy = height* 0.25 * ( 0.5 - noise(t,0, j ) ) ;

translate( width/2 + dx, height/2 + dy ) ;
}

// translate( width/2 + width*0.20*sin(t), height/2 + height*0.20*sin(t*1.37) ) ;

noStroke() ;
fill( noise(t,0,j), noise(t,1,j), noise(t,2,j), 0.1 ) ;

beginShape() ;

for ( int i = 0 ; i < 100 ; ++ i )
{
float x = width * 0.25 * ( 0.5 - 1.0 * noise( t, 1.5 + 0, i * 0.1 ) ) ;
float y = height * 0.25 * ( 0.5 - 1.0 * noise( t, 1.5 + 1, i * 0.1 ) ) ;

vertex( x, y ) ;

}

endShape() ;

popMatrix() ;
}

//
// Black smoke.
//
if ( true )
{
pushMatrix() ;

translate( width/2, height/2 ) ;
for ( int j = 0 ; j < 5 ; ++ j )
{
fill( 0, 0, 0, 0.1 ) ;

beginShape() ;

for ( int i = 0 ; i < 100 ; ++ i )
{
float x = width * 0.15 * ( 0.5 - 1.0 * noise( t, 1.5 + 0, j*100 + i * 0.1 ) ) ;
float y = height * 0.15 * ( 0.5 - 1.0 * noise( t, 1.5 + 1, j*100 + i * 0.1 ) ) ;

vertex( x, y ) ;
}

endShape() ;
}
popMatrix() ;
}

//
// Use the current frame as a texture.
//
history.copy( get(), 0, 0, width, height, 0, 0, kTextureWidth, kTextureHeight ) ;

}

Tuesday, May 26, 2009

Jim v1.1



I've animated the colours and properties of the flower and added a history buffer to the recursion. The result is that there is more depth to the sketch. If you want to run the sketch then you will have to allocate more memory to Processing (from the preferences). I've allocated 256MBytes. The other option is to reduce the size of the display window or history buffer, but I think the sketch works best with a deep history buffer.

ß e n


//
// Jim v1.1.
//
import processing.opengl.*;

//
// Dimensions of screen.
//
int kWidth = 640 ; //480 ;
int kHeight = 480 ; // 480 ; // 320 ;

//
// Dimensions of texture.
// For fast PCs reduce or remove the denominator.
//
int kTextureWidth = kWidth / 2 ;
int kTextureHeight = kHeight / 2 ;

//
// Defining properties of the flower.
//
float kInnerRadius = 200 ;
int kInnerCircles = 20 ;
int kRings = 8 ;
int kPetals = 4 ;

//
// Define a history buffer of screen textures.
//
int kHistoryLength = 100 ;
PImage[] history ;

void setup()
{
size( kWidth, kHeight, JAVA2D ) ;

colorMode( RGB, 1.0 ) ;
smooth() ;

//
// CReate the history buffer.
//
history = new PImage[ kHistoryLength ] ;

for ( int i = 0 ; i < kHistoryLength ; ++ i )
history[ i ] = createImage( kTextureWidth, kTextureHeight, RGB ) ;
}

void draw()
{
float t = millis() * 0.0001 ;

//
// Draw the texture to the 4 quadrants with
// reflections in horizontal and vertical reflection transforms.
//
pushMatrix() ;

int index = frameCount % kHistoryLength ;

image( history[ index ], 0, 0, kWidth /2, kHeight / 2 ) ;

scale( -1.0, 1.0 ) ;
image( history[ index ], - kWidth, 0, kWidth /2, kHeight / 2 ) ;

scale( - 1.0, -1.0 ) ;
image( history[ index ], 0, - kHeight, kWidth /2, kHeight / 2 ) ;

scale( -1.0, 1.0 ) ;
image( history[ index ], - kWidth, - kHeight, kWidth /2, kHeight / 2 ) ;

popMatrix() ;

//
// Fade the background a bit.
//
fill( 0, 0, 0, 0.45 ) ;
rect( 0, 0, kWidth, kHeight ) ;

//
// Draw a flower like object.
//
// color innerColour = color( noise( t*2.3, 0.1 ), noise( t*0.7, 0.2 ), noise( t, 0.3 ), 1.0 ) ;
// color outerColour = color( noise( t * 0.7, 0.3 ), noise( t*0.7, 1.5 ), noise( t * 1.3, 2.0 ), 0.5 + 0.5*noise(t) ) ;

color centralInnerColour = smoothColour( 0.05, 0.03, 0.09, 1.0 ) ;
color centralOuterColour = smoothColour( 0.05, 0.03, 0.09, 0.3 ) ;
color innerColour = smoothColour( 0.03, 0.05, 0.07, 1.0 ) ;
color outerColour = smoothColour( 0.3, 0.5, 0.7, 0.8 ) ;

translate( kWidth/2, kHeight/2 ) ;

//
// Draw the centre part.
//
noStroke() ;

for ( int i = kInnerCircles ; i >= 1 ; i -- )
{
fill( blendColour( centralInnerColour, centralOuterColour, i * 0.1 ) ) ;
ellipse( 0, 0, i * kInnerRadius / kInnerCircles, i * kInnerRadius / kInnerCircles ) ;
}

rotate( t * 3.0 ) ;

for ( int j = kRings - 1 ; j >=0 ; j -- )
{

stroke( 0.2 ) ;

fill( blendColour( innerColour, outerColour, float( j )/ kRings ) ) ;

int petals = ( j + 1 ) * kPetals ;

for ( int i = 0 ; i < petals ; ++ i )
{
if ( i % 4 != 0 )
{
pushMatrix() ;

float length = (10.0 + 5.0* noise( t*10.0, i * 0.01 ) ) * j ;
float width = length * noise( t*10.0, i + j ) * 0.75 ;

rotate( 2.0 * PI * i / petals + j * noise(t,j,i) ) ;
ellipse( 15.0 * j, 0, length, width ) ; // 10.0 - ( 10.0 - 30.0 ) * ( j / 8.0 ) ) ;
popMatrix() ;
}
}
}

//
// Use the current frame as the texture for the
// mirror in the next frame.
//
history[ frameCount % kHistoryLength ].copy( get(), 0, 0, width, height, 0, 0, kTextureWidth, kTextureHeight ) ;
}


color smoothColour( float s1, float s2, float s3, float a )
{
float t= millis() * 0.001 ;

float r = 0.5f + 0.5f * sin( t * s1 ) ;
float g = 0.5f + 0.5f * sin( t * s2 ) ;
float b = 0.5f + 0.5f * sin( t * s3 ) ;

return color( r, g, b, a ) ;
}


color blendColour( color c1, color c2, float p )
{
float r = red( c1 ) - ( red( c1 ) - red( c2 ) ) * p ;
float g = green( c1 ) - ( green( c1 ) - green( c2 ) ) * p ;
float b = blue( c1 ) - ( blue( c1 ) - blue( c2 ) ) * p ;
float a = alpha( c1 ) - ( alpha( c1 ) - alpha( c2 ) ) * p ;

return color( r, g, b, a ) ;
}

Jim



More experiments with image recursion. This one plots the central flower and the then uses the window as a background texture for the four quadrants - with reflections. The texture is drawn slightly faded which increases each time the background feeds back into itself.

ß e n


//
// Jim v1.0.
//
import processing.opengl.*;

//
// Dimensions of screen.
//
int kWidth = 640 ; //480 ;
int kHeight = 480 ; // 320 ;

//
// Dimensions of texture.
// For fast PCs reduce or remove the denominator.
//
int kTextureWidth = kWidth / 2 ;
int kTextureHeight = kHeight / 2 ;

//
// Used to store the current frame buffer as a texture.
//
PImage history ;

void setup()
{
size( kWidth, kHeight, JAVA2D ) ;

colorMode( RGB, 1.0 ) ;
smooth() ;

history = createImage( kTextureWidth, kTextureHeight, RGB ) ;
}

void draw()
{
float t = millis() * 0.0001 ;

pushMatrix() ;

//
// Draw the texture to the 4 quadrants with
// reflections in horizontal and vertical reflection transforms.
//
image( history, 0, 0, kWidth /2, kHeight / 2 ) ;

scale( -1.0, 1.0 ) ;
image( history, - kWidth, 0, kWidth /2, kHeight / 2 ) ;

scale( - 1.0, -1.0 ) ;
image( history, 0, - kHeight, kWidth /2, kHeight / 2 ) ;

scale( -1.0, 1.0 ) ;
image( history, - kWidth, - kHeight, kWidth /2, kHeight / 2 ) ;

popMatrix() ;

//
// Fade the background a bit.
//
fill( 1, 1, 1, 0.25 ) ;
rect( 0, 0, kWidth, kHeight ) ;

//
// Draw a flower like object.
//
translate( kWidth/2, kHeight/2 ) ;

fill( noise(t,0), noise(t,1), noise(t,2) ) ;
ellipse( 0, 0, 100, 100 ) ;

rotate( t * 3.0 ) ;

for ( int j = 3 ; j >=0 ; j -- )
{
fill( noise(t*0.3,0,j), noise(t*0.3,1,j), noise(t*0.3,2,j) ) ;
int petals = ( j + 1 ) * 8 ;

for ( int i = 0 ; i < petals ; ++ i )
{
pushMatrix() ;

rotate( 2.0 * PI * i / petals ) ;
ellipse( 30.0 * j, 0, 30.0*j, 10 * j ) ;
popMatrix() ;
}
}

//
// Use the current frame as the texture for the
// mirror in the next frame.
//
history.copy( get(), 0, 0, width, height, 0, 0, kTextureWidth, kTextureHeight ) ;
}