Hızlı Konu Açma

Hızlı Konu Açmak için tıklayınız.

Son Mesajlar

Konulardaki Son Mesajlar

Reklam

Forumda Reklam Vermek İçin Bize Ulaşın

Java ile Appletler: Mouse Takip Eden Göz

BlackKey

Üye
Fenerbahçe
Kayıtlı Üye
Katılım
12 Eylül 2014
Mesajlar
167
Tepkime puanı
0
Puanları
0
Bu derste appletlerle mouse takip eden göz uygulaması yapalım.

PHP Kod:

class Eyeball{

double xm,ym,x1,x2,y1,y2,xc,yc,radius;
int x_coord,y_coord;

public
void geteyes(int x,int y,int rad)
{
xc=x;
yc=y;
radius=rad;
}

public
void getmouse(int x,int y)
{
xm=x;
ym=y;
}

double slope(double xm,double ym,double xc,double yc)
{
double sl=(xm-xc)/(ym-yc);
return
sl;
}

double cvalue(double yc,double radius,double slope)
{
double exp1=radius*radius;
double exp2=slope*slope;
double exp3=yc*yc;
double cvalue=exp3-((exp1*exp2)/(exp2+1));
return
cvalue;
}

double bvalue(double yc)
{
double bvalue=-1*2*yc;
return
bvalue;
}

double desc(double b,double c)
{
double exp1=b*b;
double exp2=4*c;
double desc=Math.sqrt(exp1-exp2);
return
desc;
}

double y1(double b,double desc)
{
double y=(b + desc)/2;
return
y;
}

double y2(double b,double desc)
{
double y=(b - desc)/2;
return
y;
}

double x(double y1,double sl,double yc,double xc)
{
double exp1=y1-yc;
double exp2=exp1/sl;
double x=exp2+xc;
return
x;
}

void calculations()
{
double m=slope(xm,ym,xc,yc);
double c=cvalue(yc,radius,m);
double b=bvalue(yc);
double desc=desc(b,c);
y1=y1(-b,desc);
y2=y2(-b,desc);
x1=x(y1,m,yc,xc);
x2=x(y2,m,yc,xc);
}

void co_ordinates()
{
calculations();
if(
xm>xc)
{
x_coord=(int) x1;
y_coord=(int) y1;
}
else
{
x_coord=(int) x2;
y_coord=(int) y2;
}
}

public
int give_eyeballx()
{
co_ordinates();
return
x_coord;
}

public
int give_eyebally()
{
co_ordinates();
return
y_coord;
}
}

public class
MerhabaApplet extends Applet implements MouseMotionListener
{

Eyeball e1=new Eyeball();
Eyeball e2=new Eyeball();

public
void init()
{
setSize(600, 600);
setBackground(Color.yellow);
addMouseMotionListener(this);
}

public
void mouseMoved(MouseEvent e)
{
int xm=e.getY();
int ym=e.getX();

e1.getmouse(xm,ym);
e2.getmouse(xm,ym);
repaint();
}
public
void mouseDragged(MouseEvent e){}
public
void paint(Graphics g)
{

e1.geteyes(330,330,30);
e2.geteyes(260,330,30);
//Göz Çerçeve Çizimi
g.setColor(Color.blue);
g.drawOval(300,300,75,80);
g.drawOval(230,300,75,80);
//Gözlerin Çizimi
g.setColor(Color.blue);
g.fillOval(e1.give_eyeballx(),e1.give_eyebally(),20,20);
g.fillOval(e2.give_eyeballx(),e2.give_eyebally(),20,20);
}
}





 

Users Who Are Viewing This Konu (Users: 0, Guests: 1)

Üst