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