Paint Brush Program Updated

Previous Page       C Projects Home          Next Page

  • Modified paint brush program
  • In this programs we can draw with mouse
  • We can draw with different colors
  • The color can be selected using mouse and then we can draw.

/* with changes*/
#include<dos.h>
#include<graphics.h>

union REGS i,o;

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

maxx=getmaxx();
maxy=getmaxy();
rectangle(0,0,maxx,maxy);
setfillstyle(1,4);
rectangle(10,450,50,470);
outtextxy(15,453,"RED");
outtextxy(5,5,"Press Esc To Exit");
for(i=450;i<=470;i++)
{
setcolor(RED);
line(10,i,50,i);
}
setcolor(WHITE);
outtextxy(15,453,"RED");
rectangle(60,450,100,470);
for(i=450;i<=470;i++)
{
setcolor(GREEN);
line(60,i,100,i);
}
setcolor(WHITE);
outtextxy(62,453,"GREEN");
rectangle(110,450,150,470);
for(i=450;i<=470;i++)
{
setcolor(BLUE);
line(110,i,150,i);
}
setcolor(WHITE);
outtextxy(115,453,"BLUE");
rectangle(210,450,250,470);
outtextxy(212,453,"WHITE");
setcolor(WHITE);
rectangle(310,450,350,470);
outtextxy(312,453,"ERASE");
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)
{
if ((x>=10 && x<=50) && (y>=450 && y<=470))
z=4;
if ((x>=60 && x<=100) && (y>=450 && y<=470))
z=2;
if ((x>=110 && x<=150) && (y>=450 && y<=470))
z=1;
if ((x>=210 && x<=250) && (y>=450 && y<=470))
z=15;
if ((x>=310 && x<=350) && (y>=450 && y<=470))
z=0;
hidemouseptr();
prevx=x;
prevy=y;
gotoxy(60,3);
printf("x %d y %d",x,y);
while((button&1)==1)
{
setcolor(z);
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