Graphics Editor

in C

A Syllabus Project of Bangalore University
(Computer Science and Engineering. )

Designed by :-

Madhu Sudan Rao G.K
[gumballi@hotmail.com]

AND

Srivathsa M.P

[vathsa_mp@yahoo.co.uk]
Source Code

CONTENTS

1. Acknowledgements
2. Introduction
3. Editor Algorithm
4. Modules Used
5. Source Code

ACKNOWLEDGEMENTS

 

We would like to sincerely thank Mr.Inayath Khan for providing us with excellent technical support, constant feedback, and appropriate motivation.

We would also like to thank a lot of our classmates for sharing vital, rare and considerable information, for finding bugs (even though it proved to be a futile exercise).

 

INTRODUCTION

An editor is general-purpose system software, which can be used to enter, modify programs or data. Editors may be simple with limited range of operations or may be powerful with sophisticated commands. Editors are classified into 3 categories as follows

  1. 1)LINE EDITORS
  2. 2)SCREEN EDITORS
  3. 3)GRAPHIC EDITORS

Line and Screen editors are used for handling text where as graphical editors are used for handling pictures.

GRAPHICS EDITOR

A Graphical oriented Screen editor is mainly used for creating and modifying pictures, few operations on pictures include windowing, clipping, object moving Etc.

Ex: Flow, Coral draw, Auto Cad Etc.

One of the distinguishing features of Screen and Graphic editors is that any changes will be displayed on the screen soon after they are implemented.

STANDARD EDITORS

There are different editors available for different applications. One cannot conclude that a particular editor is standard because one editor may seem inferior to users who are accustomed to other editors. Therefore it is very difficult to standardize any particular editor. Moreover, the capability of the editor changes from one operating system to another operating system and one computer system to another.

Ex: 1) Norton’s editor 2) News Master editor 3) Banner 4) Print Master 5)Paint Brush

BASICS OF VIDEO DISPLAY UNIT

The two most important components of the computer system are

1) Video Screen

2) Video display adapter

The microprocessor does not have the ability to send signals necessary to produce the images on the screen. This task is performed by the display adapter. The display adapter acts as an agent between the up and video screen.

 

EDITOR ALGORITHM

A typical overall algorithm for an editor is as folow:

  1. START
  2.  

  3. INITIALIZATION
  4. Display Title bar, Status Bar, Toolbar, Menubar, Palettebar

    Initialize the mouse to display the pointer on screen

    Display various buttons, icons & fill patterns

     

  5. Repeat step 4 until QUIT
  6.  

  7. If any Toolbar Button Pressed then
  8. Perform corresponding operation like Line drawing, circle, ellipse, rectangle, reflection, rotation……

    Else

    If any menu Button is Pressed then

    If NEW Button Pressed then

    Open blank screen

    Else If OPEN Button Pressed then

    Open the requested file

    Else If SAVE Button Pressed then

    Save the file

    Else If DELETE Button Pressed then

    Delete the file

    Else If QUIT Button Pressed then

    Quit the editor

  9. TERMINATION

If file not saved then alert message to save file

Closegraph

Clear screen

 

MODULES USED

1. "proto.c"

Specifies the functions prototype used

------------------------------------------------------------------------

2. "point.c"

1.>drawpoint(int x1,int y1,int color)

2.>wrtstr(int x1,int y1,int color)

------------------------------------------------------------------------

3. "bres_lin.c"

1.>drawline(int x1,int y1,int color)

Draws line from x1,y1 to x2,y2 with color

2.>bres_line(x1,y1,x2,y2,color)

3.>slope1(x1,y1,x2,y2,const1,const2,p,inc_val,color)

4.>slope2(x1,y1,x2,y2,const1,const2,p,inc_val,color)

5.>del_bres_line(int ch)

------------------------------------------------------------------------

4. "screen.c"

1.>screen()

2.>void about()

3.>void get_date()

------------------------------------------------------------------------

5. "option.c"

1.>int get_option_or_color(int x,int y)

Select options from screen options

2.>int between(x,y,x1,y1,x2,y2);

Returns "1" if the mouse pointer (x,y) is within the specified

area (x1,y1) and (x2,y2)

------------------------------------------------------------------------

6. "circle.c"

1.>drawcircle(int x1,int y1,int color)

Draws circle with x1,y1 as center and abs(x2-x1) as radius

2.>bres_circle(x1,y1,x2,color)

3.>draw_circle(int x_c,int y_c,int rad,int color)

4.>plot_cir_pt(int x_c,int y_c,int x,int y,int color)

------------------------------------------------------------------------

7. "rect.c"

1.>drawrect(int x1,int y1,int color)

2.>void getpattern()

------------------------------------------------------------------------

8. "clip.c"

1.>inclip(int x1,int y1,int color)

Inside clipping from x1,y1 to x2,y2

2.>outclip(int x1,int y1,int color)

Outside clipping from x1,y1 to x2,y2

------------------------------------------------------------------------

9. "shapes.c"

1.>cardiod(int x,int y,int r,int color)

2.>bres_cardiod(int x,int y,int r,int color)

3.>spiral(x,y,r,color)

------------------------------------------------------------------------

10. "carspi.c"

1.>drawcardiod(int x1,int y1,int color)

Draws cardiod with x1,y1 as center with distance=abs(x2-x1)

2.>drawspiral(int x1,int y1,int color)

Draws spiral with x1,y1 as centre & distance=abs(x2-x1)

3.>draw_spiral(int xc,int yc,int r,int color)

------------------------------------------------------------------------

11. "flood.c"

1.>void insert(x,y)

2.>void ffill(x,y,background_color,fill_color)

3.>fldfill(int x,int y,int color)

------------------------------------------------------------------------

12. "erase.c"

1.>erase(int x1,int y1)

Write in backgroundcolor at position x1,y1

------------------------------------------------------------------------

13. "trans.c"

1.>translate(int x1,int y1,int color)

Translate selected portion

2.>rotate(int x1,int y1,int color)

Rotate the selected portion by 90 degres

3.>scal(int x1,int y1,int color)

Scale the selected portion with sx & sy as scaling factors

------------------------------------------------------------------------

14. "fileopt.c"

1.>newfile()

Creates a new file with file name as "NONAME".Before creating

this new file it asks if the currently open file is to be saved.

2.>save()

If the file is been saved for the first time then it asks for

a file name else it simply saves.

3.>load()

Asks the user to enter a file name.

4.>saveas()

Asks the user to enter a name with which the file is to be saved.

This is done by simply changing the file name to "NONAME" and

calling the module " save() ".

5.>clear()

6.>question()

------------------------------------------------------------------------

15. "ellipse.c"

1.>int bres_ellipse(int,int,float,float,int);

Draws ellipse with x1,y1 as centre & abs(x2-x1) as major axis

& abs(y2-y1) as minor axis

2.>drawellipse(int x1,int y1,int color)

3.>plot_ellipse_points(x_c,y_c,x,y,color)

------------------------------------------------------------------------

16. "mouse.c"

1.> showcursor()

Shows back the cursor.

2.> hidecursor()

Hides the cursor.

3.> getmousepos(int *button,int *x,int *y)

Gives mouse pointer position on screen & mouse button status.

4.> restrictmouseptr(int x1,int y1,int x2,int y2)

Sets horizontal & vertical limits for mouse pointers.

------------------------------------------------------------------------

17. "help.c"

1.> void display_help()

2.> void help()

------------------------------------------------------------------------

18. "main.c" - Main Program

------------------------------------------------------------------------


SOURCE CODE

/* FILE NAME : "bres_lin.c" */
/* Draws line from x1,y1 to x2,y2 with color */

drawline(int x1,int y1,int color)
{
 int x2,y2,xprev,yprev;
 hidecursor();
 xprev=x1;yprev=y1;
 do
 {
  setcolor(color);
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2 || yprev!=y2)
  {
   del_bres_line(1);
   bres_line(x1,y1,x2,y2,color);
   xprev=x2;
   yprev=y2;
  }
 }while(out.x.bx==1);
 del_bres_line(0);
 showcursor();
 return 1;
}

bres_line(x1,y1,x2,y2,color)
int x1,y1,x2,y2,color;
{
 int dy,const1,const2;
 double p;
 float slope,dx;
 setcolor(color);
 dx=abs(x2-x1);
 dy=abs(y2-y1);
 if(dx==0)
 {
  slope=dy;
 }
 else
 slope=dy/dx;
 p=2*dy-dx;
 const1=2*dy;
 const2=2*(dy-dx);
 if(slope<=1 && slope >=0 && ((x1<=x2 && y1<=y2) || (x1>=x2 && y1>= y2)))
      slope1(x1,y1,x2,y2,const1,const2,p,1,color);
 else if(slope>1 &&((x1<=x2 && y1<=y2)||(x1>=x2 && y1>=y2)))
      {
       p=2*dx-dy;
       const1=2*dx;
       const2=2*(dx-dy);
       slope2(x1,y1,x2,y2,const1,const2,p,1,color);
      }
      else if(slope>0&& slope <= 1 &&( (x1y2)||(x1>x2 && y11 && ((x1y2)||(x1>x2 && y1x2)
 {
  x=x2;y=y2;
  x_end=x1;
 }
 else
 {
  x=x1;y=y1;
  x_end=x2;
 }
 if( between(x,y,70,40,620,400) )
 {
  new=(struct link *)malloc(sizeof(struct link));
  col=getpixel(x,y);
  new->xpos=x;
  new->ypos=y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x,y,color);
 }
 while(x0)
	p+=const1;
  else
  {
   y+=inc_val;
   p+=const2;
  }
  if( between(x,y,70,40,620,400) )
  {
   new=(struct link *)malloc(sizeof(struct link));
   col=getpixel(x,y);
   new->xpos=x;
   new->ypos=y;
   new->pcol=col;
   new->next=head;
   head=new;
   putpixel(x,y,color);
  }
 }				/* End While construct */
 return 1;
}

slope2(x1,y1,x2,y2,const1,const2,p,inc_val,color)
int x1,x2,y1,y2,const2,const1,inc_val,color;
double p;
{
 int y_end,x,y,col;
 struct link *new;
 if(y1>y2)
 {
  x=x2;y=y2;
  y_end=y1;
 }
 else
 {
  x=x1;y=y1;
  y_end=y2;
 }
 if( between(x,y,70,40,620,400) )
 {
  new=(struct link *)malloc(sizeof(struct link));
  col=getpixel(x,y);
  new->xpos=x;
  new->ypos=y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x,y,color);
 }
 while(y0)
	p+=const1;
  else
  {
   x+=inc_val;
   p+=const2;
  }
  if( between(x,y,70,40,620,400) )
  {
   new=(struct link *)malloc(sizeof(struct link));
   col=getpixel(x,y);
   new->xpos=x;
   new->ypos=y;
   new->pcol=col;
   new->next=head;
   head=new;
   putpixel(x,y,color);
  }
 }					/* End While construct */
 return 1;
}

/* if ch==1 putpixel with color if ch==0 without putpixel */

del_bres_line(int ch)
{
 int xp,yp,pc;
 struct link *cur;
 while(head!=NULL)
 {
  cur=head;
  if(ch==1)
  {
   xp=head->xpos;
   yp=head->ypos;
   pc=head->pcol;
   putpixel(xp,yp,pc); /* "putpixel" plots a pixel at a specified point */
  }		       /* in the specified color.		        */
  head=head->next;
  free(cur);
 }					/* End While construct */
 return 1;
}

/* FILE NAME : "carspi.c" */
/* Draws cardiod with x1,y1 as center with distance=abs(x2-x1) */

drawcardiod(int x1,int y1,int color)
{
 int x2,y2,xprev,yprev;

 hidecursor();
 xprev=x1;yprev=y1;
 do
 {
  setcolor(color);
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2 || yprev!=y2)
  {
   del_bres_line(1);
   bres_cardiod(x1,y1,(abs)(x2-x1),color);
   xprev=x2;
   yprev=y2;
  }
 }while(out.x.bx==1);
 del_bres_line(0);
 showcursor();
 return 1;
}

/* Draws spiral with x1,y1 as centre & distance=abs(x2-x1) */

drawspiral(int x1,int y1,int color)
{
 int x2,y2,xprev,yprev;

 hidecursor();
 xprev=x1;yprev=y1;
 do
 {
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2 || yprev!=y2)
  {
   del_bres_line(1);
   draw_spiral(x1,y1,(abs)(x2-x1),color);
   xprev=x2;
   yprev=y2;
  }
 }while(button == 1);
 del_bres_line(0);
 showcursor();
 return 1;
}

draw_spiral(int xc,int yc,int r,int color)
{
 int x3,y3,x4,y4,radius,xd;
 float theta=0;
 int a=4;
 float dtheta=1.0/a;

 x3=xc;
 y3=yc;
 do
 {
  radius=a*theta;
  x4=xc+radius*cos(theta);
  y4=yc+radius*sin(theta);
  xd=abs(x4-xc);
  bres_line(x3,y3,x4,y4,color);
  x3=x4;
  y3=y4;
  theta=theta+dtheta;
 } while(xd/r)
return 1;
}

/* FILE NAME : circle.c */
/* Draws circle with x1,y1 as center and abs(x2-x1) as radius */

drawcircle(int x1,int y1,int color)
{
 int x2,y2,xprev,yprev,k;

 hidecursor();
 xprev=x1;yprev=y1;
 do
 {
  setcolor(color);
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2||yprev!=y2)
  {
   del_bres_line(1);
   bres_circle(x1,y1,x2,color);
  }
  xprev=x2;yprev=y2;
 } while(button == 1);
 del_bres_line(0);
 if(pattern==on)		/* draws pattern */
 {
  k=abs(x2-x1);
  if( (k<(abs(x1-101))) && (k<(abs(619-x1)))
	      && (k<(abs(y1-41))) && (k<(abs(399-y1))) )
  {
   getpattern();
   setfillpattern(style,color);
   pieslice(x1,y1,0,360,abs(x2-x1));
  } /* "pieslice" [library function] draws and fills a circular pie slice */
 }  /* centre of pie slice = (x1,y1) ; start angle in deg = 0 ;           */
 showcursor();   /* end angle in deg = 360 ; radius = abs(x2-x1)          */
 return 1;
}

bres_circle(x1,y1,x2,color)
int x1,y1,x2,color;
{
 int r1;
 /*	r1=(int)sqrt(abs(x2-x1)*abs(x2-x1)+abs(y2-y1)*abs(y2-y1));*/
 r1=abs(x2-x1);
 draw_circle(x1,y1,r1,color);
 return 1;
}

draw_circle(int x_c,int y_c,int rad,int color)
{
 int p,x,y;

 x=0; y=rad; p=3-2*rad;
 while(x0)
  {
   p=p+4*x+6;
  }
  else
  {
   p=p+4*(x-y)+10;
   y=y-1;
  }
  x=x+1;
 }			/* End While construct	*/
 if(x==y)
       plot_cir_pt(x_c,y_c,x,y,color);
 return 1;
}

plot_cir_pt(int x_c,int y_c,int x,int y,int color)
{
 int col;

 if( between(x_c+x,y_c+y,70,40,620,400) )
 {
  struct link *new;
  col=getpixel(x_c+x,y_c+y);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c+x;
  new->ypos=y_c+y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c+x,y_c+y,color);
 }
 if( between(x_c-x,y_c+y,70,40,620,400) )
 {
  col=getpixel(x_c-x,y_c+y);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c-x;
  new->ypos=y_c+y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c-x,y_c+y,color);
 }
 if( between(x_c+x,y_c-y,70,40,620,400) )
 {
  col=getpixel(x_c+x,y_c-y);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c+x;
  new->ypos=y_c-y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c+x,y_c-y,color);
 }
 if( between(x_c-x,y_c-y,70,40,620,400) )
 {
  col=getpixel(x_c-x,y_c-y);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c-x;
  new->ypos=y_c-y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c-x,y_c-y,color);
 }
 if( between(x_c+y,y_c+x,70,40,620,400) )
 {
  col=getpixel(x_c+y,y_c+x);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c+y;
  new->ypos=y_c+x;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c+y,y_c+x,color);
 }
 if( between(x_c-y,y_c+x,70,40,620,400) )
 {
  col=getpixel(x_c-y,y_c+x);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c-y;
  new->ypos=y_c+x;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c-y,y_c+x,color);
 }
 if( between(x_c+y,y_c-x,70,40,620,400) )
 {
  col=getpixel(x_c+y,y_c-x);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c+y;
  new->ypos=y_c-x;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c+y,y_c-x,color);
 }
 if( between(x_c-y,y_c-x,70,40,620,400) )
 {
  col=getpixel(x_c-y,y_c-x);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c-y;
  new->ypos=y_c-x;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c-y,y_c-x,color);
 }
 return 1;
}

/* FILE NAME : "clip.c" */

/* Inside clipping from x1,y1 to x2,y2 */

inclip(int x1,int y1,int color)
{
 int i,j,x2,y2,xprev,yprev;

 hidecursor();
 xprev=x1;
 yprev=y1;
 do
 {
  setcolor(color);
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2||yprev!=y2)
  {
   setcolor(WHITE);
   del_bres_line(1);
   bres_line(x1,y1,x2,y1,color);
   bres_line(x2,y1,x2,y2,color);
   bres_line(x2,y2,x1,y2,color);
   bres_line(x1,y2,x1,y1,color);
  }
  xprev=x2;yprev=y2;
 } while(button == 1);
 del_bres_line(0);
 if(x2<70)  x2=70;
 if(x2>620)  x2=620;
 if(y2<40)  y2=40;
 if(y2>400)  y2=400;
 if(x1>x2)
 {
  xprev=x1;
  x1=x2;
  x2=xprev;
 }
 if(y1>y2)
 {
  yprev=y1;
  y1=y2;
  y2=yprev;
 }
 for(i=x1;i<=x2;i++)
    for(j=y1;j<=y2;j++)
       putpixel(i,j,WHITE);
 showcursor();
 return 1;
}

/* Outside clipping from x1,y1 to x2,y2 */

outclip(int x1,int y1,int color)
{
 int i,j,x2,y2,xprev,yprev;

 hidecursor();
 xprev=x1;
 yprev=y1;
 do
 {
  setcolor(color);
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2||yprev!=y2)
  {
   setcolor(WHITE);
   del_bres_line(1);
   bres_line(x1,y1,x2,y1,color);
   bres_line(x2,y1,x2,y2,color);
   bres_line(x2,y2,x1,y2,color);
   bres_line(x1,y2,x1,y1,color);
  }
  xprev=x2;yprev=y2;
 } while(button == 1);
 del_bres_line(0);
 if(x2<70)  x2=70;
 if(x2>620)  x2=620;
 if(y2<40)  y2=40;
 if(y2>400)  y2=400;
 if(x1>x2)
 {
  xprev=x1;
  x1=x2;
  x2=xprev;
 }
 if(y1>y2)
 {
  yprev=y1;
  y1=y2;
  y2=yprev;
 }
 for(i=70;i<=620;i++)
    for(j=40;j<=400;j++)
       if(!between(i,j,x1,y1,x2,y2) )
			putpixel(i,j,WHITE);
 setcolor(WHITE);
 rectangle(x1,y1,x2,y2);
 showcursor();
 return 1;
}

/* FILE NAME : "ellipse.c" */
/* Draws ellipse with x1,y1 as centre & abs(x2-x1) as major axis
   & abs(y2-y1) as minor axis */

int  bres_ellipse(int,int,float,float,int);

drawellipse(int x1,int y1,int color)
{
 int x2,y2,xprev,yprev,k,l;

 xprev=x1;
 yprev=y1;
 hidecursor();
 do
 {
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2 || yprev!=y2)
  {
   del_bres_line(1);
   bres_ellipse(x1,y1,(abs)(x2-x1)*2+5,(abs)(y2-y1)*2+5,color);
   xprev=x2;
   yprev=y2;
  }
 } while(button == 1);
 del_bres_line(0);
 if(pattern==on)		 /* draws pattern */
 {
  k=2*abs(x2-x1);
  l=2*abs(y2-y1);
  if( (k<(abs(x1-104))) && (k<(abs(616-x1)))
	      && (l<(abs(y1-44))) && (l<(abs(396-y1))) )
  {
   getpattern();
   setfillpattern(style,color);
   sector(x1,y1,0,360,2*abs(x2-x1)+5,2*abs(y2-y1)+5);
  }
 }
 showcursor();
 return 1;
}

bres_ellipse(int xc,int yc,float r1,float r2,int color)
{
 int x,y,y1,x1;
 float p;

 x=0;
 y=r2;
 p=1-2*r2+2*(r2/r1)*(r2/r1);
 if(r1>=r2)
 {
  while(x<(r1*y/r2 + (r1-r2)))
  {
   plot_ellipse_points(xc,yc,x,y,color);
   if(p<0)
	p+=(4*x+6)*(r2/r1)*(r2/r1);
   else
   {
    p+=(4*x+6)*(r2/r1)*(r2/r1)+4*(1-y);
    y--;
   }
   x++;
  }				/* End While construct */
  p=1-2*r1+2*(r1/r2)*(r1/r2);
  y1=0;
  x=r1;
  while(y1<=y)
  {
   plot_ellipse_points(xc,yc,x,y1,color);
   if(p<0)
	p+=(4*y1+6)*(r1/r2)*(r1/r2);
   else
   {
    p+=(4*y1+6)*(r1/r2)*(r1/r2)+4*(1-x);
    x--;
   }
   y1++;
  }					/* End While construct */
 }
 else
 {
  p=1-2*r1+2*(r1/r2)*(r1/r2);
  y=0;
  x=r1;
  while(y<(r2*x/r1+(r2-r1)))
  {
   plot_ellipse_points(xc,yc,x,y,color);
   if(p<0)
	p+=(4*y+6)*(r1/r2)*(r1/r2);
   else
   {
    p+=(4*y+6)*(r1/r2)*(r1/r2)+4*(1-x);
    x--;
   }
   y++;
  }					/* End While construct */
  x1=0;
  y=r2;
  p=1-2*r2+2*(r2/r1)*(r2/r1);
  while(x1<=x)
  {
   plot_ellipse_points(xc,yc,x1,y,color);
   if(p<0)
	p+=(4*x1+6)*(r2/r1)*(r2/r1);
   else
   {
    p+=(4*x1+6)*(r2/r1)*(r2/r1)+4*(1-y);
    y--;
   }
   x1++;
  }					/* End While construct */
 }
 return 1;
}


plot_ellipse_points(x_c,y_c,x,y,color)
int x_c,y_c,x,y,color;
{
 int col;
 struct link *new;

 if( between(x_c+x,y_c+y,70,40,620,400) )
 {
  col=getpixel(x_c+x,y_c+y);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c+x;
  new->ypos=y_c+y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c+x,y_c+y,color);
 }
 if( between(x_c-x,y_c+y,70,40,620,400) )
 {
  col=getpixel(x_c-x,y_c+y);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c-x;
  new->ypos=y_c+y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c-x,y_c+y,color);
 }
 if( between(x_c+x,y_c-y,70,40,620,400) )
 {
  col=getpixel(x_c+x,y_c-y);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c+x;
  new->ypos=y_c-y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c+x,y_c-y,color);
 }
 if( between(x_c-x,y_c-y,70,40,620,400) )
 {
  col=getpixel(x_c-x,y_c-y);
  new=(struct link *)malloc(sizeof(struct link));
  new->xpos=x_c-x;
  new->ypos=y_c-y;
  new->pcol=col;
  new->next=head;
  head=new;
  putpixel(x_c-x,y_c-y,color);
 }
 return 1;
}

/* FILE NAME : "erase.c" */
/* Write in backgroundcolor at position x1,y1 */

erase(int x1,int y1)
{
 int i,j,x2,y2,xprev,yprev;

 hidecursor();
 x2=x1+10;
 y2=y1+10;
 if(x2<70)  x2=70;
 if(x2>620)  x2=620;
 if(y2<40)  y2=40;
 if(y2>400)  y2=400;
 if(x1>x2)
 {
  xprev=x1;
  x1=x2;
  x2=xprev;
 }
 if(y1>y2)
 {
  yprev=y1;
  y1=y2;
  y2=yprev;
 }
 for(i=x1;i<=x2;i++)
    for(j=y1;j<=y2;j++)
       putpixel(i,j,WHITE);
 showcursor();
 return 1;
}

/* FILE NAME : "fileopt.c" */

newfile()
{
 question();
 setfillstyle(1,WHITE);
 bar(70,40,620,400);

 setfillstyle(1,LIGHTGRAY);
 bar(392,20,550,39);
 setcolor(BLUE);
 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
 outtextxy(420,25,"noname");
 strcpy(filename,"noname");

 setfillstyle(1,BLACK);
 bar(110,415,140,455);
 pattern=off;
 patopt=0;
 setfillstyle(1,WHITE);
 bar(50,415,80,455);

 option=1;
 color=BLACK;
 return 1;
}

save()
{
 FILE *fp;
 int i,j,col;
 char ch[1];
 char namex[8];

 hidecursor();
 if(strcmp(filename,"NONAME") == 0 || strcmp(filename,"noname") == 0)
 {
  fp=fopen("tra","w");
  for(i=250;i<=430;i++)
  {
   for(j=220;j<=300;j++)
   {
    col=getpixel(i,j);
    fputc(col,fp);
   }
  }
  fclose(fp);

  setfillstyle(1,YELLOW);
  bar(250,220,430,300);
  setcolor(BLACK);
  outtextxy(275,225,"Enter File Name");
  setfillstyle(1,GREEN);
  bar(275,250,400,280);
  moveto(278,260);
  i=0;j=0;
   /* take in the place */
  while(1)
  {
   namex[i]=getch();
   sprintf(ch,"%c",namex[i]);
   if(namex[i]=='\n'|| namex[i]=='\r')
   {
    namex[i]='\0';
    strcpy(filename,namex);
    break;
   }
   else
   {
    outtext(ch);
    i++;
   }
  }
  setfillstyle(1,LIGHTGRAY);
  bar(392,20,550,39);
  setcolor(BLUE);
  outtextxy(420,25,filename);

  fp=fopen("tra","r");
  for(i=250;i<=430;i++)
  {
   for(j=220;j<=300;j++)
   {
    col=fgetc(fp);
    putpixel(i,j,col);
   }
  }
  fclose(fp);
 }

 fp=fopen(filename,"w");
 for(i=71;i<620;i++)
 {
  for(j=41;j<400;j++)
  {
   col=getpixel(i,j);
   fputc(col,fp);
  }
 }
 fclose(fp);

 showcursor();
 option=prevopt;
 outtextxy(420,440,"Saving...");
 delay(20);
 setfillstyle(1,BLUE);
 bar(420,460,440,480);
 delay(20);
 bar(440,460,460,480);
 delay(20);
 bar(460,460,480,480);
 delay(20);
 bar(480,460,500,480);
 delay(20);
 bar(500,460,520,480);
 delay(20);
 bar(520,460,540,480);
 delay(20);
 bar(540,460,560,480);
 delay(20);
 bar(560,460,580,480);
 delay(20);
 bar(580,460,600,480);
 delay(20);
 setfillstyle(1,CYAN);
 delay(20);
 bar(400,440,600,480);
 return 1;
}


load()
{
 FILE *fp;
 int i,j,col;
 char flname[8];
 char ch[1];
 char namex[8];

 question();

 hidecursor();

 fp=fopen("tra","w");
 for(i=250;i<=430;i++)
 {
  for(j=220;j<=300;j++)
  {
   col=getpixel(i,j);
   fputc(col,fp);
  }
 }
 fclose(fp);

 strcpy(flname,filename);
 setfillstyle(1,YELLOW);
 bar(250,220,430,300);
 setcolor(BLACK);
 outtextxy(275,225,"File to open");
 setfillstyle(1,GREEN);
 bar(275,250,400,280);
 moveto(278,260);

 i=0;j=0;
  /* take in the place */
 while(1)
 {
  namex[i]=getch();
  sprintf(ch,"%c",namex[i]);
  if(namex[i]=='\n'|| namex[i]=='\r')
  {
   namex[i]='\0';
   strcpy(filename,namex);
   break;
  }
  else
  {
   outtext(ch);
   i++;
  }
 }

 fp=fopen(filename,"r");
 if(fp==NULL)			/* if file not exists */
 {
  setcolor(BLACK);
  outtextxy(275,290,"File Not Found!");
  getch();
  strcpy(filename,flname);

  fp=fopen("tra","r");
  for(i=250;i<=430;i++)
  {
   for(j=220;j<=300;j++)
   {
    col=fgetc(fp);
    putpixel(i,j,col);
   }
  }
  fclose(fp);
 }
 else
 {
  fp=fopen(filename,"r");
  for(i=71;i<620;i++)
  {
   for(j=41;j<400;j++)
   {
    col=fgetc(fp);
    putpixel(i,j,col);
   }
  }
  fclose(fp);

  setfillstyle(1,LIGHTGRAY);
  bar(392,20,550,38);
  setcolor(BLUE);
  settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
  outtextxy(420,25,filename);
/*	 line(390,20,390,40);
	 line(550,20,550,40);*/
 }
 showcursor();
 option=prevopt;
 return 1;
}

saveas()
{
 strcpy(filename,"noname");
 save();
 option=prevopt;
 return 1;
}

clear()
{
 setfillstyle(SOLID_FILL,WHITE);
 bar(71,41,619,399);
 pattern=off;
 sound(7);
 delay(1000);
 nosound();
 return 1;
}

question()
{
	union REGS in,out;
	char temp;
	FILE *fp1;
	int i,j,col;
	 //Question to Save then erase
	hidecursor();
	fp1=fopen("tra1","w");

	for(i=250;i<=430;i++)
	   {
		  for(j=220;j<=300;j++)
		 {
			col=getpixel(i,j);
			fputc(col,fp1);
		 }
	   }
	fclose(fp1);

	 setfillstyle(1,YELLOW);
	 bar(250,220,430,300);
	 setcolor(BLACK);
	 outtextxy(275,225,"Save Y/N");
	 setfillstyle(1,GREEN);
	 bar(275,250,400,280);
	 moveto(278,260);
	 temp=getche();

	 fp1=fopen("tra1","r");

	for(i=250;i<=430;i++)
	   {
		  for(j=220;j<=300;j++)
		 {
			col=fgetc(fp1);
			putpixel(i,j,col);
		 }
	   }
	fclose(fp1);
	showcursor();

	if(temp=='y'||temp=='Y')
		save();
	return ;
}

/* FILE NAME : "flood.c" */

struct node1
{
 int x;
 int y;
 struct node1 *next;
};

struct node1 *root1,*p1,*last1;
int x,y;

void insert(x,y)
int x,y;
{
 struct node1 *new1;

 new1=(struct node1*)malloc(sizeof(struct node1));
 new1->x=x;
 new1->y=y;
 new1->next=NULL;
 last1->next=new1;
 last1=new1;
 return;
}

void ffill(x,y,background_color,fill_color)
int x,y,background_color,fill_color;
{
 if(background_color==fill_color)
	     return;
 last1=root1=(struct node1*)malloc(sizeof(struct node1));
 root1->x=x;
 root1->y=y;
 root1->next=NULL;
 while(root1!=NULL)
 {
  putpixel(x,y,fill_color);
  if(getpixel(x,y-1)==background_color)
  {
   putpixel(x,y-1,fill_color);
   insert(x,y-1);
  }
  if(getpixel(x+1,y)==background_color)
  {
   putpixel(x+1,y,fill_color);
   insert(x+1,y);
  }
  if(getpixel(x,y+1)==background_color)
  {
   putpixel(x,y+1,fill_color);
   insert(x,y+1);
  }
  if(getpixel(x-1,y)==background_color)
  {
   putpixel(x-1,y,fill_color);
   insert(x-1,y);
  }
  p1=root1;
  root1=root1->next;
  free(p1);
  x=root1->x;
  y=root1->y;
 }				/* End While construct */
}

fldfill(int x,int y,int color)
{
 int bcolor;

 hidecursor();
 bcolor=getpixel(x,y);
 ffill(x,y,bcolor,color);
/*	 area_fill(x,y,bcolor,color);*/
 showcursor();
 return 1;
}

void help()
{
 FILE *fp1;
 int i,j,col;

 hidecursor();

 fp1=fopen("tra1","w");
 for(i=70;i<=620;i++)
 {
  for(j=40;j<=400;j++)
  {
   col=getpixel(i,j);
   fputc(col,fp1);
  }
 }
 fclose(fp1);

 display_help();
 screen();

 fp1=fopen("tra1","r");
 for(i=70;i<=620;i++)
 {
  for(j=40;j<=400;j++)
  {
   col=fgetc(fp1);
   putpixel(i,j,col);
  }
 }
 fclose(fp1);

 showcursor();

}

void display_help()
{
 char choice;

 setfillstyle(1,WHITE);
 bar(70,40,620,400);
 setcolor(BLUE);
 outtextxy(78,43,"GRAPHICS EDITOR - HELP");
 setfillstyle(1,BLUE);
 setcolor(YELLOW);
 bar(70,58,620,68);
 outtextxy(78,60,"                      PRESS ANY KEY TO RETURN");
 setcolor(BLUE);
 outtextxy(78,73,"1.Translation ::");
 setcolor(BLACK);
 outtextxy(78,83," 1.Select an object & draw");
 outtextxy(78,93," 2.Click on the translate button");
 outtextxy(78,103," 3.Select an area of the object by pressing and dragging the");
 outtextxy(78,113,"   mouse button,a rectangle box would appear which comprises");
 outtextxy(78,123,"   the area selected.");
 outtextxy(78,133," 4.Now click anywhere on the screen where the object is");
 outtextxy(78,143,"   intended to be translated.Step 4 can be repeated to");
 outtextxy(78,153,"   successively");
 outtextxy(78,163,"   translate the object from one location to other."); setcolor(BLUE);
 outtextxy(78,173,"2.Rotation ::"); setcolor(BLACK);
 outtextxy(78,183," 1.Select an object and draw it on the screen");
 outtextxy(78,193," 2.Click on the Rotate button");
 outtextxy(78,203," 3.Select an area of the object by pressing and dragging");
 outtextxy(78,213,"   the mouse button,a rectangle box would appear which");
 outtextxy(78,223,"   comprises the area selected.");
 outtextxy(78,233,"   Once you release the mouse button,you will find the");
 outtextxy(78,243,"   selected portion of the object rotated by 90 degree.");
 outtextxy(78,253,"   Repeating Step 3 would result in successive");
 outtextxy(78,263,"   rotations by 90 degree."); setcolor(BLUE);
 outtextxy(78,273,"3.Scaling ::"); setcolor(BLACK);
 outtextxy(78,283," 1.Select an object and draw it on the screen");
 outtextxy(78,293," 2.Click on the Scale button a rectangle box would");
 outtextxy(78,303,"   appear which comprises");
 outtextxy(78,313," 3.Select an area of the object by pressing and dragging the");
 outtextxy(78,323,"   mouse button,the area selected.");
 outtextxy(78,333,"   Once you release the mouse button,a screen appears");
 outtextxy(78,343,"   prompting for the X and Y scaling values (Sx and Sy)");
 outtextxy(78,353," 4.Enter the Sx value followed by a space and enter the Sy value");
 outtextxy(78,363,"   and press Enter.");
 outtextxy(78,373,"   Repeating Step 3 and Step 4 would result in successive scaling.");
 setfillstyle(1,BLUE);
 bar(70,390,620,400);
 setcolor(YELLOW);
 outtextxy(78,393,"                      PRESS ANY KEY TO RETURN");

 choice = getch();
 option = 1;
}

/* FILE NAME : "liclip.c" */

lineclip(int x1,int y1,int color)
{
 int x2,y2,x3,y3,x4,y4,xprev,yprev;

 hidecursor();
 xprev=x1;
 yprev=y1;
 do
 {
  setcolor(color);
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2||yprev!=y2)
  {
   del_bres_line(1);
   bres_line(x1,y1,x2,y1,color);
   bres_line(x2,y1,x2,y2,color);
   bres_line(x2,y2,x1,y2,color);
   bres_line(x1,y2,x1,y1,color);
  }
  xprev=x2;yprev=y2;
 } while(button == 1);
 if(x2<100)  x2=100;
 if(x2>620)  x2=620;
 if(y2<40)  y2=40;
 if(y2>400)  y2=400;
 if(x1>x2)
 {
  xprev=x1;
  x1=x2;
  x2=xprev;
 }
 if(y1>y2)
 {
  yprev=y1;
  y1=y2;
  y2=yprev;
 }
 showcursor();
 xwmin=x1;ywmin=y1;xwmax=x2;ywmax=y2;
 do
 {
  getmousepos(&button,&x,&y);
 } while(!((button == 1)||(button == 2)));
 while(button != 2)
 {
  x3=x;
  y3=y;
  do
  {
   getmousepos(&button,&x,&y);
  } while(button == 1);
  if( between(x3,y3,100,40,620,400) )
  {
   do
   {
    getmousepos(&button,&x,&y);
   } while(button != 1);
   x4=x;
   y4=y;
   do
   {
    getmousepos(&button,&x,&y);
   } while(button == 1);
   setcolor(color);
   if( between(x4,y4,100,40,620,400) )
   {
    clip_line(x3,y3,x4,y4,color);
   }
  }
  do
  {
   getmousepos(&button,&x,&y);
  } while(!((button == 1)||(button == 2)));
 }
 del_bres_line(1);
 return 1;
}

void clip_line(x1,y1,x2,y2,color)
int x1,y1,x2,y2,color;
{
 int done,display;
 int code1[4],code2[4];
 float m;

 done = false;
 display = false;
 if ( x1 == x2 )
     m = (float)(y2-y1);
 else
     m = (float)(y2-y1)/(float)(x2-x1);
 if(m==0)
     m=1;
 while ( done == false )
 {
  encode(x1,y1,code1);
  encode(x2,y2,code2);
  if ( accept(code1,code2) )
  {
   done = true;
   display = true;
  }
  else if ( reject(code1,code2) )
       {
	done = true;
	setcolor(WHITE);
	line(x1,y1,x2,y2);
       }
       else /* find intersection */
       {
	swap_if_needed(&x1,&y1,&x2,&y2,code1,code2);  /* swap if needed */
	if ( code1[0] ) /* left bit */
	{
	 y1 = y1 + (xwmin-x1)*m;
	 x1 = xwmin;
	}
	else if ( code1[1] ) /* right bit */
	{
	 y1 = y1 + (xwmax-x1)*m;
	 x1=xwmax;
	}
	else if ( code1[2] ) /* bottom bit */
	{
	 x1 = x1 + (ywmin-y1)/m;
	 y1 = ywmin;
	}
	else if ( code1[3] )  /* top bit */
	{
	 x1 = x1+(ywmax-y1)/m;
	 y1=ywmax;
	}
      }
   }
   if ( display )
   {
    setcolor(color);	    /* draw lines */
    line(x1,y1,x2,y2);
   }
}

void encode(x,y,c)
int x,y,c[];
{
   if ( x < xwmin )
     c[0] = true;
   else
     c[0] = false;
   if ( x > xwmax )
     c[1] = true;
   else
     c[1] = false;
   if ( y < ywmin )
     c[2] = true;
   else
     c[2] = false;
   if ( y > ywmax )
     c[3] = true;
   else
     c[3] = false;
}

int accept(c1,c2)
int c1[4],c2[4];
{
   int k;

   for ( k = 0; k < 4; k++ )
      if ( c1[k] || c2[k] ) return(false);
   return(true);
}

int reject(c1,c2)
int c1[4],c2[4];
{
   int k;

   for ( k = 0; k < 4; k++ )
      if ( c1[k] && c2[k] ) return(true);
   return(false);
}

void swap_if_needed(x1,y1,x2,y2,c1,c2)
int *x1,*y1,*x2,*y2,c1[],c2[];
{
   int k,t;

   if ( (*x1 <= xwmax && *x1 >= xwmin) &&
	(*y1 <= ywmax && *y1 >= ywmin) )
   {
      t = *x1;
      *x1 = *x2;
      *x2 = t;

      t = *y1;
      *y1 = *y2;
      *y2 = t;

      for ( k = 0; k < 4; k++ )
      {
	 t = c1[k];
	 c1[k] = c2[k];
	 c2[k] = t;
      }
   }
}

/* FILE NAME : "main.c" - Main Program */

# include 
# include 
# include 
# include 
# include 
# include 
# include 
# include 

# define on 1
# define off 0
# define true 1
# define false 0

struct link
{
 int xpos,ypos,pcol;
 struct link *next;
};

struct link *head=NULL,*new;

int prevopt,option,color,pattern,patopt;
int xwmin,xwmax,ywmin,ywmax;
int x,y,button;
char filename[8],style[20];

union REGS in,out;

/* include files */

# include "e:\turboc\cglab\2dexam\proto.c"
# include "e:\turboc\cglab\2dexam\point.c"
# include "e:\turboc\cglab\2dexam\bres_lin.c"
# include "e:\turboc\cglab\2dexam\screen.c"
# include "e:\turboc\cglab\2dexam\option.c"
# include "e:\turboc\cglab\2dexam\circle.c"
# include "e:\turboc\cglab\2dexam\rect.c"
# include "e:\turboc\cglab\2dexam\clip.c"
# include "e:\turboc\cglab\2dexam\shapes.c"
# include "e:\turboc\cglab\2dexam\carspi.c"
# include "e:\turboc\cglab\2dexam\flood.c"
# include "e:\turboc\cglab\2dexam\erase.c"
# include "e:\turboc\cglab\2dexam\trans.c"
# include "e:\turboc\cglab\2dexam\fileopt.c"
# include "e:\turboc\cglab\2dexam\ellipse.c"
# include "e:\turboc\cglab\2dexam\mouse.c"
# include "e:\turboc\cglab\2dexam\liclip.c"
# include "e:\turboc\cglab\2dexam\help.c"

 void main()
 {
  int i,x1,y1;
  int gd=DETECT,gm;
  char temp1[4],temp2[4];

  fflush(stdin);
  initgraph(&gd,&gm,"e:\\turboc");

  cleardevice();		    /* Clears the graphics screen  */
  clearviewport();		    /* Clears the current viewport */
  screen();
  restrictmouseptr(10,20,620,465);
  showcursor();

  strcpy(filename,"NONAME");
  option=1;
  color=BLACK;
  pattern=off;
  i=0;

  while(1)
  {
   while(i==0)
   {
    do
    {
     getmousepos(&button,&x1,&y1);
     setfillstyle(1,CYAN);
     bar(520,430,630,460);
     outtextxy(515,445,"X = ");               /* Displays the X & Y co- */
     outtextxy(540,445,itoa(x1,temp1,10));    /* ordinates as the mouse */
     outtextxy(555,445," ,Y = ");	      /* position changes.      */
     outtextxy(594,445,itoa(y1,temp2,10));
     delay(10);
     getmousepos(&button,&x,&y);
    }                           /* when mouse clicked but not released */
    while(button != 1);
				   /* status  clicked  -> 0       */
				   /*         released -> 1       */
    i=get_option_or_color(x,y);
   } 			   /* End Inner While loop        */
			   /* Mouse clicked within window */
   switch(option)
   {
    case 0: /* exit  */
    {
     question();
     closegraph();
     exit(1);
     break;
    }
    case 1: /* point - this is selected as default */
    {
     drawpoint(x,y,color);
     break;
    }
    case 2:  /* line */
    {
     drawline(x,y,color);
     break;
    }
    case 3:  /* circle */
    {
     drawcircle(x,y,color);
     break;
    }
    case 4:  /* ellipse */
    {
     drawellipse(x,y,color);
     break;
    }
    case 5:  /* rectangle */
    {
     drawrect(x,y,color);
     break;
    }
    case 6:  /* floodfill */
    {
     fldfill(x,y,color);
     break;
    }
    case 7:  /* cardiod */
    {
     drawcardiod(x,y,color);
     break;
    }
    case 8:  /* spiral */
    {
     drawspiral(x,y,color);
     break;
    }
    case 9:  /* inside clip */
    {
     inclip(x,y,color);
     break;
    }
    case 10:  /* outside clip */
    {
     outclip(x,y,color);
     break;
    }
    case 11:  /* writing character */
    {
     wrtstr(x,y,color);
     break;
    }
    case 12:  /* erase */
    {
     erase(x,y);
     break;
    }
    case 13: /* help */
    {
     help();
     break;
    }
    case 14: /* About Screen */
    {
     about();
     break;
    }
    case 22:
    {
     saveas();
     break;
    }
    case 23:
    {
     load();
     break;
    }
    case 24:
    {
     save();
     break;
    }
    case 25:
    {
     newfile();
     screen();
     break;
    }
    case 26:
    {
     translate(x,y,color);
     break;
    }
    case 27:
    {
     rotate(x,y,color);
     break;
    }
    case 28:
    {
     scal(x,y,color);
     break;
    }
    case 30:
    {
     clear();
     break;
    }
   }				 /* End Switch Construct  */
   i=0;
  }
 closegraph();				 /* End outer While loop  */
 }				 /* End Main		  */

/* FILE NAME : "mouse.c" */

showcursor()	/*    Shows back the cursor.*/
{
 in.x.ax=1;
 int86(0x33,&in,&out);
 return 1;
}

hidecursor()	/*    Hides the cursor.	    */
{
 in.x.ax=2;
 int86(0x33,&in,&out);
 return 1;
}

/* Gives mouse pointer position on screen & mouse button status.*/

getmousepos(int *button,int *x,int *y)
{
 in.x.ax=3;
 int86(0x33,&in,&out);
 *button = out.x.bx;
 *x=out.x.cx;
 *y=out.x.dx;
 return 1;
}

/* Sets horizontal & vertical limits for mouse pointers. */

restrictmouseptr(int x1,int y1,int x2,int y2)
{
 in.x.ax=7;
 in.x.cx=x1;
 in.x.dx=x2;
 int86(0x33,&in,&out);

 in.x.ax=8;
 in.x.cx=y1;
 in.x.dx=y2;
 int86(0x33,&in,&out);
 return 1;
}

/* FILE NAME : "option.c" */
/* Select options from screen options */

int get_option_or_color(int x,int y)
{
 union REGS in,out;
 int i,j;

 if( between(x,y,70,40,620,400) )
 {
  return 1;
 }
 if( between(x,y,550,20,620,40) )
 {
  option=0;
  return 1;               /* EXIT         */
 }
			  /* Draw options */
 if( between(x,y,10,40,100,400) )  /* left & right options */
 {
  if( between(x,y,10,40,40,70) )
  {
   option=1;
   return 0;
  }
  if( between(x,y,40,40,70,70) )
  {
   option=2;
   return 0;
  }
  if( between(x,y,10,70,40,100) )
  {
   option=3;
   return 0;
  }
  if( between(x,y,40,70,70,100) )
  {
   option=4;
   return 0;
  }
  if( between(x,y,10,100,40,130) )
  {
   option=5;
   return 0;
  }
  if( between(x,y,40,100,70,130) )
  {
   option=6;
   return 0;
  }
  if( between(x,y,10,130,40,160) )
  {
   option=7;
   return 0;
  }
  if( between(x,y,40,130,70,160) )
  {
   option=8;
   return 0;
  }
  if( between(x,y,10,160,40,190) )
  {
   option=9;
   return 0;
  }
  if( between(x,y,40,160,70,190) )
  {
   option=10;
   return 0;
  }
  if( between(x,y,10,190,40,220) )
  {
   option=11;
   return 0;
  }
  if( between(x,y,40,190,70,220) )
  {
   option=12;
   return 0;
  }
  if( between(x,y,10,250,70,290) )
  {
   option=26;
   return 0;
  }
  if( between(x,y,10,290,70,330) )
  {
   option=27;
   return 0;
  }
  if( between(x,y,10,330,70,370) )
  {
   option=28;
   return 0;
  }          	 	      /*  tr,rot,scl    */
 }
			      /* Colour options */
 if(between(x,y,115,410,350,430))
 {
  j = 115;
  for (i=0;i<8;i++)
  {
   if (between(x,y,j,410,j+25,430))
   {
    setfillstyle(SOLID_FILL,i);
    bar(31,421,79,449);
    color = i;
    if(pattern==on)
    {
     setfillpattern(style,color);
     bar(588,418,609,451);
    }
   }
   j+=30;
  }
 }
 else if (between(x,y,115,440,350,460))
 {
  j = 115;
  for (i=15;i>7;i--)
  {
   if (between(x,y,j,440,j+25,460))
   {
    setfillstyle(SOLID_FILL,i);
    bar(31,421,79,449);
    color = i;
    if(pattern==on)
    {
     setfillpattern(style,color);
     bar(588,418,609,451);
    }
   }
   j += 30;
  }
 }
			      /* File  options */
 if( between(x,y,70,20,600,40) )
 {
  if( between(x,y,70,20,130,40) )
  {
   prevopt=option;
   option=25;
   return 1;
  }
  if( between(x,y,130,20,190,40) )
  {
   prevopt=option;
   option=23;
   return 1;
  }
  if( between(x,y,190,20,250,40) )
  {
   prevopt=option;
   option=24;
   return 1;
  }
  if( between(x,y,250,20,330,40) )
  {
   prevopt=option;
   option=22;
   return 1;
  }
  if(between(x,y,330,20,390,40))
  {
   option=30;
   return 1;
  }
 }
 if(between(x,y,10,220,70,250))		/* About Screen */
 {
  option = 14;
  return 1;
 }

 if(between(x,y,10,370,70,400))		/* Help Screen  */
 {
  option = 13;
  return 1;
 }

 return 0;
}

int between(x,y,x1,y1,x2,y2)
{
 if( (x>=x1) && (x<=x2) && (y>=y1) && (y<=y2) )
	 return 1;
 else
	 return 0;
}

/* FILE NAME : "point.c" */

drawpoint(int x1,int y1,int color)
{				/* Draw continous point or free hand */
 setcolor(color);
 putpixel(x1,y1,color);
 hidecursor();
 do
 {
  getmousepos(&button,&x,&y);
  if( between(x,y,70,40,620,400) )
  {
   line(x1,y1,x,y);
   x1=x;
   y1=y;
  }
 } while(button == 1);
 showcursor();
 return 0;
}

wrtstr(int x1,int y1,int color)   /* To Write Text on the scren */
{
 int i=0,l=0;
 char namex[100],ch[1];

 setcolor(color);
 hidecursor();
 while(l==0)
 {
  moveto(x1,y1);
  if( between(x1,y1,110,50,610,390) )
  {
   namex[i]=getch();
   sprintf(ch,"%c",namex[i]);
   if(namex[i]=='\n' || namex[i]=='\r')
   {
    namex[i]='\0';
    break;
   }
   outtext(ch);
   i++;
   x1+=10;
  }
  else
  l=1;
 }
 showcursor();
 return 1;
}

/* FILE NAME : "proto.c" */
/* Specifies the functions prototype used */

   between(int,int,int,int,int,int);
   showcursor(void);
   wrtstr(int,int,int);
   del_bres_line(int);
   bres_line(int,int,int,int,int);
   slope1(int,int,int,int,int,int,double,int,int);
   slope2(int,int,int,int,int,int,double,int,int);
   cardiod(int,int,int,int);
   spiral(int,int,int,int);
   bres_circle(int,int,int,int);
   void getpattern(void);
   draw_circle(int,int,int,int);
   plot_cir_pt(int,int,int,int,int);
   draw_spiral(int,int,int,int);
   plot_ellipse_points(int,int,int,int,int);
   save(void);
   saveas(void);
   clear(void);
   load(void);
   newfile(void);
   question();
   screen(void);
   void about();
   void get_date();
   void insert(int,int);
   void ffill(int,int,int,int);
   void encode(int,int,int*);
   void clip_line(int,int,int,int,int);
   int accept(int*,int*);
   int reject(int*,int*);
   void swap_if_needed(int*,int*,int*,int*,int*,int*);
   void display_help();
   void help();

/* FILE NAME : "rect.c" */

/* Draws rectangle from x1,y1[left top]  to x2,y2[right bottom] */

drawrect(int x1,int y1,int color)
{
 int x2,y2,xprev,yprev;

 hidecursor();
 xprev=x1;
 yprev=y1;
 do
 {
  setcolor(color);
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2||yprev!=y2)
  {
   setcolor(WHITE);
   del_bres_line(1);
   bres_line(x1,y1,x2,y1,color);
   bres_line(x2,y1,x2,y2,color);
   bres_line(x2,y2,x1,y2,color);
   bres_line(x1,y2,x1,y1,color);
  }
  xprev=x2;yprev=y2;
 } while(out.x.bx==1);
 del_bres_line(0);
 if(pattern==on)
 {
  if( between(x2,y2,70,40,620,400) )
  {
   getpattern();
   setfillpattern(style,color);
   bar(x1,y1,x2,y2);
  }
 }
 showcursor();
 return 1;
}

/* selects the patterns */

void   getpattern()
{
 if(patopt==1)
 {
  strcpy(style,"EMPTY_FILL");
  return;
 }
 if(patopt==2)
 {
  strcpy(style,"SOLID_FILL");
  return;
 }
 if(patopt==3)
 {
  strcpy(style,"LINE_FILL");
  return;
 }
 if(patopt==4)
 {
  strcpy(style,"LTSLASH_FILL");
  return;
 }
 if(patopt==5)
 {
  strcpy(style,"SLASH_FILL");
  return;
 }
 if(patopt==6)
 {
  strcpy(style,"HATCH_FILL");
  return;
 }
 if(patopt==7)
 {
  strcpy(style,"INTERLEAVE_FILL");
  return;
 }
 if(patopt==8)
 {
  strcpy(style,"WIDE_DOT_FILL");
  return;
 }
}

/* FILE NAME : "screen.c" */
/* screen design */

screen()
{
 int i,j;

 setfillstyle(1,CYAN);
 bar(0,0,640,480);

 setfillstyle(1,LIGHTGRAY);

 /* left options */
 bar(10,40,40,70);
 bar(10,70,40,100);
 bar(10,100,40,130);
 bar(10,130,40,160);
 bar(10,160,40,190);
 bar(10,190,40,220);
	/* put options */
 setcolor(BLUE);
 putpixel(15,45,BLUE);
 putpixel(20,50,BLUE);
 putpixel(25,55,BLUE);
 putpixel(30,60,BLUE);
 circle(25,85,8);
 rectangle(15,110,35,125);
 cardiod(25,145,8,BLUE);
 setcolor(BLUE);
 rectangle(15,170,35,185);
 /* setcolor(RED); */
 outtextxy(18,175,"IC ");          /* co-ord altered  */
				 /* IN->interior clip */
 setcolor(BLUE);
 outtextxy(10,205," TXT ");
	/* outtextxy(15,290,"lclip"); */
	/* right options */
 bar(40,40,70,70);
 bar(40,70,70,100);
 bar(40,100,70,130);
 bar(40,130,70,160);
 bar(40,160,70,190);
 bar(40,190,70,220);

	/* lines b/w left & right HORIZ,VERTICAL LINES  */
 setcolor(WHITE);
 line(40,40,40,220);
 line(70,40,70,220);
 line(10,40,10,220);
 line(10,40,70,40);
 line(10,70,70,70);
 line(10,100,70,100);
 line(10,130,70,130);
 line(10,160,70,160);
 line(10,190,70,190);
 line(10,220,70,220);
 setcolor(BLACK);
 line(70,40,70,220);
 line(10,220,70,220);
 /* put options */
 /* to write the trans ,rot and  */

 bar(10,250,70,370);
 outtextxy(25,265,"Tran");
 outtextxy(25,305,"Rot ");
 outtextxy(25,345,"Scal");
 setcolor(WHITE);
 line(10,250,10,370);
 line(10,250,70,250);
 line(10,290,70,290);
 line(10,330,70,330);
 setcolor(BLACK);
 line(70,250,70,370);
 line(10,370,70,370);

 setcolor(BLUE);
 line(50,45,65,65);
 ellipse(55,80,0,360,10,5);
 rectangle(50,115,65,125);   /* flood fill dig */
 line(58,120,58,110);
 line(58,110,45,110);
 line(45,110,45,120);
 spiral(55,145,15,BLUE);
 rectangle(45,170,65,185);
 outtextxy(50,175,"EC");    	  /* OUT -> exterior clip */
 outtextxy(43,197,"Era-");        /* Eraser		  */
 outtextxy(45,205,"ser");

 setfillstyle(1,GREEN);
 bar(10,370,70,400);
 outtextxy(25,380,"Help");
 setcolor(WHITE);
 line(10,370,70,370);
 line(10,370,10,400);
 setcolor(BLACK);
 line(10,400,70,400);
 line(70,400,70,370);


 /* colour options */
 setcolor(BLACK);
 j = 115;
 for (i=0;i<8;i++)
 {
  rectangle(j,410,j+25,430);
  setfillstyle(SOLID_FILL,i);
  floodfill(j+10,420,0);
  j+=30;
 }
 j = 115;
 for (i=15;i>7;i--)
 {
  rectangle(j,440,j+25,460);
  setfillstyle(SOLID_FILL,i);
  floodfill(j+10,450,0);
  j+=30;
 }
 rectangle(20,410,90,460);
 setcolor(RED);
 rectangle(30,420,80,450);
 setfillstyle(SOLID_FILL,BLACK);
 bar(31,421,79,449);
 setcolor(WHITE);
 line(105,405,360,405);
 line(105,405,105,464);
 setcolor(DARKGRAY);
 line(360,405,360,464);
 line(105,464,360,464);

 /* file & tran options */
 setfillstyle(1,BLUE);
 bar(0,0,640,39);
 setfillstyle(1,LIGHTGRAY);
 bar(0,20,640,39);

	/*  lines b/w file options  */
  /* write the menus */
 setcolor(BLUE);
 outtextxy(80,25,"New");
 outtextxy(140,25,"Load");
 outtextxy(200,25,"Save");
 outtextxy(260,25,"Save As ");
 outtextxy(340,25,"Clear");
 outtextxy(570,25,"Exit");

 setcolor(BLUE);
 outtextxy(420,25,"NONAME");

 setcolor(BLUE);
 line(70,20,70,39);
 line(130,20,130,39);
 line(190,20,190,39);
 line(250,20,250,39);
 line(330,20,330,39);
 line(390,20,390,39);
 line(560,20,560,39);
 line(0,39,639,39);

 /* main bar */
 setcolor(BLACK);
 rectangle(70,40,620,400);
 setfillstyle(1,WHITE);
 bar(71,41,619,399);

 setfillstyle(1,GREEN);
 bar(10,221,69,249);
 outtextxy(20,232,"About");
 setcolor(WHITE);
 line(10,220,70,220);
 line(10,220,10,250);

 setcolor(YELLOW);
 outtextxy(280,10,"GRAPHICS EDITOR");

 get_date();

 return 1;
}

void about()
{
 union REGS in,out;
 char temp;
 FILE *fp1;
 int i,j,col;

 hidecursor();

 fp1=fopen("tra1","w");
 for(i=200;i<=500;i++)
 {
  for(j=100;j<=300;j++)
  {
   col=getpixel(i,j);
   fputc(col,fp1);
  }
 }
 fclose(fp1);

 setfillstyle(1,LIGHTGRAY);
 bar(200,100,500,300);
 rectangle(200,100,500,300);
 rectangle(205,105,495,295);
 setcolor(RED);
 outtextxy(333,110,"ABOUT");
 outtextxy(333,120,"=====");
 setcolor(BLUE);
 outtextxy(210,130,"Graphics Editor");
 outtextxy(210,140,"-------- ------");
 outtextxy(210,180,"Designed By:");
 setcolor(BLACK);
 outtextxy(210,200,"Madhu Sudan Rao G.K & ");
 outtextxy(230,220,"97QEEC3018");
 outtextxy(370,200," Srivathsa M.P");
 outtextxy(395,220,"97QEEC3039");
 setcolor(BLACK);
 outtextxy(210,240,"VII Sem Computer Science & Engg.");
 outtextxy(250,260,"S . R . S . I . T");
 setcolor(BLUE);
 outtextxy(374,280,"");
 setcolor(BLACK);
 temp=getche();

 fp1=fopen("tra1","r");
 for(i=200;i<=500;i++)
 {
  for(j=100;j<=300;j++)
  {
   col=fgetc(fp1);
   putpixel(i,j,col);
  }
 }
 fclose(fp1);

 showcursor();
}

void get_date()
{
 char s[10];
 int j;
 union REGS in,ot;

 in.h.ah=0x2a;
 intdos(&in,&ot);
 setcolor(WHITE);
 setfillstyle(SOLID_FILL,BLUE);
 settextstyle(0,HORIZ_DIR,1);
 bar(451,0,600,10);
 switch(ot.h.al)
 {
  case 0:
   outtextxy(455,10,"Sunday,");
   break;
  case 1:
   outtextxy(455,10,"Monday,");
   break;
  case 2:
   outtextxy(455,10,"Tuesday,");
   break;
  case 3:
   outtextxy(455,10,"Wednesday,");
   break;
  case 4:
   outtextxy(455,10,"Thursday,");
   break;
  case 5:
   outtextxy(455,10,"Friday,");
   break;
  case 6:
   outtextxy(455,10,"Saturday,");
   break;
 }
 switch(ot.h.dh)
 {
  case 0x01:
   outtextxy(517,10,"January");
   break;
  case 0x02:
   outtextxy(517,10,"February");
   break;
  case 0x03:
   outtextxy(517,10,"March");
   break;
  case 0x04:
   outtextxy(517,10,"April");
   break;
  case 0x05:
   outtextxy(517,10,"May");
   break;
  case 0x06:
   outtextxy(517,10,"June");
   break;
  case 0x07:
   outtextxy(517,10,"July");
   break;
  case 0x08:
   outtextxy(517,10,"August");
   break;
  case 0x09:
   outtextxy(517,10,"September");
   break;
  case 0x0a:
   outtextxy(517,10,"October");
   break;
  case 0x0b:
   outtextxy(517,10,"November");
   break;
  case 0x0c:
   outtextxy(517,10,"December");
   break;
 }
 itoa(ot.h.dl,s,10);
 if (strlen(s)==1)
 {
  outtextxy(580,10,"0");
  outtextxy(600,10,s);
 }
 else
  outtextxy(580,10,s);
}

/* FILE NAME : "shapes.c" */
/* bres cardiod and spiral */

cardiod(int x,int y,int r,int color)
{
 double th,r1,dt;
 int x1,y1;

 setcolor(color);

 r=r?r:1;
 dt=1.0/r;
 x1 = (x-r) + 2 * r;
 y1 = y;
 th = 0.0;
 x-=r;
 for(;fabs(th) <=2*3.1715 ; th += dt)
 {
  r1=r*(1+cos(th));
  putpixel(x1,y1,color);
  x1=x+r1*cos(th);
  y1=y+r1*sin(th);
 }
 return 1;
}

bres_cardiod(int x,int y,int r,int color)
{
 struct link *new;
 double th,r1,dt;
 int x1,y1,col;

 setcolor(color);
 r=r?r:1;
 dt=1.0/r;
 x1 = (x-r) + 2 * r;
 y1 = y;
 th = 0.0;
 x-=r;
 for(;fabs(th) <=2*3.1715 ; th += dt)
 {
  r1=r*(1+cos(th));
  if( between(x1,y1,100,40,620,400) )
  {
   col=getpixel(x1,y1);
   new=(struct link *)malloc(sizeof(struct link));
   new->xpos=x1;
   new->ypos=y1;
   new->pcol=col;
   new->next=head;
   head=new;
   putpixel(x1,y1,color);
  }
  x1=x+r1*cos(th);
  y1=y+r1*sin(th);
 }			       /* End For construct */
 return 1;
}

spiral(x,y,r,color)
int x,y,r,color;
{
 int ty=y,tr=1,flag=1,sign=1;

 setcolor(color);
 for(;tr<=r; tr+=5,flag=!flag, sign = -sign)
 {
  if (flag)
	arc(x,ty,90,270,tr);
  else
	arc(x,ty,270,90,tr);
  ty += sign*5;
 }
 return 1;
}

/* FILE NAME : "trans.c" */

/* Translate selected portion */

translate(int x1,int y1,int color)
{
 FILE *fp;
 int i,j,x2,y2,x3,y3,xprev,yprev,col,tx,ty,px,py;

 hidecursor();
 xprev=x1;
 yprev=y1;
 do			 /* select from x1,y1 to x2,y2 */
 {
  setcolor(color);
  getmousepos(&button,&x,&y);
  x2=x;
  y2=y;
  if(xprev!=x2||yprev!=y2)
  {
   setcolor(WHITE);
   del_bres_line(1);
   bres_line(x1,y1,x2,y1,color);
   bres_line(x2,y1,x2,y2,color);
   bres_line(x2,y2,x1,y2,color);
   bres_line(x1,y2,x1,y1,color);
  }
  xprev=x2;yprev=y2;
 } while(out.x.bx==1);
 del_bres_line(0);
 /* x1,y1 as lefttop x2,y2 as rightbottom */
 if(x2<100)  x2=100;
 if(x2>620)  x2=620;
 if(y2<40)  y2=40;
 if(y2>400)  y2=400;
 if(x1>x2)
 {
  xprev=x1;
  x1=x2;
  x2=xprev;
 }
 if(y1>y2)
 {
  yprev=y1;
  y1=y2;
  y2=yprev;
 }
 fp=fopen("tra.c","w");
 for(i=x1+1;iy2;j++)
  {
   col=getpixel(i,j);
   fputc(col,fp);
  }
 }
 fclose(fp);
 showcursor();
 do
 {
  getmousepos(&button,&x,&y);
 } while(button != 1);
/* put selected option from x3,y3 */
 x3=x;
 y3=y;
 tx=x3-x1;
 ty=y3-y1;
 hidecursor();
 for(i=x1;i<=x2;i++)
    for(j=y1;j<=y2;j++)
       putpixel(i,j,WHITE);
 fp=fopen("tra.c","r");
 for(i=x1+1;iy2;j++)
  {
   col=fgetc(fp);
   px=i+tx;
   py=j+ty;
   if( between(px,py,100,40,620,400) )
   {
    putpixel(px,py,col);
   }
  }
 }
 fclose(fp);
 showcursor();
 return 1;
}

/* rotate the selected portion by 90 degres */

rotate(int x1,int y1,int color)
{
 FILE *fp;
 int i,j,x2,y2,xprev,yprev,col,xr,yr,px,py;

 hidecursor();
 xprev=x1;
 yprev=y1;
 do
 {
 setcolor(color);
 getmousepos(&button,&x,&y);
 x2=x;
 y2=y;
 if(xprev!=x2||yprev!=y2)
 {
 setcolor(WHITE);
 del_bres_line(1);

 bres_line(x1,y1,x2,y1,color);
 bres_line(x2,y1,x2,y2,color);
 bres_line(x2,y2,x1,y2,color);
 bres_line(x1,y2,x1,y1,color);
 }
 xprev=x2;yprev=y2;
 }while(out.x.bx==1);

 del_bres_line(0);

 if(x2<100)
    x2=100;
 if(x2>620)
    x2=620;
 if(y2<40)
    y2=40;
 if(y2>400)
    y2=400;

 if(x1>x2)
    {
      xprev=x1;
      x1=x2;
      x2=xprev;
    }
 if(y1>y2)
    {
      yprev=y1;
      y1=y2;
      y2=yprev;
    }

fp=fopen("tra.c","w");

 for(i=x1+1;iy2;j++)
	  {
	     col=getpixel(i,j);
	     fputc(col,fp);
	  }
    }
   fclose(fp);

 for(i=x1;i<=x2;i++)
    {
       for(j=y1;j<=y2;j++)
	  {
	    putpixel(i,j,WHITE);
	  }
    }

   xr=(x2-x1)/2+x1;
   yr=(y2-y1)/2+y1;

   fp=fopen("tra.c","r");

      for(i=x1+1;iy2;j++)
	      {
		 col=fgetc(fp);
		 px=xr-(j-yr);
		 py=yr+(i-xr);
		 if( between(px,py,100,40,620,400) )
		 {
		 putpixel(px,py,col);
		 }
	      }
	 }
      fclose(fp);
 showcursor();
 return 1;
 }

 /* scale the selected portion with sx & sy as scaling factors  */

scal(int x1,int y1,int color)
{
 FILE *fp;
 int i,j,x2,y2,x3,y3,x4,y4,xprev,yprev,col,px,py,xf,yf,k,l;
 float sx,sy,tx,ty;
 char namex[4],namey[4],ch[1];

 hidecursor();
 xprev=x1;
 yprev=y1;
 do
 {
 setcolor(color);
 getmousepos(&button,&x,&y);
 x2=x;
 y2=y;
 if(xprev!=x2||yprev!=y2)
 {
 setcolor(WHITE);
 del_bres_line(1);
 bres_line(x1,y1,x2,y1,color);
 bres_line(x2,y1,x2,y2,color);
 bres_line(x2,y2,x1,y2,color);
 bres_line(x1,y2,x1,y1,color);
 }
 xprev=x2;yprev=y2;
 }while(out.x.bx==1);
 del_bres_line(0);
 if(x2<100)
    x2=100;
 if(x2>620)
    x2=620;
 if(y2<40)
    y2=40;
 if(y2>400)
    y2=400;
 if(x1>x2)
    {
      xprev=x1;
      x1=x2;
      x2=xprev;
    }
 if(y1>y2)
    {
      yprev=y1;
      y1=y2;
      y2=yprev;
    }
fp=fopen("tra.c","w");
 for(i=x1+1;iy2;j++)
	  {
	     col=getpixel(i,j);
	     fputc(col,fp);
	  }
    }
   fclose(fp);
	fp=fopen("exa.c","w");
	for(i=250;i<=430;i++)
	   {
	      for(j=220;j<=300;j++)
		 {
		    col=getpixel(i,j);
		    fputc(col,fp);
		 }
	   }
	fclose(fp);
	     setfillstyle(1,YELLOW);
	     bar(250,220,430,300);
	     setcolor(BLACK);
	     outtextxy(265,225,"Enter Sx & Sy values");
	     setfillstyle(1,GREEN);
	     bar(275,250,400,280);
	     moveto(278,260);
	     i=0;
	     /* take in the place */
		while(1)
		{
			namex[i]=getch();
			sprintf(ch,"%c",namex[i]);
			if(isspace(namex[i]))
			{
				namex[i]='\0';
				break;
			}
			else
			    outtext(ch);
			i++;
		}
		sx=atof(namex);
		strcpy(ch," ");
		outtext(ch);
	 i=0;
		while(1)
		{
			namey[i]=getch();
			sprintf(ch,"%c",namey[i]);
			if(isspace(namey[i]))
			{
				namey[i]='\0';
				break;
			}
			else
			   outtext(ch);
			i++;

		}
		sy=atof(namey);
	fp=fopen("exa.c","r");
	for(i=250;i<=430;i++)
	   {
	      for(j=220;j<=300;j++)
		 {
		    col=fgetc(fp);
		    putpixel(i,j,col);
		 }
	   }
	fclose(fp);
 for(i=x1;i<=x2;i++)
    {
       for(j=y1;j<=y2;j++)
	  {
	    putpixel(i,j,WHITE);
	  }
    }
   xf=(x2-x1)/2+x1;
   yf=(y2-y1)/2+y1;
   tx=xf*(float)(1-sx);
   ty=yf*(float)(1-sy);
   x3=(float)x1*sx+tx;
   y3=(float)y1*sy+ty;
   x4=(float)x2*sx+tx;
   y4=(float)y2*sy+ty;
   for(i=x3+1;iy4;j++)
	  {
	    if( between(i,j,100,40,620,400) )
	       {
		 putpixel(i,j,WHITE);
	       }
	  }
    }
   fp=fopen("tra.c","r");
      for(i=x1+1;iy2;j++)
	      {
		 col=fgetc(fp);
		 px=(float)i*sx+tx;
		 py=(float)j*sy+ty;

/*		 if( between(px,py,100,40,620,400) )
		   {
		     if(col!=WHITE)
			putpixel(px,py,col);
		   }*/

		 for(k=0;ksy;l++)
		       {
			 if( between(px+k,py+l,100,40,620,400) && (col!=WHITE) )
			    putpixel(px+k,py+l,col);
		       }
		   }
	      }
	   }
 fclose(fp);
 showcursor();
 return 1;
}

Screen Editor
Graphics Editor
DBMS
Source Code Metrics Tool

[CodeEverywhere]