After the Swing based commets from your last article Jeff, I thought I'd have a go at a Swing version of this one...
I have added the code as well, to use AffineTransform to paint a 1/2 size "corner" image into the four corners, rather than draw the polygon four times. This is probably complete overkill, and the original "paint" routine is probably more understandable...
Still...Hope it proves interesting for someone 
Code:
// A Swing version of the kaleidoscope tutorial from JavaWorld
//
// http://www.javaworld.com/javaworld/jw-09-2005/jw-0919-funandgames.html
//
// This only draws one quater of the screen, then flips that image about to draw the other
// three quarters.
//
// The image is first drawn inside the KalSwing class, then, the KalPanel class paints this image
// to the screen.
import java.awt.* ;
import java.awt.geom.* ;
import java.awt.image.* ;
import javax.swing.* ;
public class KalSwing extends JApplet implements Runnable
{
class KalPanel extends JPanel
{
public void paintComponent( Graphics g )
{
Graphics2D g2 = (Graphics2D)g ;
// Draw the top left hand corner normally, as you would
g2.drawImage( imBuffer, 0, 0, this ) ;
// This is the bottom left hand corner.
// Flip it upside down
AffineTransform tx = AffineTransform.getScaleInstance( 1, -1 ) ;
// Then move it back into its original position
tx.translate( 0, -imBuffer.getHeight() ) ;
AffineTransformOp op = new AffineTransformOp( tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR ) ;
// And draw it in the bottom left hand corner
g2.drawImage( imBuffer, op, 0, halfHeight ) ;
// This is the top right hand corner.
// Flip it horizontally
tx = AffineTransform.getScaleInstance( -1, 1 ) ;
// Then move it back into its original position
tx.translate( -imBuffer.getWidth(), 0 ) ;
op = new AffineTransformOp( tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR ) ;
// And draw it in the top right hand corner
g2.drawImage( imBuffer, op, halfWidth, 0 ) ;
// This is the bottom right hand corner.
// Flip it horizontally and vertically (same as a 180deg rotation)
tx = AffineTransform.getScaleInstance( -1, -1 ) ;
// Then move it back into its original position
tx.translate( -imBuffer.getWidth(), -imBuffer.getHeight() ) ;
op = new AffineTransformOp( tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR ) ;
// And draw it in the bottom right hand corner
g2.drawImage( imBuffer, op, halfWidth, halfHeight ) ;
}
}
// Maximum iterations before background is cleared.
final static int MAXITER = 200 ;
// Maximum number of points that comprise polygon.
final static int MAXPOINTS = 6 ;
// Animation thread.
Thread runner ;
// Current number of iterations counter.
int counter ;
// Half the width of the applet drawing area.
int halfWidth ;
// Half the height of applet drawing area.
int halfHeight ;
// Image buffer.
BufferedImage imBuffer ;
// The panel contained by this applet which will do all the painting
KalPanel kalPanel ;
// Array of polygon points x-coordinates.
int[] xpoints = new int[ MAXPOINTS ] ;
// Array of polygon points y-coordinates.
int[] ypoints = new int[ MAXPOINTS ] ;
// Initialize the applet. Invoked by Web browser.
public void init()
{
// Acquire the applet's width and height.
halfWidth = getSize().width >> 1 ;
halfHeight = getSize().height >> 1 ;
// Create an image buffer.
imBuffer = new BufferedImage( halfWidth, halfHeight, BufferedImage.TYPE_INT_RGB ) ;
// Create a new KalPanel object, this will paint our kaleidoscope
kalPanel = new KalPanel() ;
// Add the panel to our jApplet...
this.getContentPane().setLayout( new BorderLayout() ) ;
this.getContentPane().add( kalPanel, BorderLayout.CENTER ) ;
}
// Start the applet. Invoked by Web browser.
public void start()
{
// If no thread exists, create a Thread object that associates with the
// current Kal object, and start a new thread that invokes the current
// Kal object's run() method. Before doing that, clear the counter so
// we don't draw only a few polygons before clearing the applet's
// drawing area.
if( runner == null )
{
counter = 0 ;
runner = new Thread( this ) ;
runner.start() ;
}
}
// Paint the image onto the 1/4 sized BufferedImage
public void paintPattern()
{
Graphics imG = imBuffer.getGraphics() ;
// Clear image buffer before it gets too crowded.
if( ++counter == MAXITER )
{
imG.setColor( Color.black ) ;
imG.fillRect( 0, 0, halfWidth, halfHeight ) ;
counter = 0 ;
}
// Generate a random color and establish that color as the image buffer
// Graphics context's drawing color.
Color c = new Color( rnd( 256 ), rnd( 256 ), rnd( 256 ) ) ;
imG.setColor( c ) ;
// Obtain number of points that compose the polygon: 1 through MAXPOINTS.
int npoints = rnd( MAXPOINTS ) + 1 ;
// Obtain coordinates for each point composing the polygon.
for( int i = 0 ; i < npoints ; i++ )
{
xpoints[ i ] = rnd( halfWidth ) ;
ypoints[ i ] = rnd( halfHeight ) ;
}
// Display initial polygon.
imG.fillPolygon( xpoints, ypoints, npoints ) ;
}
// Obtain a random integer.
static int rnd( int limit )
{
// Return a random integer that ranges from 0 through limit-1.
return( int ) ( Math.random() * limit ) ;
}
// Run the animation.
public void run()
{
// Obtain a reference to the thread that was started in the applet's
// start() method.
Thread current = Thread.currentThread() ;
// As long as runner contains the same reference, keep looping. The
// reference in runner becomes null when the applet's stop() method
// executes.
while( current == runner )
{
// Draw the new polygon to our buffered image
paintPattern() ;
// Then paint this image to the four corners of our KalPanel
kalPanel.repaint() ;
// Pause for 50 milliseconds to achieve an eye-pleasing display.
try
{
Thread.sleep( 50 ) ;
}
catch( InterruptedException e )
{
}
}
}
// Stop the applet. Invoked by Web browser.
public void stop()
{
// Tell the drawing thread to terminate.
runner = null ;
}
}
Hope my modifications are ok with you Jeff...
Cheers,
Tim