Tuesday, May 26, 2009

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 ) ;
}

No comments: