import java.awt.*; import java.awt.image.*; import java.awt.geom.*; import javax.swing.*; import java.util.Random; public class Rossler extends JComponent implements Runnable { double initialX, initialY, initialZ; int imageWidth, imageHeight; double delta = 0.001; //double delta = 0.5/3.0; double hDispF = Math.sqrt(3)/2.0; double vDispF = 1.0/2.0; double xLowerLeft, yLowerLeft, xUpperRight, yUpperRight; double pixelWidth, pixelHeight, invPixelWidth, invPixelHeight; double[] pt2D = new double[2]; double[] pt3D = new double[3]; double[] qt2D = new double[2]; double[] qt3D = new double[3]; //double sigma = 10.0; double B = 8.0/3.0; double R = 28.0; double aR = 0.2; double bR = 0.2; double cR = 8.0; double cR1 = 8.0; int counter = 0; Random randNumGen = new Random(5); BufferedImage bufImage; Graphics2D bufImageGraphic; public Rossler(int w, int h, double xLL, double yLL, double xUR, double yUR) { initialX = 2.403; initialY = 4.892; initialZ = 4.673; pt3D[0] = 2.403; pt3D[1] = 4.892; pt3D[2] = 4.673; qt3D[0] = 2.403; qt3D[1] = 4.892; qt3D[2] = 4.673; 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); 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); bufImageGraphic.setPaint(Color.blue); bufImageGraphic.setStroke(new BasicStroke((float)(1*pixelHeight))); AffineTransform at = new AffineTransform(invPixelWidth, 0, 0, -invPixelHeight, -invPixelWidth*xLL, invPixelHeight*yUR ); bufImageGraphic.setTransform(at); Thread t = new Thread(this); t.start( ); } public void timeStep( ) { //counter++; double[] u3D = new double[3]; double[] v3D = new double[3]; u3D = DRossler(pt3D,cR); double[] u2D = new double[2]; double[] v2D = new double[2]; u2D = isom(u3D); pt2D = isom(pt3D); //System.out.println(u2D[0] + " " + u2D[1]); Line2D.Double L = new Line2D.Double(pt2D[0], pt2D[1], u2D[0], u2D[1]); bufImageGraphic.fill(L); pt3D[0] = u3D[0]; pt3D[1] = u3D[1]; pt3D[2] = u3D[2]; //cR += 0.000001; if (counter > 200000) { v3D = DRossler(qt3D,cR1); v2D = isom(v3D); qt2D = isom(qt3D); L = new Line2D.Double(qt2D[0], qt2D[1], v2D[0], v2D[1]); bufImageGraphic.setPaint(Color.white); bufImageGraphic.fill(L); qt3D[0] = v3D[0]; qt3D[1] = v3D[1]; qt3D[2] = v3D[2]; // cR1 += 0.000001; bufImageGraphic.setPaint(Color.blue); } } public void run( ) { try { //while (true) //for(int i = 0; i < 1000000; ++i) for(counter = 0; counter < 10000000; ++counter) { //Loopbody: if (counter % 10000 == 0) System.out.println(cR); timeStep( ); repaint( ); Thread.sleep(0); } } catch (InterruptedException ie) {} } double[] DRossler(double[] s, double c) { double u[] = new double[3]; u[0] = -delta*(s[1]+s[2]) + s[0]; u[1] = delta*(s[0] + aR*s[1]) + s[1]; u[2] = delta*(bR + s[0]*s[2] - c*s[2]) + s[2]; return u; } double[] isom(double[] s) { double q[] = new double[2]; // q in R^2 q[0] = s[0] + hDispF*s[1]; // s in R^3 q[1] = s[2] + vDispF*s[1]; return q; } 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("Rossler"); frame.setBackground(Color.white); Rossler plot = new Rossler(800, 800, -15, -7, 30, 38); //Plotter plot = new Plotter(700, 700, -2, -1.5, 1, 1.5); //Plotter plot = new Plotter(700, 700, 0, 0, 700, 700); frame.getContentPane( ).add(plot); frame.setSize(800, 800); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }