import java.awt.*; public class Ogen extends java.applet.Applet{ //blx holds previous x-value of of left eye, etc... double blx,bly,brx,bry; //new values of eyes double lx=150, ly=150, rx=260, ry=150; public boolean mouseMove(Event evt,int x,int y) { //move to corner of window and calc schale double k = schaallengte(x-150,y-150); lx = k * (double)(x-150) + 150; ly = k * (double)(y-150) + 150; //move to corner of window and calc scale k = schaallengte(x-260,y-150); rx = k * (double)(x-260) + 260; ry = k * (double)(y-150) + 150; repaint(); // call to update return true; } //get the scale factor to make sure the eyeballs remains in the eye //itself, by the concept of Inversive geometry, see: //http://en.wikipedia.org/wiki/Inversive_geometry public double schaallengte(int x,int y) { return (double)(38) / Math.sqrt((double)(x*x+y*y+1444)); } public void paint(Graphics g) { //out black circle of eyes (solid) g.setColor(Color.black); g.fillOval(100,100,100,100); g.fillOval(210,100,100,100); //put white circle in there to make the circle non-solid g.setColor(Color.white); g.fillOval(104,104,92,92); g.fillOval(214,104,92,92); //draw eyes, calling update might be more handy g.setColor(Color.black); g.fillOval((int)(blx=lx-8),(int)(bly=ly-8),16,16); g.fillOval((int)(brx=rx-8),(int)(bry=ry-8),16,16); } public void update(Graphics g) { // delete old eyes by painting them white again g.setColor(Color.white); g.fillOval((int)blx,(int)bly,16,16); g.fillOval((int)brx,(int)bry,16,16); // set new eyes, the minus 8 will make it a good center, else it // will pass the border and whipe the eyeball g.setColor(Color.black); g.fillOval((int)(blx=lx-8),(int)(bly=ly-8),16,16); g.fillOval((int)(brx=rx-8),(int)(bry=ry-8),16,16); } }