Computer Graphics System Project Report.
Computer Graphics System Project Report.
INTERNSHIP REPORT
ON
COMPUTER GRAPHICS SYSTEM PROJECT
REPORT
BY
KAMAL ACHARYA
(Tribhuvan University)
Date: 2021/11/10
1|Page
1. INTRODUCTION
1.1 Overview
2|Page
Chapter 1 Introduction
1.2 About C:
1.3.1. Simple
1.3.3 Robust
1.3.4 Rich set of built in programs and operations
1.3.5 Programs written are efficient and fast.
1.3.6 Highly portable.
1.3.7 Ability to extend itself.
3|Page
Chapter 1 Introduction
(BGI). All interfaces to the SRGP and SPHIGS graphics package are
defined in C/C++.
----------->x-axis
|
|
|
V
y-axis
4|Page
2. REQUIREMENT SPECIFICATIONS
Scope: This document describes the functional requirements for the graphics
package to run efficiently and provide optimum results. It is meant for use by
the developers and will also be used for further maintaining and upgrading the
various components of the requirements in future. Then, it will be reflected as
an addition to this document.
2.3.6. 32 MB RAM.
5|Page
Chapter 2 Requirement Specification
2.4.12. Segmentation
We use the following functions to interface the mouse with the user
screen.
void showmouse( )
void hidemouse( )
Int getmousepos( )
This is a function which gets the current mouse pointer on the screen.
It is called using service 03h. This returns mouse button status to BX and x-
coordinate to CX and y-coordinate to DX . It uses interrupt 33h.
7|Page
Chapter 3 System Design
int restrictmouse( )
Line: We can draw a line in any of the coordinates using Bresenham’s line
algorithm. Based on the input values given by the user, slopes are calculated
and corresponding pixels are called using putpixel( ) built-in function. We also
ensure that the line lies within the user area.
Rectangle: We can draw a rectangle using service 03h, which returns current
x and y coordinates. Then, we call line function 4 times to draw a rectangle
and ensure that it is within user area as long as left button is pressed.
Circle: We can draw a circle using Bresenham’s circle algorithm. The initial
left click position of the mouse is taken as the centre of the circle. The radius
is given by service 03h which returns x and y coordinates when the left button
is released. We ensure that it is within the user area.
Spiral: We can draw a spiral using service 02h. It makes use of contents of
CX and DX registers to know the centre and maximum radius. We ensure that
it is within the user area.
Wheel: When this icon is clicked, a rotating wheel is displayed within the
user screen, until right button of mouse is clicked.
Translate: We can translate a given circle within the user screen. The circle
is translated to the position where the mouse is clicked.
New file: We can create a new file by filling the entire user area with white
colour and naming it as untitled.bmp.
Load file: We can load a saved file by using file operations. If the file is not
present, error is displayed.
Clear: This option clears the screen and fills the user area with white colour.
Colours: We can select a colour and perform any of the operations using that
colour.
Fill colour: This option fills the entire user screen within the selected colour.
9|Page
Chapter 3 System Design
The construction techniques are one of the most important ingredients of a graphics
editor. A superior approach to the construction technique is the rubber-band
technique, which is used in this editor. The state diagram for rubber-band line
drawing is show below.
10 | P a g e
Chapter 4 Source Code
Source Code
/* GLOBAL DECLARATION
*/
#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
void wel();
int initmouse();
void startmouse(int x,int y);
void showmouse();
void hidemouse();
void getxy();
void disp_coord();
void restrictmouse(int,int,int,int);
void tme();
void ClearStatus();
void ShowStatus(char*);
void beep();
char* readline(char*);
void animate();
//void loading();
void save();
void load();
void clear();
void exchange(int*,int*);
11 | P a g e
Chapter 4 Source Code
//void erase();
void drawtext();
void putback();
void set(int x,int y);
void putcircle(int,int,int,int);
void bcircle( int,int,int);
void setpixel(int,int,int);
void bline(int,int,int,int);
void brectangle(int,int,int,int);
void spiral(int,int,int,int,int);
void plotpnts(int,int,int,int,int,int);
void bellipse(int,int,int,int);
void myw(int,int,float);
void Wheel();
void myl(int,int,float);
void rotate_line();
void rubberband();
void scale();
void rotate();
void translate();
void
CohenSutherlandLine(int,int,int,int,int,int,int,int);
void lineclipping();
void clearin();
void clearout();
void seg();
12 | P a g e
Chapter 4 Source Code
void dispfile();
void frame();
int check_mouse_on(int,int,int,int);
void check_if_exit();
int check_if_color();
int check_if_button_pressed();
void tools();
void drawrectangle();
int a,b,c,d;
int Current_Color=BLACK;
int Current_Pattern=EMPTY_FILL;
struct
{
int x,y;
int c;
}r[MAX_PIXEL];
struct Node
{
int x,y;
struct Node* next;
};
13 | P a g e
Chapter 4 Source Code
void wel()
{
14 | P a g e
Chapter 4 Source Code
outtextxy(430,432,"chinmaya \n amar");
settextstyle(SMALL_FONT,HORIZ_DIR,5);
icons(MAX_X-208,MAX_Y+25,MAX_X-2,MAX_Y+65,1);
icons(MIN_X,MAX_Y+6,MAX_X,MAX_Y+18,0);
15 | P a g e
Chapter 4 Source Code
16 | P a g e
Chapter 4 Source Code
17 | P a g e
Chapter 4 Source Code
settextstyle(1,0,1);
outtextxy(x+8,y+10,"BZ");
}
}
void scale_icon(int x1, int y1)// used to display
scaling picture
{
setcolor(0);
rectangle(x1+4,y1+4,x1+21,y1+18);
rectangle(x1+7,y1+7,x1+17,y1+12);
18 | P a g e
Chapter 4 Source Code
setfillstyle(1,RED);
floodfill(x1+8,y1+8,BLACK);
/* MOUSE FUNCTIONS
*/
int initmouse()
{
regs.x.ax=0;
int86(0x33,®s,®s);
return(regs.x.bx);
}
void showmouse()
{
regs.x.ax=1;
int86(0x33,®s,®s);
}
void getxy()
{
regs.x.ax=3; //get mouse status using 03h
of int 33h
int86(0x33,®s,®s);
prevx=mousex;
prevy=mousey;
if(regs.x.bx&1) //LSB of reg BX
LeftButtonPressed=1;
else
LeftButtonPressed=0;
mousex=regs.x.cx; //(cx,dx)=(x,y)
mousey=regs.x.dx;
if(regs.x.bx&2)
RightButtonPressed=1;
else
RightButtonPressed=0;
}
void hidemouse()
19 | P a g e
Chapter 4 Source Code
{
regs.x.ax=2;
int86(0x33,®s,®s);
}
void tme()
{
char k[3],l[3],m[4]=" : ";
static int hour,minute;
20 | P a g e
Chapter 4 Source Code
regs.h.ah=0x2c;
int86(0x21,®s,®s);
if(hour!=regs.h.ch||minute!=regs.h.cl)
{
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(22,MAX_Y+52,81,MAX_Y+58); //refresh
display
settextstyle(DEFAULT_FONT,HORIZ_DIR,0);//restore
normal font style/size
//setusercharsize(0,0,0,0);
setcolor(BLACK);
sprintf(k,"%d",regs.h.ch);
outtextxy(25,442,k);
outtextxy(40,442,m);
sprintf(l,"%d",regs.h.cl);
outtextxy(62,442,l);
}
hour=regs.h.ch,minute=regs.h.cl;
}
/* FILE OPERATIONS
*/
21 | P a g e
Chapter 4 Source Code
void beep()
{
sound(1000);
delay(75);
nosound();
}
22 | P a g e
Chapter 4 Source Code
}
ch=getch();
}
temp[i]='\0';
ClearStatus();
if(ch==27)
return NULL;
else
{
Line=malloc(strlen(temp)+1);
strcpy(Line,temp);
}
return Line;
}
void animate()
{
int i,j=2;
setfillstyle(SOLID_FILL,BLUE);
for(i=1;i<66;i++)
{
bar(MIN_X+j,MAX_Y+15,MIN_X+j+6,MAX_Y+9);
j+=8;
delay(10);
}
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(MIN_X+2,MAX_Y+16,626,MAX_Y+8);
}
void save()
{
char* name;
FILE* out;
char ch;
int row,col;
char byte;
if(strcmp(filename,"Untitled")==0)
{
name=readline("Save File As : ");
if(name==NULL) return;
}
else
{
name=malloc(strlen(filename)+1);
strcpy(name,filename);
}
out=fopen(name,"w");
if(out==NULL)
{
ShowStatus(" Error Opening File !");
delay(1000);
ClearStatus();
23 | P a g e
Chapter 4 Source Code
return;
}
ShowStatus(" Saving File (Please Wait) ");
animate();
for(row=MIN_Y+2;row<=MAX_Y-2;++row)
{
for(col=MIN_X+2;col<=MAX_X-2;)
{
byte=getpixel(col,row);
byte=byte<<4;
col++;
byte+=getpixel(col,row);
col++;
if(fputc(byte,out)==EOF)
{
ShowStatus("Error Writing FIle ! ");
delay(1000);
ClearStatus();
free(name);
fclose(out);
}
}
}
ClearStatus();
strcpy(filename,name);
dispfile();
free(name);
fclose(out);
saved=1;
}
void load()
{
FILE* in;
char* name;
char ch;
char byte;
int row,col;
int temp;
if(!saved)
{
ShowStatus(" Save Current File ? ");
ch=getch();
if(ch=='y'||ch=='Y')
save();
}
name=readline(" Enter File To Open : ");
if(name==NULL)
return;
in=fopen(name,"r");
if(in==NULL)
24 | P a g e
Chapter 4 Source Code
{
ShowStatus(" Error Opening File ");
delay(1000);
ClearStatus();
return;
}
byte=fgetc(in);// gets a char from a stream
ClearStatus();
ShowStatus("Loading....");
animate();
ClearStatus();
strcpy(filename,name);
dispfile();
for(row=MIN_Y+2;row<=MAX_Y-2;row++)
{
for(col=MIN_X+2;col<=MAX_X-2;)
{
temp=(byte&0xf0)>>4;
putpixel(col,row,temp);
col++;
temp=(byte&0x0f);
putpixel(col,row,temp);
col++;
byte=fgetc(in);
}
}
free(name);
fclose(in);
saved=1;
}
/* ALGORITHMS
*/
void clear()
{
setfillstyle(SOLID_FILL,WHITE);
bar(MIN_X+2,MIN_Y+2,MAX_X-2,MAX_Y-2);
}
25 | P a g e
Chapter 4 Source Code
void putback()
{
int i;
for(i=0;i<t;i++)
{
if(getpixel(r[i].x,r[i].y)!=r[i].c)
putpixel(r[i].x,r[i].y,r[i].c);
}
t=0;
}
26 | P a g e
Chapter 4 Source Code
p+=4*x+6;
else
{
p+=4*(x-y)+10;
y--;
}
x++;
if(x==y)
putcircle(x,y,xc,yc);
}
showmouse();
}
27 | P a g e
Chapter 4 Source Code
}
setpixel(xs,ys,slope);
}
}
28 | P a g e
Chapter 4 Source Code
else
ro=(float)(r1*1.0/r2);
set(xc+x*ro,(int)(yc+y*r));
set(xc-y*ro,(int)(yc+x*r));
set(xc-x*ro,(int)(yc+y*r));
set(xc+y*ro,(int)(yc+x*r));
set(xc-x*ro,(int)(yc-y*r));
set(xc+y*ro,(int)(yc-x*r));
set(xc+x*ro,(int)(yc-y*r));
set(xc-y*ro,(int)(yc-x*r));
}
29 | P a g e
Chapter 4 Source Code
void rotate()
{
char *name;
int x,y,xnew=0,ynew=0;
float tx=0,th=0;
setcolor(Current_Color);
rectangle(MIN_X,MIN_Y,MAX_X,MAX_Y);
ShowStatus("Draw rectangle to rotate");
drawrectangle();
name=readline("Enter the rotational angle along x-
axis: ");
tx=atoi(name);
th= (3.1416 * tx)/180.0;
30 | P a g e
Chapter 4 Source Code
}
void seg()
{
setcolor(BLACK);
rectangle(200,200,400,380);
line(200,200,300,100);
line(300,100,400,200);
rectangle(275,300,325,380);
rectangle(212,225,263,275);
rectangle(337,225,388,275);
line(237,225,237,275);
line(212,250,263,250);
line(362,225,362,275);
line(337,250,388,250);
circle(300,165,25);
setfillstyle(SOLID_FILL,GREEN);
floodfill(210,210,BLACK);
setfillstyle(SOLID_FILL,WHITE);
floodfill(300,165,BLACK);
setfillstyle(SOLID_FILL,BROWN);
floodfill(300,125,BLACK);
/*int i,j=0,k=0;
//delay(1000);
settextstyle(3,0,3);
setcolor(RED);
outtextxy(250,350,"DEMONSTRATION OF SEGMENTATION");
setcolor(0);
//MONITOR
rectangle(140,110,220,210);
rectangle(130,100,230,220);
line(165,220,145,250);
31 | P a g e
Chapter 4 Source Code
line(195,220,215,250);
ellipse(180,250,130,50,45,15);
line(120,90,120,210);
line(120,210,130,220);
line(120,90,220,90);
line(220,90,230,100);
setfillstyle(1,7);
floodfill(131,101,0);
setfillstyle(1,7);
floodfill(121,91,0);
line(120,90,130,100);
setfillstyle(1,7);
floodfill(166,222,0);
getch();
//delay(1100);
//CABINET
setfillstyle(1,7);
bar3d(350,90,280,250,7,1);
setfillstyle(1,8);
floodfill(345,87,0);
setfillstyle(1,8);
floodfill(353,235,0);
getch();
//delay(1000);
//CD ROM
setcolor(0);
line(280,100,350,100);
line(280,110,350,110);
setfillstyle(1,8);
floodfill(281,101,0);
setfillstyle(1,GREEN);
fillellipse(340,105,4,4);
ellipse(340,105,100,90,5,5);
//delay(1000);
getch();
//FLOPPY
setfillstyle(1,7);
floodfill(291,151,0);
rectangle(290,150,335,158);
setfillstyle(1,8);
floodfill(291,151,0);
//delay(1000);
getch();
//RESET BUTTON
setfillstyle(1,RED);
fillellipse(310,180,4,4);
ellipse(310,180,100,90,3,5);
32 | P a g e
Chapter 4 Source Code
//delay(1000);
getch();
//POWER BUTTON
setfillstyle(1,YELLOW);
fillellipse(310,200,4,4);
ellipse(310,200,100,90,7,8);
circle(310,200,8);
//MONITOR CONNECTOR
//delay(1000);
getch();
setcolor(0);
line(230,210,250,200);
line(231,211,251,201);
line(232,212,252,202);
line(250,200,280,180);
line(251,201,280,181);
line(252,202,280,182);
setcolor(0);
//delay(1000);
getch();
//KEYBOAD
k=0;
for(i=0;i<7;i++)
{
line(106+k,280+j,258+k,280+j);
j+=8;
k+=3;
j=0;
for(i=0;i<20;i++)
{
line(106+j,280,125+j,328);
j+=8;
}
line(106,280,106,290);
line(106,290,125,338);
line(277,328,277,338);
line(125,338,277,338);
setfillstyle(1,7);
floodfill(126,329,0);
line(125,328,125,338);
//delay(1000);
33 | P a g e
Chapter 4 Source Code
getch();
//KEYBOARD CONNECTOR
line(210,280,280,230);
line(211,281,281,231);
line(250,250,280,230);
//delay(1000);
getch();
//MOUSE
setfillstyle(1,7);
fillellipse(300,300,9,15);
ellipse(300,300,100,90,10,18);
//delay(1000);
getch();
line(300,285,270,260);
line(301,286,271,261);
line(302,287,272,262);
line(270,260,245,250);
line(271,261,246,251);
line(272,262,247,252);
line(245,250,280,205);
line(246,251,280,206);
line(247,252,280,207);
//display on screen
settextstyle(3,0,1);
setcolor(0);
outtextxy(142,150,"CG PROJECT");
outtextxy(142,165,"By:uub1970");
//outtextxy(165,175,"Usha");
for(i=0;i<=5;i++)
{ delay(1000);
if(i%2==0)
{
setfillstyle(1,11);
floodfill(141,111,0);
}
else
{
setfillstyle(1,14);
floodfill(141,111,0);
}
}*/
}
void mul(float a[10][10],float d[10][10])
{
34 | P a g e
Chapter 4 Source Code
char k1[4],l1[4],m1[4];
int i,j,k,xc,yc,zc;
float c[10][10];
for(i=0;i<1;i++)
{
for(j=0;j<4;j++)
{
c[i][j]=0;
for(k=0;k<4;k++)
c[i][j]+=a[i][k]*d[k][j];
}
}
xc=c[0][0],yc=c[0][1],zc=c[0][2];
outtextxy(570,100,"x=");
outtextxy(570,120,"y=");
outtextxy(570,140,"z=");
sprintf(k1,"%d",(xc-MIN_X));
outtextxy(600,100,k1);
sprintf(l1,"%d",(yc-MIN_Y));
outtextxy(600,120,l1);
sprintf(m1,"%d",(zc-100));
outtextxy(600,140,m1);
if(xc>MIN_X&&yc>MIN_Y&&xc<MAX_X&&yc<MAX_Y)
{
putpixel(xc,yc,RED);
putpixel(xc+1,yc+1,RED);
putpixel(xc,yc+1,RED);
putpixel(xc+1,yc,RED);
}
else
outtextxy(150,316 ,"sorry! pixel is outside the
boundary");
}
void t3d()
{
char
*xs,*ys,*zs,*chs,*txs,*tys,*tzs,*sxs,*sys,*szs,*angs;
float a[10][10],d[10][10],c[9][9];
int tx,ty,tz,sx,sy,sz,ch;
int x,y,z,ang,i;
float th;
xs=readline("Enter x cordinate:(0-525) ");
x=atoi(xs);
ys=readline("Enter y cordinate:(0-290) ");
y=atoi(ys);
zs=readline("Enter z cordinate:(0-300) ");
z=atoi(zs);
x=x+MIN_X;
y=y+MIN_Y;
35 | P a g e
Chapter 4 Source Code
z=z+100;
putpixel(x,y,BLUE);
putpixel(x+1,y+1,BLUE);
putpixel(x+1,y,BLUE);
putpixel(x,y+1,BLUE);
d[0][0]=x,d[0][1]=y,d[0][2]=z,d[0][3]=1;
chs=readline("1.TRANS 2.SCALING 3.Zrotate
4.Yrotate 5.Xrotate");
ch=atoi(chs);
switch(ch)
{
case 1:
txs=readline("Enter tx: ");
tx=atoi(txs);
tys=readline("Enter ty ");
ty=atoi(tys);
tzs=readline("Enter tz: ");
tz=atoi(tzs);
a[0][0]=a[1][1]=a[2][2]=a[3][3]=1;
a[3][0]=tx;a[3][1]=ty;a[3][2]=tz;
a[0][1]=a[0][2]=a[0][3]=a[1][0]=a[1][2]=a[1][3]=a[2]
[0]=a[2][1]=a[2][3]=0;
mul(d,a);
break;
a[0][1]=a[0][2]=a[0][3]=a[1][0]=a[1][2]=a[1][3]=a[2]
[0]=a[2][1]=a[2][3]=a[3][0]=a[3][1]=a[3][2]=0;
mul(d,a);
break;
case 3:
angs=readline("enter rotatinal angle about
z");
ang=atoi(angs);
th=(3.142*ang)/180;
a[0][0]=a[1][1]=cos(th);
36 | P a g e
Chapter 4 Source Code
a[0][2]=a[1][2]=a[0][3]=a[1][3]=a[2][1]=a[2][0]=a[3]
[0]=a[3][1]=a[3][2]=a[2][3]=0;
a[3][3]=a[2][2]=1;
a[0][1]=sin(th);a[1][0]=-sin(th);
mul(d,a);
break;
case 4:
angs=readline("enter rotatinal angle
about y");
ang=atoi(angs);
th=(3.142*ang)/180;
a[1][1]=a[3][3]=1;
a[0][1]=a[0][3]=a[1][0]=a[1][2]=a[1][3]=a[2][1]=a[2]
[3]=a[3][0]=a[3][1]=a[3][2]=0;
a[0][0]=a[2][2]=cos(th);
a[2][0]=sin(th);
a[0][2]=-sin(th);
mul(d,a);
break;
case 5:
angs=readline("enter rotatinal angle
about x");
ang=atoi(angs);
th=(3.142*ang)/180;
a[0][0]=a[3][3]=1;
a[1][1]=a[2][2]=cos(th);
a[1][2]=sin(th);a[2][1]=-sin(th);
a[0][1]=a[0][2]=a[0][3]=a[1][0]=a[1][3]=a[2][0]=a[2]
[3]=a[3][0]=a[3][1]=a[3][2]=0;
mul(d,a);
break;
default:exit(0);
}
}
void translate()
{
char *name;
int tx,ty;
setcolor(Current_Color);
rectangle(MIN_X,MIN_Y,MAX_X,MAX_Y);
ShowStatus("Draw rectangle to translate");
drawrectangle();
37 | P a g e
Chapter 4 Source Code
setcolor(Current_Color);
if(Current_Pattern!=EMPTY_FILL)
setfillstyle(Current_Pattern,Current_Color);
bar(a,b,c,d);
rectangle(a,b,c,d);
}
38 | P a g e
Chapter 4 Source Code
tmp=first;
first=first->next;
x=first->x;
y=first->y;
free(tmp);
39 | P a g e
Chapter 4 Source Code
}
for(p=first;p!=NULL;p=q)
{
q=p->next;
free(p);
}
}
void fillcolor()
{
unsigned oldcolor;
int x=mousex;
int y=mousey;
oldcolor=getpixel(mousex,mousey);
hidemouse();
floodfill4(x,y,oldcolor,Current_Color);
showmouse();
}
line((int)(x+70*sqrt(2)*cos(theta)),(int)(y+70*sqrt(2)*si
n(theta)),(int)
(x+70*sqrt(2)*cos(theta+M_PI_2)),(int)(y+70*sqrt(2)*
sin(theta+M_PI_2)));
circle(x,y,70);
}
void rotate_line()
{
float theta=0;
int i,j;
clear();
ShowStatus("Press ESC to terminate");
while(1)
{
if(kbhit())
if(getch()==27)
{
clear();
return;
}
setcolor(BLACK);
myl(360,249,theta);
delay(100);
setcolor(WHITE);
myl(360,249,theta);
theta+=M_PI_2/10;
40 | P a g e
Chapter 4 Source Code
}
}
int x2,y2,x3,y3;
outcode0=compcode(x0,y0,xmin,ymin,xmax,ymax);
outcode1=compcode(x1,y1,xmin,ymin,xmax,ymax);
while(done)
{
if(!(outcode0|outcode1))
{
accept=1;
done=0;
}
else if(outcode0&outcode1)
done=0;
else
{
outcodeout=outcode0?outcode0:outcode1;
m=(y1-y0)/(float)(x1-x0);
if(outcodeout&top)
41 | P a g e
Chapter 4 Source Code
{
x=x0+(ymax-y0)/m;
y=ymax;
}
else if(outcodeout&bottom)
{
x=x0+(ymin-y0)/m;
y=ymin;
}
else if(outcodeout&right)
{
y=y0+(xmax-x0)*m;
x=xmax;
}
else
{
y=y0+(xmin-x0)*m;
x=xmin;
}
if(outcodeout==outcode0)
{
x0=x; y0=y;
outcode0=compcode(x0,y0,xmin,ymin,xmax,ymax);
}
else
{
x1=x; y1=y;
outcode1=compcode(x1,y1,xmin,ymin,xmax,ymax);
}
}
}
hidemouse();
clear();
if(accept)
{
setcolor(BLACK);
outtextxy(110,80,"Clipped line in the window");
rectangle(x3,y3,x2,y2);
setcolor(Current_Color);
bline(x0,y0,x1,y1);
ClearStatus();
ShowStatus("Right click to view Clipped line in
Viewport");
getxy();
while(!RightButtonPressed)getxy();
x0=(float)(x0-xmin)*(umax-umin)/(xmax-xmin)+umin;
x1=(float)(x1-xmin)*(umax-umin)/(xmax-xmin)+umin;
y0=(float)(y0-ymin)*(vmax-vmin)/(ymax-ymin)+vmin;
y1=(float)(y1-ymin)*(vmax-vmin)/(ymax-ymin)+vmin;
42 | P a g e
Chapter 4 Source Code
clear();
setcolor(BLACK);
outtextxy(110,80,"Clipped line in viewport");
rectangle(umin,vmin,umax,vmax);
setcolor(Current_Color);
bline(x0,y0,x1,y1);
} // if line within the region
showmouse();
setcolor(Current_Color);
}
void lineclipping()
{
int x,y,current_x,current_y,tx,ty,b,color;
int x0,y0,x1,y1;
R=1;
clear();
showmouse();
getxy();
x=mousex;y=mousey;
disp_coord();
if(LeftButtonPressed)
{
while(LeftButtonPressed)
{
getxy();disp_coord();
if(prevx==mousex&&prevy==mousey)
continue;
hidemouse();
putback();
showmouse();
getxy();
hidemouse();
bline(x,y,mousex,mousey);
showmouse();
delay(10);
}
x0=x;y0=y;x1=mousex;y1=mousey;
ClearStatus(); ShowStatus("Draw the Clipping
Window");
getxy();
while(!LeftButtonPressed)
{
getxy();
disp_coord();
}
hidemouse();
setcolor(15-BLACK);
setwritemode(XOR_PUT);
x=mousex;
y=mousey;
43 | P a g e
Chapter 4 Source Code
while(LeftButtonPressed)
{
setlinestyle(3,1,1);
disp_coord();
current_x=mousex;
current_y=mousey;
while(current_x==mousex && current_y==mousey)
getxy();
rectangle(x,y,current_x,current_y);
rectangle(x,y,mousex,mousey);
}
setlinestyle(0,1,1);
setwritemode(COPY_PUT);
setcolor(Current_Color);
ClearStatus();
showmouse();
x3=mousex, y3=mousey, x2=x, y2=y;
if(x2>x3)
current_x=x2,x2=x3,x3=current_x;
if(y2>y3)
current_y=y2,y2=y3,y3=current_y;
CohenSutherlandLine(x0,y0,x1,y1,x2,y2,x3,y3);
t=0;
draw_button_border(Current_Button);
undraw_button_border(Prev_Button);
Current_Button=Prev_Button;
}//if left button
}
44 | P a g e
Chapter 4 Source Code
icons(buttons[no].xmin,buttons[no].ymin,buttons[no].xmax,
buttons[no].ymax,1);
icons(buttons[no].xmin+1,buttons[no].ymin+1,buttons[no].x
max-1,buttons[no].ymax-1,1);
showmouse();
}
icons(buttons[no].xmin,buttons[no].ymin,buttons[no].xmax,
buttons[no].ymax,0);
icons(buttons[no].xmin+1,buttons[no].ymin+1,buttons[no].x
max-1,buttons[no].ymax-1,0);
showmouse();
}
45 | P a g e
Chapter 4 Source Code
rectangle(colorbuttons[no].xmin+1,colorbuttons[no].ymin+1
,colorbuttons[no].xmax-1,colorbuttons[no].ymax-1);
setfillstyle(SOLID_FILL,no);
floodfill(colorbuttons[no].xmin+3,colorbuttons[no].ymin+3
,BLACK);
setcolor(color);
}
//icon panel
New_icon(x1,y1+1);
init_button(butt,x1,y1,xwidth,ywidth,"New File"); //of
struct button
draw_button_border(butt++);
Save_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"Save File");
draw_button_border(butt++);
y1+=ywidth;
Open_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"Load File");
draw_button_border(butt++);
46 | P a g e
Chapter 4 Source Code
Clear_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"Clear File");
draw_button_border(butt++);
y1+=ywidth;
Line_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"Line Drawing
Tool");
draw_button_border(butt++);
Rectangle_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"Rectangle
Drawing Tool");
draw_button_border(butt++);
y1+=ywidth;
Circle_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"Circle Drawing
Tool");
draw_button_border(butt++);
Ellipse_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"Ellipse Drawing
Tool");
draw_button_border(butt++);
y1+=ywidth;
Spiral_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"Spiral Drawing
Tool");
draw_button_border(butt++);
Clip_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"Line Clipper");
draw_button_border(butt++);
y1+=ywidth;
Rot_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"Rotating line
around circle tangentially");
draw_button_border(butt++);
Wheel_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"Rotating
Wheel");
draw_button_border(butt++);
y1+=ywidth;
47 | P a g e
Chapter 4 Source Code
Seg_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"Segmentation");
draw_button_border(butt++);
hr_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"DRAW HRMITE
CURVE ");
draw_button_border(butt++);
y1+=ywidth;
bz_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"DRAW BEZIER
CURVE");
draw_button_border(butt++);
t3d_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"3D ROTATION ");
draw_button_border(butt++);
y1+=ywidth;
Translate_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"TRANSLATE
RECTANGLE");
draw_button_border(butt++);
//y1+=ywidth;
fl_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"FILL A COLOR");
draw_button_border(butt++);
y1+=ywidth;
scale_icon(x1,y1);
init_button(butt,x1,y1,xwidth,ywidth,"SCALING
RECTANGLE");
draw_button_border(butt++);
Rotate_icon(x2,y1);
init_button(butt,x2,y1,xwidth,ywidth,"ROTATING A
RECTANGLE");
draw_button_border(butt++);
y1+=ywidth;
48 | P a g e
Chapter 4 Source Code
xwidth=30;ywidth=15;
for(i=0;i<8;i++) //iteratively init the col-but
structure
{ //init color button is very
similar to init_button
init_color_button(butt,x1,y1,xwidth,ywidth);
draw_color_button_border(butt++);
init_color_button(butt,x1,y2,xwidth,ywidth);
draw_color_button_border(butt++);
x1=x1+xwidth;
}
setcolor(Current_Color); }
void dispfile() //display and updates filename in case of
load/save,etc
{
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(260,MIN_Y-30,379,MIN_Y-6);
icons(260,MIN_Y-30,379,MIN_Y-6,1);
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(MAX_X-15+8,4,MAX_X+1+8,15-2);
icons(MAX_X-15+8,4,MAX_X+1+8,15-2,1);
icons(MAX_X-14+8,5,MAX_X+8,15-3,1);
setcolor(BLACK);
settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
outtextxy(MAX_X-10+8,4,"x"); // exits on clicking
outtextxy((getmaxx()-
textwidth(filename))/2,48,filename);
}
/* BASIC OPERATIONS
*/
int check_if_color()
{
int i=0;
for(i=0;i<MAX_COLOR;i++)
{
49 | P a g e
Chapter 4 Source Code
if(check_mouse_on(colorbuttons[i].xmin,colorbuttons[i].ym
in,colorbuttons[i].xmax,colorbuttons[i].ymax))
{
Current_Color=colorbuttons[i].color;
setfillstyle(SOLID_FILL,Current_Color);
bar(MIN_X+20,MAX_Y+35,MIN_X+44,MAX_Y+50);
setcolor(BLACK);
rectangle(MIN_X+20,MAX_Y+35,MIN_X+44,MAX_Y+50);
setcolor(Current_Color);
return 1;
}
}
return 0;
}
int check_if_button_pressed()
{
int ret_value=-1,color;
int i;
char ch;
for(i=0;i<MAX_BUTTONS;++i)
{
if(check_mouse_on(buttons[i].xmin,buttons[i].ymin,buttons
[i].xmax,buttons[i].ymax))
{
if(LeftButtonPressed && i!=Current_Button) //check
which button
{ // if not
current button
ret_value=i; //change current
button = i
draw_button_border(Current_Button);
Prev_Button=Current_Button;
Current_Button=i;
undraw_button_border(Current_Button);
switch(Current_Button)
{
case NEW :
hidemouse();
if(!saved)
{
ShowStatus("Save Changes (Y or N) ? ");
ch=getch();
if(ch=='y'||ch=='Y')
save();
}
strcpy(filename,"Untitled");
dispfile();
clear();
draw_button_border(Current_Button);
50 | P a g e
Chapter 4 Source Code
undraw_button_border(Prev_Button);
Current_Button=Prev_Button;
showmouse();
break;
case CLEAR :
hidemouse();
clear();
draw_button_border(Current_Button);
undraw_button_border(Prev_Button);
Current_Button=Prev_Button;
showmouse();
break;
case LOAD:
hidemouse();
load();
draw_button_border(Current_Button);
undraw_button_border(Prev_Button);
Current_Button=Prev_Button;
showmouse();
break;
case SAVE:
hidemouse();
save();
draw_button_border(Current_Button);
undraw_button_border(Prev_Button);
Current_Button=Prev_Button;
showmouse();
break;
case CLIP_OP:
clear();
break;
case TRANS_OP:
clear();
}
}
if(prevx!=mousex||prevy!=mousey)
ShowStatus(buttons[i].desc);
return ret_value;
}//check on which button
}//for all button
ClearStatus();
return ret_value;
}
void tools()
{
51 | P a g e
Chapter 4 Source Code
restrictmouse(MIN_X+2,MIN_Y+2,MAX_X-2,MAX_Y-2);
hidemouse();
switch(Current_Button)
{
case 4 :
case 5 :
case 6 :
case 7 :
case 13:
case 14:
case 8 : rubberband();
break;
case 9 : //freehand();
lineclipping();
break;
case 16:translate();
//clearin();
break;
52 | P a g e
Chapter 4 Source Code
}
showmouse();
restrictmouse(0,0,639,479);
}
void rubberband()
{
int x,y,xe,ye,tx,ty,b,r1,r2;
R=1;
showmouse();
getxy();
x=mousex;y=mousey;
disp_coord();
if(LeftButtonPressed)
{
while(LeftButtonPressed)
{
getxy();disp_coord();
if(prevx==mousex&&prevy==mousey)
continue;
hidemouse();
putback();
showmouse();
getxy();
hidemouse();
switch(Current_Button)
{
case 4: bline(x,y,mousex,mousey);
break;
case 5: brectangle(x,y,mousex,mousey);
break;
case 6: bcircle(x,y,abs(x-mousex)<abs(y-
mousey)?abs(y-mousey):abs(x-mousex));
break;
case 7: r1=abs(x-mousex),r2=abs(y-mousey);
if(r1!=0&&r2!=0) //else floating point
error
bellipse(x,y,abs(x-mousex),abs(y-
mousey));
break;
53 | P a g e
Chapter 4 Source Code
case 8: spiral(x,y,abs(x-mousex)<abs(y-
mousey)?abs(y-mousey):abs(x-mousex),1,50);
break;
case 13:hrcurve(x,y,mousex,mousey);
break;
case 14:bzcurve(x,y,mousex,mousey);
break;
}
showmouse();
delay(10);
}//while left button
t=0;
}//if left button
}
void Wheel()
{
char ch;
int x,y,s;
float theta=0;
int i,j,f,b;
// flushall();
clear();
ShowStatus("Press ESC to terminate");
getxy();
hidemouse();
while(!LeftButtonPressed)
{
getxy();
for(i=153;i<=573;i+=8)
{
if(kbhit())
if(getch()==27)
{
clear();
showmouse();
return;
}
setcolor(BLACK);
myw(i,230,theta);
delay(130);
setcolor(WHITE);
myw(i,230,theta);
theta+=M_PI/10;
}
for(i=573;i>=153;i-=8)
{
if(kbhit())
54 | P a g e
Chapter 4 Source Code
if(getch()==27)
{
clear();
showmouse();
return;
}
setcolor(BLACK);
myw(i,230,theta);
delay(130);
setcolor(WHITE);
myw(i,230,theta);
theta-=M_PI/10;
}
}
clear();
showmouse();
}
void scale()
{
char *name;
float sx,sy;
setcolor(Current_Color);
rectangle(MIN_X,MIN_Y,MAX_X,MAX_Y);
ShowStatus("Draw rectangle to scale");
drawrectangle();
setcolor(WHITE);
setfillstyle(SOLID_FILL,WHITE);
bar(a,b,c,d);
c= (float)(c-a)*sx + (float)a;
d= (float)(d-b)*sy + (float)b;
if(c >=MAX_X) c=MAX_X-1;
setcolor(Current_Color);
if(Current_Pattern!=EMPTY_FILL)
setfillstyle(Current_Pattern,Current_Color);
bar(a,b,c,d);
rectangle(a,b,c,d);
}
void drawrectangle()
{
55 | P a g e
Chapter 4 Source Code
int color=15-Current_Color;
int x,y;
setcolor(color);
setwritemode(XOR_PUT);
x=mousex;
y=mousey;
while(LeftButtonPressed)
{
disp_coord();
rectangle(x,y,mousex,mousey);
getxy();
rectangle(x,y,mousex,mousey);
}
setwritemode(COPY_PUT);
setcolor(Current_Color);
if(Current_Pattern==EMPTY_FILL)
rectangle(x,y,mousex,mousey);
else
{
setfillstyle(Current_Pattern,Current_Color);
bar(x,y,mousex,mousey);
}
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\tc\\bgi");
if(!initmouse())
{
outtextxy(250,230,"Mouse not present");
getch();
exit(0);
}
wel();
cleardevice();
frame();// To create window
startmouse((MIN_X+MAX_X)/2,(MIN_Y+MAX_Y)/2);
showmouse();
init(); // To display all icons
undraw_button_border(Current_Button);
dispfile();
while(1)
{
tme();
56 | P a g e
Chapter 4 Source Code
getxy();
if(!check_mouse_on(MIN_X+2,MIN_Y+2,MAX_X-2,MAX_Y-
2))
{
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(487,462,522,472); //refresh display
bar(555,462,585,472);
}
else disp_coord();
if(LeftButtonPressed)
{
if(check_if_button_pressed()>=0) ;
else if(check_if_color())
ClearStatus();
else if(check_mouse_on(MIN_X+2,MIN_Y+2,MAX_X-
2,MAX_Y-2))
{
ClearStatus();
saved=0;
tools();
}
else check_if_exit();
}
else check_if_button_pressed();
}
}
// to display exiting page
57 | P a g e
Chapter 4 Source Code
setcolor(RED);
outtextxy(100,25,"\n");
outtextxy(100,375,"\n");
rectangle(1,1,637,477);
rectangle(3,3,635,475);
setcolor(BLUE);
outtextxy(190,200,"THANK YOU!!!!!");
setcolor(9);
outtextxy(189,201,"THANK YOU!!!!!");
settextstyle(0,0,0);
setcolor(12);
_dos_getdate(&d);
printf(" %d-%d-%d ", d.day,d.month,d.year);
_dos_gettime(&t);
printf(" %2d:%02d:%02d\n", t.hour, t.minute,t.second);
outtextxy(430,450,"NOW PRESS ANY KEY TO EXIT");
settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
getch(); exit(0);
}
}
58 | P a g e
5. SAMPLE OUTPUT
59 | P a g e
CONCLUSION
The most obvious enhancement that we see is, support for the standard image
formats such as BMP, JPEG, GIF etc. This would allow the editor to open image
documents stored in these standard formats. We would also like to support saving of
our documents in these formats so that the editor is compatible with all the standard
graphics editors.
Another feature we would like to incorporate is to provide a way for the user to store
and open documents in directories other than the current directory. We would like to
provide the user with a simple way to traverse the directory structure for file
operations.
60 | P a g e
References
61 | P a g e
Acharya, Kamal, Online Job Portal Management System (May 5, 2024).
Available at
SSRN: https://ssrn.com/abstract=4817534 or http://dx.doi.org/10.2139/ssrn.4
817534
Acharya, Kamal, Employee leave management system. (May 7, 2024).
Available at
SSRN: https://ssrn.com/abstract=4819626 or http://dx.doi.org/10.2139/ssrn.4
819626
Acharya, Kamal, Online job placement system project report. (January 10,
2023). Available at
SSRN: https://ssrn.com/abstract=4831638 or http://dx.doi.org/10.2139/ssrn.4
831638
Acharya, Kamal, Software testing for project report. (May 16, 2023).
Available at
SSRN: https://ssrn.com/abstract=4831028 or http://dx.doi.org/10.2139/ssrn.4
831028
Acharya, Kamal, Burger ordering system project report. (October 10, 2022).
Available at
SSRN: https://ssrn.com/abstract=4832704 or http://dx.doi.org/10.2139/ssrn.4
832704
62 | P a g e
Acharya, Kamal, Dairy Management System Project Report (December 20,
2020). Available at
SSRN: https://ssrn.com/abstract=4835231 or http://dx.doi.org/10.2139/ssrn.4
835231
Acharya, Kamal, Paint shop management system project report. (January 10,
2019). Available at
SSRN: https://ssrn.com/abstract=4835441 or http://dx.doi.org/10.2139/ssrn.4
835441
Acharya, Kamal, Online taxi booking system project report. (March 10, 2022).
Available at
SSRN: https://ssrn.com/abstract=4837729 or http://dx.doi.org/10.2139/ssrn.4
837729
Acharya, Kamal, Online car servicing system project report. (March 10,
2023). Available at
SSRN: https://ssrn.com/abstract=4837832 or http://dx.doi.org/10.2139/ssrn.4
837832
Acharya, Kamal, School management system project report. (July 10, 2021).
Available at
SSRN: https://ssrn.com/abstract=4837837 or http://dx.doi.org/10.2139/ssrn.4
837837
Acharya, Kamal, Online Vehicle Rental System Project Report (March 21,
2019). Available at
SSRN: https://ssrn.com/abstract=4839429 or http://dx.doi.org/10.2139/ssrn.4
839429
63 | P a g e
Acharya, Kamal, Fruit Shop Management System Project Report (August 10,
2023). Available at
SSRN: https://ssrn.com/abstract=4841048 or http://dx.doi.org/10.2139/ssrn.4
841048
Acharya, Kamal, College bus management system project report (April 25,
2023). Available at
SSRN: https://ssrn.com/abstract=4846920 or http://dx.doi.org/10.2139/ssrn.4
846920
Acharya, Kamal, Courier management system project report (May 25, 2023).
Available at
SSRN: https://ssrn.com/abstract=4846922 or http://dx.doi.org/10.2139/ssrn.4
846922
Acharya, Kamal, Event management system project report (April 25, 2021).
Available at
SSRN: https://ssrn.com/abstract=4846927 or http://dx.doi.org/10.2139/ssrn.4
846927
65 | P a g e