You are on page 1of 2

import import import import

java.awt.Color; java.awt.Graphics; java.awt.Graphics2D; java.awt.image.BufferedImage;

import javax.swing.JApplet; public class FixedPointIteration extends JApplet implements Runnable{ final static int w = 600; final static int h = 400; static double angle = 0; BufferedImage tempImage; Graphics2D g2d; int x0 = w/2; int y0 = h/2; Thread t; public void init(){ tempImage = new BufferedImage(500,500,BufferedImage.TYPE_INT_ARGB); g2d = tempImage.createGraphics(); t = new Thread(this); setSize(w,h); this.setVisible(true); this.setFocusable(true); t.start(); } public void run(){ while(true){ try{ Thread.sleep(10); angle += Math.toRadians(0.5); angle %= Math.toRadians(360);

repaint(); }catch(Exception e){ } } } public void paint(Graphics g){ g2d.setBackground(Color.WHITE); g2d.clearRect(0,0,w,h); g2d.setColor(Color.BLACK); g2d.drawOval(0, (h/2)-50, 100, 100); int tempx = -(int)(Math.cos(angle-Math.toRadians(180))*50); int tempy = (int)(Math.sin(angle-Math.toRadians(180))*50);

g2d.setColor(Color.RED); g2d.drawLine(50, h/2, 50+tempx, h/2+tempy); g2d.setColor(Color.BLACK); g2d.drawLine(100, h/2, w, h/2); g2d.drawLine(100, h/2-100, 100, h/2+100); double tempx1 = 0; double tempy1 = 0; for(double i=0;i<angle;i+=0.01){ tempx1 = i*(50); tempy1 = -Math.sin(i)*50; g2d.drawLine((int)tempx1+100,(int)tempy1+h/2,(int)tempx1+100,(int)tempy1+h/2) ; } g2d.setColor(Color.BLUE); g2d.drawLine((int)tempx+50,(int)tempy+h/2,(int)tempx1+100,(int)tempy1+h/2); g.drawImage(tempImage,0,0,this); } }

You might also like