Color Magic


///####SOURCE CODE IS GIVEN BELOW####///

#include <graphics.h>
#include <dos.h>
void colorbox();
union REGS i,o;
init_mouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
show_mouse()
{
i.x.ax=1;
int86(0x33,&i,&o);
}

hide_mouse()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
get_mouse_pos(int *x,int *y,int *button)
{
i.x.ax=3;
int86(0x33,&i,&o);
*x=o.x.cx;
*y=o.x.dx;
*button=o.x.bx&1;
}
main()
{ int e,brush=0,k,b,t;
char name[10];
int gdriver = DETECT, gmode, errorcode,button,x1,y1,x2,y2;
initgraph(&gdriver, &gmode, “..\\bgi”);
init_mouse();
outtextxy(230,400,”Press any key to exit….”);
x1=x2=20;y1=20;y2=80;
for(k=1;k<10;k++)
{
line(x1,y1,x1,y2);
t=k;
while(t–)
line(x1+t,y1+t,x1+t,y2+t);
x1+=20;
}
printf(“enter brush size”);
scanf(“%d”,&b);
cleardevice();
colorbox();
while(!kbhit())
{
brush=b;
show_mouse();
get_mouse_pos(&x1,&y1,&button);
x2=x1;
y2=y1;
if(button==1)
{
hide_mouse();
if(x1>10&&x1<getmaxx()-50)
{
if(x1<30)
setcolor(1);
else if(x1<60)
setcolor(2);
else if(x1<60)
setcolor(2);
else if(x1<90)
setcolor(3);
else if(x1<120)
setcolor(4);
else if(x1<150)
setcolor(5);
else if(x1<180)
setcolor(6);
else if(x1<210)
setcolor(7);
else if(x1<240)
setcolor(8);
else if(x1<270)
setcolor(9);
else if(x1<300)
setcolor(10);
else if(x1<330)
setcolor(11);
else if(x1<360)
setcolor(12);
else if(x1<390)
setcolor(13);
else if(x1<420)
setcolor(14);
else if(x1<450)
setcolor(15);
else if(x1<480)
setcolor(30);
else if(x1<510)
setcolor(17);
else if(x1<540)
setcolor(18);
else if(x1<570)
setcolor(19);
else if(x1<600)
setcolor(20);
else if(x1<630)
setcolor(21);

line(x1,y1,x2,y2);
while(brush–) {
line(x1+brush,y1+brush,x2+brush,y2+brush);   }
x1=x2;
y1=y2;          }
button–;
get_mouse_pos(&x2,&y2,&button);
}
}
setcolor(BLACK);
settextstyle(3,0,5);
outtextxy(getmaxx()/2-20,getmaxy()/2,name);
getchar();
getchar();
}
void colorbox()
{
int i,j,k,x,y,vx,vy;
vx=-30;vy=0 ;
y=getmaxy();
rectangle(10,y-50,getmaxx()-50,y-4);
for(i=1;i<=20;i++)
{
x=i*30;
line(x,y-50,x,y-4);
setcolor(i);
setfillstyle(1,i);
bar(x-30,y-50,x,y-4);
//setfillstyle(1,i+40);
//bar(5,vx+30,25,vx+60);
//vx+=30;
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s