package sierp;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Lorentz extends JFrame{
	
	
	public Lorentz(Dimension d) {
		this.setSize(d);
		this.add(new MyPane(d));this.setBackground(Color.WHITE);
		this.pack();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}

	class MyPane extends JPanel implements Runnable{
		Thread thread=null;
		
		double delta=0.005;
		double ratio=2.7;
		Point2D.Double pt=new Point2D.Double(0,0.5454629),old=new Point2D.Double(0,0);
		
		public MyPane(Dimension d){
			this.setPreferredSize(d);
			this.setBackground(Color.WHITE);
			repaint();
			
			thread = new Thread(this);
			thread.start();
		}
		
		protected void paintComponent(Graphics g){
			Graphics2D g2d = (Graphics2D)g;
			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
			g2d.setColor(Color.RED);
			g2d.fillOval((int)(3*pt.x),300+(int)(600*pt.y),1,1);
			//g2d.fillRect((int)(4*pt.x),(int)(1000*pt.y),4,1);
			//g2d.drawLine((int)(old.x),(int)(1000*old.y),(int)(pt.x),(int)(1000*pt.y));
			//System.out.println("-- ok");
		}
		
		public void run() {
			for(int j=0;j<400;j++){
				try {
					thread.sleep(10);
				} catch (InterruptedException e){
					e.printStackTrace();
				}
				ratio+=delta;
				for(int i=0;i<200;i++){
					pt.y=ratio*pt.y*(1-pt.y);
					//System.out.println(1000*pt.y);
					Graphics g = getGraphics();
					if (g != null) paintComponent(g);
					else repaint();
				}
				pt.x=pt.x+1;
				//System.out.println("------------------------------------");
				//repaint();
			}
		}	
	}
}

