Paint Brush Program

Previous Page       C Projects Home          Next Page

  • This is a paint brush program.
  • It includes computer graphics.   
  • In this program we can draw using mouse.
  • The coordinates of  mouse are also displayed as we draw with mouse.

#include<dos.h>
#include<graphics.h>

union REGS i,o;

main()
{
int gd=DETECT,gm,maxx,maxy,x,y,button,prevx,prevy;
initgraph(&gd,&gm,"c:\\turboc3");

maxx=getmaxx();
maxy=getmaxy();

rectangle(0,0,maxx,maxy);
setviewport(1,1,maxx-1,maxy-1,1);

if(initmouse()==0)
{
closegraph();
restorecrtmode();
printf("Mouse driver not loaded");
exit();
}

restrictmouseptr(1,1,maxx-1,maxy-1);
showmouseptr();

while(!kbhit())
{
getmousepos(&button,&x,&y);

if((button&1)==1)
{
hidemouseptr();

prevx=x;
prevy=y;
gotoxy(60,3);
printf("x %d y %d",x,y);

/*while((button&1)==1)*/
while((button)==1)
{
setcolor(15);//15: white color
/* color can be changed as per requirement*/
line(prevx,prevy,x,y);
prevx=x;
prevy=y;

getmousepos(&button,&x,&y);
}

showmouseptr();
}}}
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
restrictmouseptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);

i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}

getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);

*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
gotoxy(60,3);
printf("x %d y %d",*x,*y);
}

Previous Page       C Projects Home          Next Page