Kod: Zaznacz cały
[tex]import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class boil extends Applet
implements MouseMotionListener {
int width, height;
Image moil;
Graphics toil;
int mx, my;
double t = 0;
public void init() {
width = getSize().width;
height = getSize().height;
mx = width / 2;
my = height / 2;
moil = createImage( width, height );
toil = moil.getGraphics();
toil.setColor( Color.black );
toil.fillRect( 0, 0, width, height );
toil.setColor( Color.white );
addMouseMotionListener( this );
}
public void mouseMoved( MouseEvent e ) { }
public void mouseDragged( MouseEvent e ) {
int x = e.getX();
int y = e.getY();
int dx = x - mx;
int dy = y - my;
t += Math.sqrt( (dx*dx + dy*dy)/a ) / b;
if ( t > 2*Math.PI ) {
t -= 2*Math.PI;
}
toil.drawLine( x, y, x+(int)(c*Math.cos(t)), y+(int)(d*Math.sin(t)) );
mx = x;
my = y;
repaint();
e.consume();
}
public void update( Graphics g ) {
g.drawImage( moil, 0, 0, this );
}
public void paint( Graphics g ) {
update( g );
}
}[/tex]