import java.awt.*; import java.awt.event.*; import java.lang.Math.*; import java.lang.*; import java.net.*; import java.security.*; public class NewRose extends java.applet.Applet implements Runnable, MouseListener { int i = 0; int c_i = 0; double cycle = 0.0; volatile int changed = 0; volatile int threadStop = 0; volatile int threadSuspend = 0; int old_width = 0; int old_height = 0; volatile double a; Thread myThread = null; Image im; Graphics buf; synchronized void mySuspend() { try { threadSuspend = 1; wait(); } catch (InterruptedException e) { } } synchronized void myResume() { threadSuspend = 0; notify(); } public NewRose() { } public void run() { while( myThread != null && myThread.isAlive() && threadStop != 1 ) { Dimension d = getSize(); if ( d.width != old_width || d.height != old_height ) { im = createImage( getSize().width, getSize().height ); buf = im.getGraphics(); old_width = d.width; old_height = d.height; a = java.lang.Math.min( getSize().width / 2, getSize().height / 2 ); } try { myThread.sleep(1000); } catch (InterruptedException e) { } doIt( buf ); } System.out.println( "Dead Thread does suicide!" ); } public void init() { System.out.println( "init called" ); im = createImage( getSize().width, getSize().height ); buf = im.getGraphics(); a = java.lang.Math.min( getSize().width / 2, getSize().height / 2 ); myThread = new Thread(this); myThread.start(); threadSuspend = 1; addMouseListener( this ); } public void start() { System.out.println( "start called" ); if ( myThread != null ) { myResume(); } } public void stop() { System.out.println( "stop called" ); if ( myThread != null && myThread.isAlive() ) { threadSuspend = 1; } } public void destroy() { if ( myThread != null && myThread.isAlive() ) { threadStop = 1; } System.out.println( "destroy called" ); } public void doIt ( Graphics g ) { //g.setColor( Color.red ); //g.setColor( Color(i)); Graphics screen = getGraphics(); Color bg = getBackground(); g.setColor( bg ); Dimension d = getSize(); //g.clearRect( 0,0, d.width, d.height ); g.fillRect( 0,0, d.width, d.height ); screen.clearRect( 0,0, d.width, d.height ); double r; double th = 0.0; //double a = 100; //cycle += 1.0; cycle = ( java.lang.Math.random() * 100.0 ); int oldx = 0; int oldy = 0; int x,y; int half_width = d.width / 2; int half_height = d.height / 2; //double a = java.lang.Math.min( half_width, half_height ); //double n = ( java.lang.Math.random() * Integer.MAX_VALUE ); double n = ( java.lang.Math.random() * 10.0 ); //double n = java.lang.Math.random(); Color c; while ( th <= ( cycle * java.lang.Math.PI ) ) { if ( myThread != null && !myThread.isAlive() ) { System.out.println( "Dead Thread Running!" ); return; } if ( changed == 1 ) { changed = 0; return; } if ( threadSuspend == 1 ) { System.out.println( "Thread Suspended" ); mySuspend(); } if ( threadStop == 1 ) { return; } c_i = (int) java.lang.Math.rint( java.lang.Math.random() * Integer.MAX_VALUE ); c = new Color( c_i ); g.setColor( c ); screen.setColor( c ); r = a * java.lang.Math.sin( n * th ); //rose function //translate from polar to cart. corrd. x = (int) java.lang.Math.rint( r * java.lang.Math.cos( th ) ); y = (int) java.lang.Math.rint( r * java.lang.Math.sin( th ) ); g.drawLine( half_width+oldx, half_height-oldy, half_width+x, half_height-y ); screen.drawLine( half_width+oldx, half_height-oldy, half_width+x, half_height-y ); oldx = x; oldy = y; th += 1.7453293E-2; //one degree } } public void paint ( Graphics g ) { System.out.println( "paint called" ); g.drawImage( im, 0,0, this ); } public void mouseEntered( MouseEvent e ) { } public void mouseExited( MouseEvent e ) { } public void mousePressed( MouseEvent e ) { System.out.println( "mouseDown called" ); int x = e.getX(); int y = e.getY(); Dimension d = getSize(); int half_width = d.width / 2; int half_height = d.height / 2; int short_end = java.lang.Math.min( half_width, half_height ); int corr_x = x - half_width; int corr_y = half_height - y; a = java.lang.Math.min( java.lang.Math.sqrt( corr_x*corr_x + corr_y*corr_y ), short_end ); changed = 1; } public void mouseReleased( MouseEvent e ) { } public void mouseClicked( MouseEvent e ) { } }