Monday, May 18, 2009

Coral Ring

Small changes can have big effects!




import javax.media.opengl.* ;
import processing.opengl.*;

//
// Inf 1.
//
// Draw a twistig ring shape.
//

final int k_ellipses = 200 ;
final int k_width = 20 ;
final int k_height = 90 ;
final color k_background_colour = color( 200, 200, 128, 255 ) ;
final color k_edge_colour = color( 220 ) ;
final color k_fill_colour = color( 255, 255, 255, 255 ) ;

void setup()
{
// size( 640, 480, JAVA2D ) ; // , P3D ) ;
size( 640, 480, OPENGL ) ;

smooth() ;
}


void draw()
{
//
// Clear the background and set up a drawing style for the ellipses.
//
background( k_background_colour ) ;

stroke( k_edge_colour ) ;
fill( k_fill_colour ) ;

ellipseMode( RADIUS ) ;

//
// Draw a circle using a sequence of ellipses painted on top of each other.
//
for ( int i = 0 ; i < k_ellipses ; ++i )
{

pushMatrix() ;

//
// Fudge the depth of the ellipses so that the last few ellipses are painted
// underneath the starting ellipses.
//
float dz = i > k_ellipses / 4 ? -0.1 : 0.0 ;

PGraphicsOpenGL pgl = (PGraphicsOpenGL) g ;
GL gl = pgl.beginGL() ;

if ( i < k_ellipses / 5 )
gl.glEnable( gl.GL_DEPTH_TEST ) ;
else
if ( i < k_ellipses / 2 )
gl.glDisable( gl.GL_DEPTH_TEST ) ;
else
gl.glEnable( gl.GL_DEPTH_TEST ) ;

pgl.endGL() ;


//
// Draw the ellipse.
// The Processing variable frameCount is used to animate the rotation of the ellipses.
//
float offset = 0 ; // frameCount * 0.01 ; // index = ( i + frameCount ) % k_ellipses ;

translate( width/2 + 150 * sin( PI * 2.0 * i / k_ellipses + offset ), height/2 + 150 * cos( PI * 2.0 * i / k_ellipses + offset ), dz ) ;

rotate( frameCount * 0.01 + i*3 ) ;

ellipse( 0, 0, k_width, k_height ) ;

popMatrix() ;

}
}

3 comments:

jannetta said...

Hi Lazydog

I really enjoy your blog. You've done some nifty stuff here.

Jannetta

lazydog said...

Thanks for the kind comments!

ß e n

Sharon Dawes said...

I love the socks!

Sharon