head 1.1; access; symbols; locks; strict; comment @# @; 1.1 date 97.12.01.03.59.30; author hans; state Exp; branches; next ; desc @animation of chaotic behavior the panel which shows the movement of the pendulum @ 1.1 log @Initial revision @ text @import java.awt.*; import java.util.*; import java.lang.*; // // object to draw the pendulum // class graphic extends Panel { Graphics g; Dimension d; int xo, yo, x0, y0; double tx=0.0; double ty=0.0; Image offscreen; graphic() { setBackground(Color.lightGray); } public void exit() { if (offscreen != null) { offscreen.flush(); } } public void draw(double x, double v) { if (offscreen==null) { d=size(); offscreen=this.createImage(d.width, d.height); } g = offscreen.getGraphics(); d = size(); x0=(int)(d.width/2)+15; y0=(int)(d.height/2); xo=(int) ((d.width/4)*Math.sin(x)); yo=(int) ((d.width/4)*Math.cos(x)); g.setColor(Color.lightGray); g.fillRect(0,0,d.width, d.height); g.setColor(Color.red); g.drawLine (x0,y0,x0+xo,y0+yo); float color=(float) (Math.abs(v)/2); if(color>1.0) color=(float) 1.0; g.setColor(new Color(color,color,(float) 1.0)); g.fillOval(xo+x0-5,yo+y0-5,10,10); g = this.getGraphics(); if(g!=null) { g.drawImage(offscreen, 0, 0, Color.lightGray, this); } } public void drawint(double x , double y) { tx = x; ty = y; } public void paint(Graphics g) { if(offscreen!=null) { g.drawImage(offscreen, 0, 0, Color.lightGray, this); } else { d= size(); offscreen=this.createImage(d.width, d.height); draw(tx, ty); } } } @