Here's a slightly modified version of the previous code that draws using an ellipse instead of a rectangle. The resulting animation reminds me of the way eels in a bucket slip and slide around each other... not that I have or ever have had a bucket of eels before mind - I'm not that type of person!
b e n
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 = 40 ;
final color k_background_colour = color( 100, 200, 128, 255 ) ;
final color k_edge_colour = color( 200, 200, 200, 255 ) ;
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 ) ;
ellipse( 0, 0, k_width, k_height ) ;
popMatrix() ;
}
}