#include < iostream.h >
#include < math.h >
#include < winbgim.h >
#include < stdlib.h >
#define X_RADIUS 50
#define Y_RADIUS 100
#define IRIS_RADIUS 8
#define PIXEL 400
#define X1_EYE PIXEL/3
#define Y1_EYE PIXEL/2
#define X2_EYE (PIXEL*2)/3
#define Y2_EYE PIXEL/2
#define IRISCOLOR 3
//Prototypes
void draw_iris(int center_x, int center_y, int iriscolor); //draws one iris
void draw_irises(); // draws both irises
void draw_eyes(); // draws white of eyes, ellipses
void distance(); // check for in and out
//Functions
double distance(int x, int y) //Calculate distance from center of eye
{
return sqrt(x*x + y*y);
}
void draw_eyes() ///Draws the white part of eyes.
{
setfillstyle(SOLID_FILL, WHITE);
fillellipse(X1_EYE, Y1_EYE, X_RADIUS, Y_RADIUS);
fillellipse(X2_EYE, Y2_EYE, X_RADIUS, Y_RADIUS);
}
void draw_iris(int center_x, int center_y, int iriscolor)
{
double a, b; //radii of inner ellipse
double m_x, m_y; // slope, change in y and x.
double x, y; // coordinates for iris center
double m;
a = X_RADIUS-IRIS_RADIUS;
b = Y_RADIUS-IRIS_RADIUS;
m_x = mousex() - center_x;
m_y = mousey() - center_y;
if (m_x != 0.0)
{
m = m_y/ m_x;
x = (sqrt((1.0/((1.0/(a*a)+(m*m/(b*b))))))); //slope line
}
if (m_x < 0.0) //left side of ellipse
{
x = -x;
y = m*x;
}
else if (m_x > 0.0) //right ride of ellipse
{
y = m*x;
}
else
{
x = 0.0; //check for when x=0 and stuff. Undefined slope
if (m_y > 0.0) //upper ellipse
y = b;
if (m_y < 0.0) //lower ellipse
y =-b;
}
if (distance(x,y) > distance((int)m_x, (int)m_y)) //keeping iris in white area
{
x = m_x;
y = m_y;
}
x = x + center_x; //final coordinates
y = y + center_y;
setfillstyle(SOLID_FILL, iriscolor);
fillellipse((int)x, (int)y, IRIS_RADIUS, IRIS_RADIUS);
}
/*
void draw_irises()
{
draw_iris(X1_EYE, Y1_EYE);
draw_iris(X2_EYE, Y2_EYE);
}
*/
int main()
{
int lcolor = GREEN;
int rcolor = GREEN;
int page = 1;
initwindow(400, 400);
while (!kbhit()) //check for mouse clicks and change in iris colors
{
setactivepage(page);
if(ismouseclick(WM_RBUTTONDOWN))
{
rcolor++;
if (rcolor == 15)
rcolor = 0; //check for white color
clearmouseclick(WM_RBUTTONDOWN);
}
if(ismouseclick(WM_LBUTTONDOWN))
{
lcolor++;
if (lcolor == 15)
lcolor = 0;
clearmouseclick(WM_LBUTTONDOWN);
}
// check for mouse clicks
// change in iris colors
cleardevice(); // clear screen
draw_eyes();
//redraw the eyes
draw_iris(X1_EYE, Y1_EYE, lcolor); //Left
draw_iris(X2_EYE, Y2_EYE, rcolor); //Right
setvisualpage (page);
page = page%2 +1;
}
getch(); //process the key pressed
closegraph();
return EXIT_SUCCESS;
}
It draws a pair of eyes and irises that move to "look" at where your mouse cursor is and when you click left and right buttons on your mouse, the respective irises change color. I so despise programming~ My friends made me a bag dinner last night^^ Twas nice o' them since I didn't have time to eat. Who's Line was gonna come on soon okay! XD;;
I despise programming.
There is also snow outside...and people are having snowball fights. I'm sick -> Stay inside -> Doesn't mean this still ain't kewl XD
I wanna go drink myself to sleep~~ pity I don't drink >.>; Where's my man boy when I need him? I feel icky. You are my sunshine, my only sunshine. You make me happy when skies are gray. Now don't you know that I'll always love you? So don't take my sunshine away...
Hideous non-drawing hole ¬¬
I'm never going to finish this Halloween pic ><;; *At least it looks alright so far^^;* I blame prior to exams and week-week before studying o.o Didn't even do a card~
At least I enjoy coloring it...well I did until I looked at J.Axer's Freya pic, then I just felt like junk @.o;
And~! I lum Zackzack =D He sent me both Card Captor Sakura movies, the OMG movie, along with a whole buncha AMVs, a Slayers NEXT ep. and a uh...Matsui was one of the words...death gods or something ep^^