beginner seeking for processing eye
in
Programming Questions
•
1 year ago
please help!
im trying to code two responsive eyes - eyes follow mouse. But in a simple way.
My code is below. And only thing missing in it is that eyes dont follow mouse while it is in between them.
I also tried loops.. But not too much success whit it. Eyes are skipping. That code is also below.
Thank you!!!
int r1=100;
void setup ()
{
background (255);
size (800,400);
smooth();
}
void draw ()
{
int x = int (map(mouseX,0,width,-r1/8,r1/8));
int y = int (map(mouseY,0,height,-r1/8,r1/8));
int cx=width/2;
int cy=height/2;
eyeBall (cx-100, cy,cx-100+x, cy+y);
eyeBall (cx+100, cy,cx+100+x, cy+y);
}
void eyeBall (int x, int y, int xI, int yI)
{
fill(255);
ellipse (x, y, r1,r1);
fill(#CE5588);
ellipse (xI, yI, r1/2,r1/2);
fill(0);
ellipse (xI, yI, r1/20,r1/20);
}
int r1=100;
void setup ()
{
background (255);
size (800,400);
smooth();
}
void draw ()
{
int x = int (map(mouseX,0,width,-r1/6,r1/6));
int y = int (map(mouseY,0,height,-r1/6,r1/6));
int cx=width/2;
int cy=height/2;
if (mouseX>cx-r1 && mouseX<0)
{
eyeBall (cx-100, cy,cx-100-x-r1/6, cy+y);
eyeBall (cx+100, cy,cx+100+x+r1/6, cy+y);
};
if (mouseX>0 && mouseX<cx+r1)
{
eyeBall (cx-100, cy,cx-100+x+r1/6, cy+y);
eyeBall (cx+100, cy,cx+100-x-r1/6, cy+y);
};
if (mouseX<cx-r1 || mouseX>cx+r1)
{
eyeBall (cx-100, cy,cx-100+x, cy+y);
eyeBall (cx+100, cy,cx+100+x, cy+y);
}
}
void eyeBall (int x, int y, int xI, int yI)
{
fill(255);
ellipse (x, y, r1,r1);
fill(#CE5588);
ellipse (xI, yI, r1/2,r1/2);
fill(0);
ellipse (xI, yI, r1/20,r1/20);
}
im trying to code two responsive eyes - eyes follow mouse. But in a simple way.
My code is below. And only thing missing in it is that eyes dont follow mouse while it is in between them.
I also tried loops.. But not too much success whit it. Eyes are skipping. That code is also below.
Thank you!!!
int r1=100;
void setup ()
{
background (255);
size (800,400);
smooth();
}
void draw ()
{
int x = int (map(mouseX,0,width,-r1/8,r1/8));
int y = int (map(mouseY,0,height,-r1/8,r1/8));
int cx=width/2;
int cy=height/2;
eyeBall (cx-100, cy,cx-100+x, cy+y);
eyeBall (cx+100, cy,cx+100+x, cy+y);
}
void eyeBall (int x, int y, int xI, int yI)
{
fill(255);
ellipse (x, y, r1,r1);
fill(#CE5588);
ellipse (xI, yI, r1/2,r1/2);
fill(0);
ellipse (xI, yI, r1/20,r1/20);
}
int r1=100;
void setup ()
{
background (255);
size (800,400);
smooth();
}
void draw ()
{
int x = int (map(mouseX,0,width,-r1/6,r1/6));
int y = int (map(mouseY,0,height,-r1/6,r1/6));
int cx=width/2;
int cy=height/2;
if (mouseX>cx-r1 && mouseX<0)
{
eyeBall (cx-100, cy,cx-100-x-r1/6, cy+y);
eyeBall (cx+100, cy,cx+100+x+r1/6, cy+y);
};
if (mouseX>0 && mouseX<cx+r1)
{
eyeBall (cx-100, cy,cx-100+x+r1/6, cy+y);
eyeBall (cx+100, cy,cx+100-x-r1/6, cy+y);
};
if (mouseX<cx-r1 || mouseX>cx+r1)
{
eyeBall (cx-100, cy,cx-100+x, cy+y);
eyeBall (cx+100, cy,cx+100+x, cy+y);
}
}
void eyeBall (int x, int y, int xI, int yI)
{
fill(255);
ellipse (x, y, r1,r1);
fill(#CE5588);
ellipse (xI, yI, r1/2,r1/2);
fill(0);
ellipse (xI, yI, r1/20,r1/20);
}
1