Commit 0895d3b8 authored by Jalay 's avatar Jalay

Upload new file

parent e926d479
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
union REGS i, o;
int leftcolor[15];
double bez(double t,int p[],int a,int b)
{
if(a==b)
return p[a];
else
return (1-t)*bez(t,p,a,b-1)+t*bez(t,p,a+1,b);
}
int get_key()
{
union REGS i,o;
i.h.ah = 0;
int86(22,&i,&o);
return ( o.h.ah );
}
void draw_color_panel()
{
int left, top, c, color;
left = 120;
top = 436;
color = getcolor();
setcolor(GREEN);
rectangle(4,431,635,457);
setcolor(WHITE);
settextstyle(TRIPLEX_FONT,0,2);
outtextxy(30,431,"Colors : ");
for( c = 1 ; c <= 16 ; c++ )
{
setfillstyle(SOLID_FILL, c);
bar(left, top, left+16, top+16);
leftcolor[c-1] = left;
left += 26;
}
setcolor(color);
}
void draw_shape_panel()
{
int left, top, c, color;
left = 529;
top = 45;
color = getcolor();
setcolor(GREEN);
rectangle(525,40,633,255);
setcolor(CYAN);
for( c = 1 ; c <= 7 ; c++ )
{
rectangle(left, top, left+100, top+25);
top += 30;
}
setcolor(WHITE);
outtextxy(535,45,"Fill Rect.");
outtextxy(535,75,"Line");
outtextxy(535,105,"Dot");
outtextxy(535,135,"Ellipse");
outtextxy(535,165,"Pencil");
outtextxy(535,195,"Rectangle");
outtextxy(535,225,"Erase All");
setcolor(color);
}
void change_color(int x, int y)
{
int c;
for( c = 0 ; c <= 13 ; c++ )
{
if( x > leftcolor[c] && x < leftcolor[c+1] && y > 437 && y < 453 )
setcolor(c+1);
if( x > leftcolor[14] && x < 505 && y > 437 && y < 453 )
setcolor(WHITE);
}
}
char change_shape(int x, int y)
{
if ( x > 529 && x < 625 && y > 45 && y < 70 )
return 'b';
else if ( x > 529 && x < 625 && y > 75 && y < 100 )
return 'l';
else if ( x > 529 && x < 625 && y > 105 && y < 130 )
return 'p';
else if ( x > 529 && x < 625 && y > 135 && y < 160 )
return 'e';
else if ( x > 529 && x < 625 && y > 165 && y < 190 )
return 'f';
else if ( x > 529 && x < 625 && y > 195 && y < 220 )
return 'r';
else if ( x > 529 && x < 625 && y > 225 && y < 250 )
return 'c';
return 'm';
}
void showmouseptr()
{
i.x.ax = 1;
int86(0x33,&i,&o);
}
void hidemouseptr()
{
i.x.ax = 2;
int86(0x33,&i,&o);
}
void 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);
}
void 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;
}
main()
{
int gd = DETECT,gm;
int maxx,maxy,x,y,button,prevx,prevy,temp1,temp2,key,color;
char ch = 'f' ;
int i,signdx,signdy;
float len,abx,aby,dx,dy,xx,yy;
initgraph(&gd,&gm,"..//BGI");
maxx = getmaxx();
maxy = getmaxy();
setcolor(WHITE);
rectangle(0,0,maxx,maxy);
setcolor(YELLOW);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
outtextxy(maxx/2-120,maxy-23,"*** DRAWING WINDOW ***");
draw_color_panel();
draw_shape_panel();
setviewport(1,1,maxx-1,maxy-1,1);
restrictmouseptr(1,1,maxx-1,maxy-1);
showmouseptr();
setcolor(BLUE);
setfillstyle(SOLID_FILL,15);
bar(2,2,518,427);
setviewport(60,60,500,400,1);
while(1)
{
if(kbhit())
{
key = get_key();
if( key == 1 )
{
closegraph();
exit(0);
}
}
getmousepos(&button,&x,&y);
if( button == 1 )
{
if( x > 4 && x < 635 && y > 431 && y < 457 )
change_color( x, y );
else if ( x > 529 && x < 625 && y > 40 && y < 250 )
ch = change_shape( x, y );
temp1 = x ;
temp2 = y ;
if ( ch == 'f' )
{
hidemouseptr();
while( button == 1 )
{
line(temp1,temp2,x,y);
temp1 = x;
temp2 = y;
getmousepos(&button,&x,&y);
}
showmouseptr();
}
while( button == 1)
getmousepos(&button,&x,&y);
/* to avoid interference of mouse while drawing */
// hidemouseptr();
if( ch == 'p')
putpixel(x,y,getcolor());
else if ( ch == 'b' )
{
setfillstyle(SOLID_FILL,getcolor());
bar(temp1,temp2,x,y);
}
else if ( ch == 'l')
{ // line(temp1,temp2,x,y);
double step,i,t;
float size;
int x0=10,n,y0=10,x1=100,y1=200,x2=300,y2=200,x3=100,y3=100,x,y;
int arrx[10]={50,100,300,200},arry[10]={60,200,300,100};
//int gd=DETECT,gm;
//clrscr();
//printf("enter the order of the curve:");
//scanf("%d",&n);
n = 3;
//printf("enter the control points:");
//for(i=0;i<=n;i++)
//{
// scanf("%d %d",&arrx[i],&arry[i]);
//}
//initgraph(&gd,&gm,"..\\bgi");
//setcolor(GREEN);
setcolor(RED);
step=500;
size=1.0/(double)step;
moveto(arrx[0],480-arry[0]);
for(i=1;i<step;i++){
t=size*(double)i;
x=bez(t,arrx,0,n);
y=bez(t,arry,0,n);
lineto(x,480-y);
}
//setcolor(CYAN);
// moveto(arrx[0],480-arry[0]);
//for(i=0;i<=n;i++)
//{
// lineto(arrx[i],480-arry[i]);
// }
// lineto(arrx[0],480-arry[0]);
//for(i=0;i<=n;i++)
//{
// putpixel(arrx[i],480-arry[i],YELLOW);
// }
//closegraph();
//restorecrtmode();
if(temp1>x)
abx=temp1-x;
else
abx=x-temp1;
if(temp2>y)
aby=temp2-y;
else
aby=y-temp2;
if(abx>=aby)
len=abx;
else
len=aby;
dx=(temp1-x)/len;
if(abx>0)
signdx=1;
else
signdx=-1;
dy=(temp2-y)/len;
if(aby>0)
signdy=1;
else
signdy=-1;
xx=x+(0.5)*signdx;
yy=y+(0.5)*signdy;
for(i=1;i<=len;i++)
{
putpixel(xx,yy,getcolor());
xx+=dx;
yy+=dy;
}
}
else if ( ch == 'e')
ellipse(temp1,temp2,0,360,abs(x-temp1),abs(y-temp2));
else if ( ch == 'r' )
rectangle(temp1,temp2,x,y);
else if ( ch == 'c' )
{
ch = 'f'; // setting to freehand drawing
clearviewport();
color = getcolor();
setcolor(WHITE);
setfillstyle(SOLID_FILL,15);
bar(2,2,518,427);
setcolor(color);
}
showmouseptr();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment