import java.awt.*; import java.awt.image.*; import java.awt.geom.*; import javax.swing.*; import java.util.Random; public class Eigen extends JComponent implements Runnable { int imageWidth, imageHeight; double xLowerLeft, yLowerLeft, xUpperRight, yUpperRight; double pixelWidth, pixelHeight, invPixelWidth, invPixelHeight; double TwoPi = 2*Math.PI; double[][] linImage = new double[2000][2]; Random randNumGen = new Random(5); BufferedImage bufImage; Graphics2D bufImageGraphic; public Eigen(int w, int h, double xLL, double yLL, double xUR, double yUR) { imageWidth = w; imageHeight = h; xLowerLeft = xLL; yLowerLeft = yLL; xUpperRight = xUR; yUpperRight = yUR; pixelWidth = (xUR - xLL)/((double)w); invPixelWidth = ((double)w)/(xUR - xLL); pixelHeight = (yUR - yLL)/((double)h); invPixelHeight = ((double)h)/(yUR - yLL); //System.out.println(imageWidth + " " + imageHeight); //System.out.println(pixelWidth + " " + pixelHeight); for (int i = 0; i < 2000; ++i) { linImage[i][0] = Math.cos((i/2000.0)*TwoPi); linImage[i][1] = Math.sin((i/2000.0)*TwoPi); } bufImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); bufImageGraphic = bufImage.createGraphics( ); bufImageGraphic.setPaint(Color.white); //bufImageGraphic.setPaint(Color.black); bufImageGraphic.fillRect(0, 0, w, h); AffineTransform at = new AffineTransform(invPixelWidth, 0, 0, -invPixelHeight, -invPixelWidth*xLL, invPixelHeight*yUR ); bufImageGraphic.setTransform(at); Thread t = new Thread(this); t.start( ); } public void Transform( ) { int k = 0; double Max = 0; for (int i = 0; i < 2000; ++i) { double temp = linImage[i][0]; linImage[i][0] = linImage[i][1]; linImage[i][1] = temp + linImage[i][1]; } for (int i = 0; i < 2000; ++i) { double normSq = linImage[i][0]*linImage[i][0] + linImage[i][1]*linImage[i][1]; if (Max < normSq) { Max = normSq; k = i; } } Max = Math.sqrt(Max); for (int i = 0; i < 2000; ++i) { linImage[i][0] = linImage[i][0]/Max; linImage[i][1] = linImage[i][1]/Max; } System.out.println(linImage[k][0] + " " + linImage[k][1]); System.out.println(Max); } public void timeStep(int i) { Rectangle2D p = new Rectangle2D.Double(linImage[i][0], linImage[i][1], pixelWidth/1.0, pixelHeight/1.0); Color col = new Color((float)(i/2000.0), 0, (float)(1 - (i/2000.0))); bufImageGraphic.setPaint(col); bufImageGraphic.fill(p); } public void run( ) { Transform( ); try { for (int i = 0; i < 2000; ++i) { //Loopbody: timeStep(i); repaint( ); Thread.sleep(0); } } catch (InterruptedException ie) {} } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); //g2.setPaint(Color.blue); //g2.drawImage(image, imageX, imageY, this); g2.drawImage(bufImage, 0, 0, this); } public static void main(String[] args) { JFrame frame = new JFrame("Eigen"); frame.setBackground(Color.white); Eigen plot = new Eigen(700, 700, -1.2, -1.2, 1.2, 1.2); frame.getContentPane( ).add(plot); frame.setSize(700, 700); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }