Tuesday, July 26, 2011

mouse tail effect in cplusplus

hello everyone.
today i have a great,interesting and easy thing to do with cursor in c++ using graphics.
seen many animation in flash or JavaScript but today i will do something amazing in c++.
many people think that c++ is boring and is only black and white to see.
but today i will use colors to make effect in c++.
there a screenshot of the program.
before reading this post further i would like to suggest you that you read my post on cursor here
download program + source-code
/*
example of cursor tail in turbo c++ 3.0
written by kuldeep dhaka [kuldeepdhaka9@gmail.com]
*/
#include<dos.h> #include<graphics.h> #include<stdlib.h> #include<stdio.h> #include<conio.h> #include<time.h>
union REGS in,out; /*-------------------------------------------------------*/ struct mouse {int x,y,b;}; void mouse_ini(); int mouse_show(); int mouse_hide(); void mouse_get(mouse *); void mouse_set(int,int); void mouse_restrict(int,int,int,int); /*--------------------------------------------------------*/ //function to be added to main for> mouse when application loads void mouse_ini() { if(!mouse_show()) { printf("error in initializing mouse"); printf("Press any key to halt:"); getch(); exit(1); } else mouse_restrict(0,0,getmaxx(),getmaxy()); } /*--------------------------------------------------------*/ /*to enable cursor or show cursor to user*/ int mouse_show() { in.x.ax=1; return int86(51,&in,&out); } /*--------------------------------------------------------*/ /*to disable cursor or hide cursor to user*/ int mouse_hide() { in.x.ax=2; return int86(51,&in,&out); } /*--------------------------------------------------------*/ /*get current mouse information b for> button x for> x-axis u for> y-axis */ void mouse_get(mouse *mus) { in.x.ax=3; int86(51,&in,&out); mus->b=out.x.bx; /* 0:-button not pressed 1:-left button is pressed 2:-right button is pressed 3:-center button is pressed */ mus->x=out.x.cx; mus->y=out.x.dx; } /*--------------------------------------------------------*/ /*set new position for> the cursor*/ void mouse_set(int x,int y) { in.x.ax=4; in.x.cx=x; in.x.dx=y; int86(51,&in,&out); } /*--------------------------------------------------------*/ /*restrict the mouse pointer between the specific positions*/ void mouse_restrict(int x_left,int y_top,int x_right,int y_bottom) { in.x.ax=7; in.x.cx=x_left; in.x.dx=x_right; int86(51,&in,&out); in.x.ax=8; in.x.cx=y_top; in.x.dx=y_bottom; int86(51,&in,&out); } void main() { /* graphics initalisation*/ int gdriver = DETECT, gmode, errorcode; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "bgi"); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } /*---------*/ setbkcolor(7); mouse mus; mouse_ini(); /*--------------circle effect----------*/ struct { int x,y,c; }tail[5]; int i,rad[]={5,10,15,20,25},max_avail_color=getmaxcolor(); while(!kbhit()) { mouse_get(&mus); cleardevice(); mouse_hide(); setcolor(4); outtextxy(5,5,"move the cursor to see full effect...press any key to exit..."); for>(i=0;i<5;i++) { setcolor(tail[i].c); circle(tail[i].x,tail[i].y,rad[i]); } mouse_show(); for>(i=0;i<4;i++) { tail[i]=tail[i+1]; } tail[4].x=mus.x; tail[4].y=mus.y; tail[4].c=rand()%max_avail_color; delay(50); } }
thats all for now.good bye folks.

Labels: , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home