0% found this document useful (0 votes)
93 views

C++ Source Codes

This program implements the DDA (Digital Differential Analyzer) line drawing algorithm. It takes input coordinates for two points (x1,y1) and (x2,y2) and the width of the line. It then calculates the slope, length of the line, and pixel increments. A while loop draws the line by putting pixels within the width of the line between the two points.

Uploaded by

katkesav
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

C++ Source Codes

This program implements the DDA (Digital Differential Analyzer) line drawing algorithm. It takes input coordinates for two points (x1,y1) and (x2,y2) and the width of the line. It then calculates the slope, length of the line, and pixel increments. A while loop draws the line by putting pixels within the width of the line between the two points.

Uploaded by

katkesav
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 14

Program to implement DDA Line Drawing Algorithm sprintf(s,"B(%d,%d)",x2,y2);

outtextxy(40,30,s);
#include<iostream.h> getch();
#include<graphics.h> }
#include<conio.h> void main()
#include<math.h> {
#include<dos.h> int gd=DETECT,gm,i,j,xx=240,xxx=380;
#include<stdlib.h> clrscr();
#include<stdio.h> lines a;
class lines char *mess[]={"D","D","A","
{ ","A","L","G","O","R","I","T","H","M"};
private: initgraph(&gd,&gm,"..\bgi");
int length,x1,y1,x2,y2,x,y,dx,dy,wx,wy,w,width; cleardevice();
public: rectangle(120,40,320,240);
lines(); //Constructor rectangle(320,40,520,240);
void showline(); rectangle(120,240,320,440);
int sign(int); rectangle(320,240,520,440);
}; for(i=0,j=12;i<8,j>=6;i++,j--)
{
int lines::sign(int xx) xx+=10;
{ outtextxy(xx,10,mess[i]);
if(xx<0) xxx-=10;
return -1; outtextxy(xxx,10,mess[j]);
if(xx==0) delay(100);
return 0; }
if(xx>0) for(i=130;i<=510;i+=10)
return 1; for(j=50;j<=430;j+=10)
return 0; putpixel(i,j,15);
} for(i=130;i<=510;i+=10)
lines::lines() {
{ if(i==320)
x=0;y=0; continue;
cout<<" outtextxy(i,237,"+");
"Enter The Co-Ordinates (x1,y1) ":="; }
cin>>x1>>y1; for(i=50;i<=430;i+=10)
cout<<" {
"Enter The Co-Ordinates (x2,y2) ":="; if(i==240)
cin>>x2>>y2; continue;
cout<<" outtextxy(317,i,"-");
"Enter The Width Of The Line ":="; }
cin>>width; outtextxy(310,230,"O");
} outtextxy(530,240,"X");
outtextxy(320,450,"-Y");
void lines::showline() outtextxy(100,240,"-X");
{ outtextxy(320,30,"Y");
char *s,*s1; a.showline();
if(abs(x2-x1)>=abs(y2-y1)) closegraph();
length=abs(x2-x1); }
else
length=abs(y2-y1);
w=width; Program to implement Bresenhams Line Drawing Algorithm
wx=((w-1)/2)*(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-
y1))/abs(y2-y1)); #include<iostream.h>
wy=((w-1)/2)*(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2- #include<graphics.h>
y1))/abs(x2-x1)); #include<conio.h>
dx=(x2-x1)/length; #include<math.h>
dy=(y2-y1)/length; #include<dos.h>
if(dy>dx) #include<stdlib.h>
wy=wx; #include<stdio.h>
x=x1+0.5*sign(dx); class lines
y=y1+0.5*sign(dy); {
int i=1; private:
setcolor(0); int length,x1,y1,x2,y2,x,y,dx,dy,wx,wy,w,width;
while(i<=length) public:
{ lines(); //Constructor
for(int j=0;j<wy;j++) void showline();
putpixel((x+320),480-(y+240+j),6); int sign(int);
for(j=0;j<wy;j++) };
putpixel((x+320),480-(y+240-j),6);
putpixel((x+320),480-(y+240),6); int lines::sign(int xx)
x+=dx; {
y+=dy; if(xx<0)
i++; return -1;
} if(xx==0)
setcolor(15); return 0;
outtextxy(40,10,"The Points Are:="); if(xx>0)
sprintf(s,"A(%d,%d)",x1,y1); return 1;
outtextxy(40,20,s); return 0;
} lines a;
lines::lines() char *mess[]={"B","R","E","S","E","N","H","A","M","'","S","
{ ","L","I","N","E"," ","A","L","G","O","R","I","T","H","M"};
x=0;y=0; initgraph(&gd,&gm,"..\bgi");
cout<<" cleardevice();
"Enter The Co-Ordinates (x1,y1) ":="; rectangle(120,40,320,240);
cin>>x1>>y1; rectangle(320,40,520,240);
cout<<" rectangle(120,240,320,440);
"Enter The Co-Ordinates (x2,y2) ":="; rectangle(320,240,520,440);
cin>>x2>>y2; for(i=0,j=25;i<14,j>=12;i++,j--)
cout<<" {
"Enter The Width Of The Line ":="; xx+=10;
cin>>width; outtextxy(xx,10,mess[i]);
} xxx-=10;
outtextxy(xxx,10,mess[j]);
void lines::showline() delay(100);
{ }
char *s; for(i=130;i<=510;i+=10)
int s1,s2,ic; for(j=50;j<=430;j+=10)
float temp; putpixel(i,j,15);
x=x1;y=1; for(i=130;i<=510;i+=10)
w=width; {
if(y2-y1) if(i==320)
wx=((w-1)/2)*(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2- continue;
y1))/abs(y2-y1)); outtextxy(i,237,"+");
if(x2-x1) }
wy=((w-1)/2)*(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2- for(i=50;i<=430;i+=10)
y1))/abs(x2-x1)); {
dx=abs(x2-x1); if(i==240)
dy=abs(y2-y1); continue;
s1=sign(x2-x1); outtextxy(317,i,"-");
s2=sign(y2-y1); }
if(dy>dx) outtextxy(310,230,"O");
wy=wx; outtextxy(530,240,"X");
if(dy>dx) outtextxy(320,450,"-Y");
{ outtextxy(100,240,"-X");
temp=dy; outtextxy(320,30,"Y");
dy=dx; a.showline();
dx=temp; closegraph();
ic=1; }
}
else Program to implement Circle Drawing Algorithm
ic=0;
float d=2*dy-dx; #include<iostream.h>
setcolor(0); #include<graphics.h>
for(int i=1;i<=dx;i++) #include<conio.h>
{ #include<math.h>
for(int j=0;j<wy;j++) #include<dos.h>
putpixel((x+320),480-(y+240+j),5); #include<stdlib.h>
for(j=0;j<wy;j++) #include<stdio.h>
putpixel((x+320),480-(y+240-j),5); class myCircle
putpixel((x+320),480-(y+240),5); {
while(d>=0) private:
{ int x,y,r,d,x1,y1;
if(ic==1) public:
x+=s1; myCircle(); //Constructor
else void showCircle();
y+=s2; };
d-=2*dx;
} myCircle::myCircle()
if(ic==1) {
y+=s2; x=0;y=0;
else cout<<"
x+=s1; "Enter The Co-Ordinates Of The Circle ":=";
d+=2*dy; cin>>x>>y;
} cout<<"
setcolor(15); "Enter The Radius Of The Circle ":=";
outtextxy(20,10,"The Points Are:="); cin>>r;
sprintf(s,"A(%d,%d)",x1,y1); }
outtextxy(20,20,s);
sprintf(s,"B(%d,%d)",x2,y2); void myCircle::showCircle()
outtextxy(20,30,s); {
getch(); char *s;
} x1=0;y1=r;
void main() d=3-2*r;
{ while(x1<=y1)
int gd=DETECT,gm,i,j,xx=200,xxx=470; {
clrscr(); putpixel((x+x1+320),(y+y1+240),5);
putpixel((x-x1+320),(y+y1+240),5); #include<stdlib.h>
putpixel((x+x1+320),(y-y1+240),5); #include<stdio.h>
putpixel((x-x1+320),(y-y1+240),5); class myCircle
putpixel((x+y1+320),(y+x1+240),5); {
putpixel((x-y1+320),(y+x1+240),5); private:
putpixel((x+y1+320),(y-x1+240),5); int x,y,r,d,x1,y1,minor,major,dtheta,ratio,a,b,x2,y2;
putpixel((x-y1+320),(y-x1+240),5); public:
if(d<0) myCircle(); //Constructor
d+=4*x1+6; void showCircle();
else };
{
d+=4*(x1-y1)+10; myCircle::myCircle()
y1--; {
} x=0;y=0;
x1++; cout<<"
} "Enter The Major & Minor Axis Of Ellipse ":=";
setcolor(5); cin>>major>>minor;
outtextxy(318+x,235+y,"."); cout<<"
setcolor(15); "Enter The Center Of The Ellipse ":=";
sprintf(s,"Center(%d,%d)",x,y); cin>>x>>y;
outtextxy(20,10,"The Center Is At"); }
outtextxy(20,20,s);
sprintf(s,"Radius=%d",r); void myCircle::showCircle()
outtextxy(20,30,s); {
getch(); char *s;
} int ax,ay;
void main() float ar;
{ x1=1;
int gd=DETECT,gm,i,j,xx=190,xxx=480; ratio=major/minor;
clrscr(); getaspectratio(&ax,&ay);
myCircle a; ar=1;
char *mess[]={"B","R","E","S","E","N","H","A","M","'","S"," // ar=ay/ax;
","C","I","R","C","L","E"," ","A","L","G","O","R","I","T","H","M"}; while(x1<=major)
initgraph(&gd,&gm,"..\bgi"); {
cleardevice(); y1=minor*sqrt((1-(x1*x1/major*major)));
rectangle(120,40,320,240); putpixel((x+x1*ar+320),(y+y1+240),5);
rectangle(320,40,520,240); putpixel((x+x1*ar+320),(y-y1+240),5);
rectangle(120,240,320,440); putpixel((x-x1*ar+320),(y-y1+240),5);
rectangle(320,240,520,440); putpixel((x-x1*ar+320),(y+y1+240),5);
for(i=0,j=27;i<16,j>=14;i++,j--) dtheta=1/sqrt(x1*x1+y1*y1);
{ // x2=x1+cos(dtheta)-ratio*y1*sin(dtheta);
xx+=10; // y2=y1+cos(dtheta)+1/ratio*x1*sin(dtheta);
outtextxy(xx,10,mess[i]); x1++;
xxx-=10; // y1=y2;
outtextxy(xxx,10,mess[j]); }
delay(100); setcolor(5);
} outtextxy(318+x,235+y,".");
for(i=130;i<=510;i+=10) setcolor(15);
for(j=50;j<=430;j+=10) sprintf(s,"Center(%d,%d)",x,y);
putpixel(i,j,15); outtextxy(20,10,"The Center Is At");
for(i=130;i<=510;i+=10) outtextxy(20,20,s);
{ sprintf(s,"Radius=%d",r);
if(i==320) outtextxy(20,30,s);
continue; getch();
outtextxy(i,237,"+"); }
} void main()
for(i=50;i<=430;i+=10) {
{ int gd=DETECT,gm,i,j,xx=190,xxx=480;
if(i==240) clrscr();
continue; myCircle a;
outtextxy(317,i,"-"); char *mess[]={"B","R","E","S","E","N","H","A","M","'","S","
} ","C","I","R","C","L","E"," ","A","L","G","O","R","I","T","H","M"};
outtextxy(310,230,"O"); initgraph(&gd,&gm,"..\bgi");
outtextxy(530,240,"X"); cleardevice();
outtextxy(320,450,"-Y"); rectangle(120,40,320,240);
outtextxy(100,240,"-X"); rectangle(320,40,520,240);
outtextxy(320,30,"Y"); rectangle(120,240,320,440);
a.showCircle(); rectangle(320,240,520,440);
// closegraph(); for(i=0,j=27;i<16,j>=14;i++,j--)
} {
xx+=10;
Program to implement Ellipse Drawing Algorithm outtextxy(xx,10,mess[i]);
xxx-=10;
#include<iostream.h> outtextxy(xxx,10,mess[j]);
#include<graphics.h> delay(100);
#include<conio.h> }
#include<math.h> for(i=130;i<=510;i+=10)
#include<dos.h> for(j=50;j<=430;j+=10)
putpixel(i,j,15); }
for(i=130;i<=510;i+=10) void D_2::initialize()
{ {
if(i==320) int gdrive = DETECT,gmode;
continue; initgraph(&gdrive,&gmode,"c: cgi");
outtextxy(i,237,"+"); }
}
for(i=50;i<=430;i+=10) void D_2::GetPoints()
{ {
if(i==240) closegraph();
continue; cout<<"Enter The Points Of The Triangle.";
outtextxy(317,i,"-"); for(int j=0;j<MAXSIZE;j++)
} {
outtextxy(310,230,"O"); cout<<"Enter Point "<<j+1<<":-";
outtextxy(530,240,"X"); for(int i=0;i<MAXSIZE-1;i++)
outtextxy(320,450,"-Y"); {
outtextxy(100,240,"-X"); cout<<"Enter "<<char(i+'X')<<": ";
outtextxy(320,30,"Y"); cin>>Points[i][j];
a.showCircle(); }
} }
initialize();
Two-Dimension Transformation In Homogeneous Coordinate }

This Program Deals With All Two-D Transformation Such As Translation, void D_2::Mult(double temp[MAXSIZE][MAXSIZE])
Scaling, Rotation, {
Reflection, Shearing In Homogeneous Coordinates. int i,j,k;
double z[MAXSIZE][MAXSIZE];
for(i=0;i<MAXSIZE;i++)
{
Code : for(j=0;j<MAXSIZE;j++)
//TwoDimensional Transformations In Homogeneous z[i][j]=0;
}
#include<graphics.h>
#include<iostream.h> for(i=0;i<MAXSIZE;i++)
#include<Math.h> {
#include<conio.h> for(j=0;j<MAXSIZE;j++)
#define MAXSIZE 3 {

class D_2 for(k=0;k<MAXSIZE;k++)


{ z[i][j]=z[i][j]+(temp[i][k] * Points[k][j]);
private: }
double Points[MAXSIZE][MAXSIZE]; }
void Mult(double [MAXSIZE][MAXSIZE]);
void MultTwoMat(double [MAXSIZE][MAXSIZE],double for(i=0;i<MAXSIZE;i++)
[MAXSIZE][MAXSIZE]); {
void Print(); for(j=0;j<MAXSIZE;j++)
int x,y; {
public: Points[i][j] = z[i][j];
D_2(); }
void initialize(); }
void GetPoints(); }
void Draw(int);
void DrawCord();
void Translate();
void Rotate(); void D_2::Draw(int color)
void Reflect(); {
void Display(double[MAXSIZE][MAXSIZE]); int Poly[2*MAXSIZE+2];
void Shear(); int k = 0;
void Scale_Fixed(); if(color == GREEN)
void Scale_Dir(); DrawCord();
}; for(int j=0;j<MAXSIZE;j++)
{
for(int i=0;i<MAXSIZE-1;i++)
D_2::D_2() {
{ if(i==0)
for(int i=0;i<MAXSIZE;i++) Poly[k++] = x/2+Points[i][j];
{ else
for(int j=0;j<MAXSIZE;j++) Poly[k++] = y/2-Points[i][j];
{ }
if(i == (MAXSIZE-1)) }
Points[i][j] = 1; Poly[k++] = Poly[0];
else Poly[k] = Poly[1];
Points[i][j] = 0; setcolor(color);
} drawpoly(4,Poly);
} }
initialize();
x = getmaxx(); void D_2::Display(double Mat[MAXSIZE][MAXSIZE])
y = getmaxy(); {
for(int i=0;i<MAXSIZE;i++) }
{
for(int j=0;j<MAXSIZE;j++) for(i=0;i<MAXSIZE;i++)
{ {
cout<<Mat[i][j]<<" "; for(j=0;j<MAXSIZE;j++)
} {
cout<<"";
} for(k=0;k<MAXSIZE;k++)
} z[i][j]=z[i][j]+(temp[i][k] * temp1[k][j]);
}
void D_2::Print() }
{
setcolor(GREEN); for(i=0;i<MAXSIZE;i++)
setfillstyle(SOLID_FILL,GREEN); {
fillellipse(19,36,2,2); for(j=0;j<MAXSIZE;j++)
outtextxy(23,34," Original Triangle"); {
setcolor(MAGENTA); temp1[i][j] = z[i][j];
setfillstyle(SOLID_FILL,MAGENTA); }
fillellipse(x-178,y-32,2,2); }
outtextxy(x-175,y-34," Tranformed Triangle"); }
}

void D_2::DrawCord() void D_2::Translate()


{ {
setcolor(12); int Tx,Ty;
line(x/2,0,x/2,y); double Trans[MAXSIZE][MAXSIZE];
line(0,y/2,x,y/2); closegraph();
setcolor(10); cout<<"Enter Translation Factor Along X-Axis: ";
setfillstyle(SOLID_FILL,10); cin>>Tx;
fillellipse(x/2,y/2,2,2); cout<<"Enter Translation Factor Along Y-Axis: ";
for(int i=(x/2+50),j=(x/2-50);i<=x,j>=0;i=i+50,j=j-50) cin>>Ty;
{ initialize();
fillellipse(i,y/2,2,2); for(int j=0;j<MAXSIZE;j++)
fillellipse(j,y/2,2,2); {
} for(int i=0;i<MAXSIZE;i++)
for(i=(y/2+50),j=(y/2-50);i<=x,j>=0;i=i+50,j=j-50) {
{ if(i==j)
fillellipse(x/2,i,2,2); Trans[i][j] = 1;
fillellipse(x/2,j,2,2); else
} Trans[i][j] = 0;
}
outtextxy(x/2+3,y/2+4,"0"); }

outtextxy(x/2+45,y/2+5,"50"); Trans[0][MAXSIZE-1] = Tx;


outtextxy(x/2+95,y/2+5,"100"); Trans[1][MAXSIZE-1] = Ty;
outtextxy(x/2+145,y/2+5,"150"); Draw(GREEN);
outtextxy(x/2+195,y/2+5,"200"); Mult(Trans);
outtextxy(x/2+245,y/2+5,"250"); Draw(MAGENTA);
outtextxy(x/2+295,y/2+5,"300"); Print();
}
outtextxy(x/2-65,y/2+5,"-50");
outtextxy(x/2-115,y/2+5,"-100"); void D_2::Rotate()
outtextxy(x/2-165,y/2+5,"-150"); {
outtextxy(x/2-215,y/2+5,"-200"); double ang;
outtextxy(x/2-265,y/2+5,"-250"); const double PI = 22.0/7;
outtextxy(x/2-315,y/2+5,"-300"); double xr,yr;
double TransMat[MAXSIZE][MAXSIZE];
outtextxy(x/2+5,y/2+45,"-50"); double RotMat[MAXSIZE][MAXSIZE];
outtextxy(x/2+5,y/2+95,"-100"); double InvTransMat[MAXSIZE][MAXSIZE];
outtextxy(x/2+5,y/2+145,"-150");
outtextxy(x/2+5,y/2+195,"-200"); closegraph();
cout<<"Enter Angle Of Rotation: ";
outtextxy(x/2+5,y/2-50,"50"); cin>>ang;
outtextxy(x/2+5,y/2-100,"100"); cout<<"Enter Point Of Rotation:X: ";
outtextxy(x/2+5,y/2-150,"150"); cin>>xr;
outtextxy(x/2+5,y/2-200,"200"); cout<<"Y: ";
cin>>yr;
} initialize();
ang = (PI * ang)/180.0;
void D_2::MultTwoMat(double temp[MAXSIZE][MAXSIZE],double setcolor(YELLOW);
temp1[MAXSIZE][MAXSIZE]) setfillstyle(SOLID_FILL,YELLOW);
{ fillellipse(x/2+xr,y/2-yr,2,2);
int i,j,k; outtextxy(x/2+xr,y/2-yr-2," Point Of Rotation");
double z[MAXSIZE][MAXSIZE];
for(i=0;i<MAXSIZE;i++) //Transformation Matrix
{ //Translate arbitrary point to origin then rotate then translate back.
for(j=0;j<MAXSIZE;j++) for(int i=0;i<MAXSIZE;i++)
z[i][j]=0; {
for(int j=0;j<MAXSIZE;j++) if(i == j)
{ {
if(i == j) TransMat[i][j] = 1;
{ InvTransMat[i][j] = 1;
TransMat[i][j] = 1; RotMat[i][j] = 1;
InvTransMat[i][j] = 1; InvRotMat[i][j] = 1;
RotMat[i][j] = 1; RefMat[i][j] = 1;
}
else }
{ else
TransMat[i][j] = 0; {
InvTransMat[i][j] = 0; TransMat[i][j] = 0;
RotMat[i][j] = 0; InvTransMat[i][j] = 0;
} RotMat[i][j] = 0;
} InvRotMat[i][j] = 0;
} RefMat[i][j] = 0;
}
TransMat[0][2] = -xr; }
TransMat[1][2] = -yr; }

InvTransMat[0][2] = xr; TransMat[0][2] = -xr;


InvTransMat[1][2] = yr; TransMat[1][2] = -yr;

RotMat[0][0] = cos(ang); InvTransMat[0][2] = xr;


RotMat[0][1] = -sin(ang); InvTransMat[1][2] = yr;
RotMat[1][0] = sin(ang);
RotMat[1][1] = cos(ang); RotMat[0][0] = cos(ang);
RotMat[0][1] = sin(ang);
Draw(GREEN); RotMat[1][0] = -sin(ang);
Print(); RotMat[1][1] = cos(ang);
MultTwoMat(InvTransMat,RotMat);
MultTwoMat(RotMat,TransMat); InvRotMat[0][0] = cos(ang);
Mult(TransMat); InvRotMat[0][1] = -sin(ang);
Draw(MAGENTA); InvRotMat[1][0] = sin(ang);
} InvRotMat[1][1] = cos(ang);

void D_2::Reflect() for(i=0;i<MAXSIZE;i++)


{ {
double ang; for(int j=0;j<MAXSIZE;j++)
double a,b,c; {
double xr,yr; if(i==j)
double TransMat[MAXSIZE][MAXSIZE]; RefMat[i][j] = pow(-
double RotMat[MAXSIZE][MAXSIZE]; 1,i)*1;
double InvTransMat[MAXSIZE][MAXSIZE]; else
double InvRotMat[MAXSIZE][MAXSIZE]; RefMat[i][j] = 0;
double RefMat[MAXSIZE][MAXSIZE]; }
}
closegraph();
cout<<"Enter The Line (ax+by+c=0): "; Print();
cout<<"a: "; Draw(GREEN);
cin>>a; MultTwoMat(InvTransMat,InvRotMat);
cout<<"b: "; MultTwoMat(InvRotMat,RefMat);
cin>>b; MultTwoMat(RefMat,RotMat);
cout<<"c: "; MultTwoMat(RotMat,TransMat);
cin>>c; Mult(TransMat);
if(b!=0) Draw(MAGENTA);
{ }
yr = (-c/b);
xr = 0; void D_2::Shear()
double m = -a/b; {
ang = atan(m); double ang;
double a,b,c;
} double xr,yr,shx;
else double TransMat[MAXSIZE][MAXSIZE];
{ double RotMat[MAXSIZE][MAXSIZE];
yr = 0; double InvTransMat[MAXSIZE][MAXSIZE];
xr = (-c/a); double InvRotMat[MAXSIZE][MAXSIZE];
ang = 22.0/14.0; // Angle = PI/2 double ShearMat[MAXSIZE][MAXSIZE];
}
closegraph();
cout<<"Enter The Line (ax+by+c=0): ";
initialize(); cout<<"a: ";
//Transformation Matrix cin>>a;
//Translate arbitrary point to origin then rotate then translate back. cout<<"b: ";
for(int i=0;i<MAXSIZE;i++) cin>>b;
{ cout<<"c: ";
for(int j=0;j<MAXSIZE;j++) cin>>c;
{ cout<<"Enter Shearing Factor Along X-Axis: ";
cin>>shx; double InvTransMat[MAXSIZE][MAXSIZE];
if(b!=0)
{ closegraph();
yr = (-c/b); cout<<"Enter The Scaling Factor Along X-Axis: ";
xr = 0; cin>>sx;
double m = -a/b; cout<<"Enter The Scaling Factor Along Y-Axis: ";
ang = atan(m); cin>>sy;
cout<<"Enter Point Of Scaling:X: ";
} cin>>xr;
else cout<<"Y: ";
{ cin>>yr;
yr = 0; initialize();
xr = (-c/a);
ang = 22.0/14.0; // Angle = PI/2 //Transformation Matrix
} for(int i=0;i<MAXSIZE;i++)
{
for(int j=0;j<MAXSIZE;j++)
initialize(); {
if(i == j)
//Transformation Matrix {
for(int i=0;i<MAXSIZE;i++) TransMat[i][j] = 1;
{ InvTransMat[i][j] = 1;
for(int j=0;j<MAXSIZE;j++) ScaleMat[i][j] = 1;
{ }
if(i == j) else
{ {
TransMat[i][j] = 1; TransMat[i][j] = 0;
InvTransMat[i][j] = 1; InvTransMat[i][j] = 0;
RotMat[i][j] = 1; ScaleMat[i][j] = 0;
InvRotMat[i][j] = 1; }
ShearMat[i][j] = 1; }
}
}
else TransMat[0][2] = -xr;
{ TransMat[1][2] = -yr;
TransMat[i][j] = 0;
InvTransMat[i][j] = 0; InvTransMat[0][2] = xr;
RotMat[i][j] = 0; InvTransMat[1][2] = yr;
InvRotMat[i][j] = 0;
ShearMat[i][j] = 0; ScaleMat[0][0] = sx;
} ScaleMat[1][1] = sy;
}
} Draw(GREEN);
Print();
TransMat[0][2] = -xr; MultTwoMat(InvTransMat,ScaleMat);
TransMat[1][2] = -yr; MultTwoMat(ScaleMat,TransMat);
Mult(TransMat);
InvTransMat[0][2] = xr; Draw(MAGENTA);
InvTransMat[1][2] = yr; }
void D_2::Scale_Dir()
RotMat[0][0] = cos(ang); {
RotMat[0][1] = sin(ang); double sx,sy;
RotMat[1][0] = -sin(ang); double ang;
RotMat[1][1] = cos(ang); const double PI = 22.0/7;
double RotMat[MAXSIZE][MAXSIZE];
InvRotMat[0][0] = cos(ang); double ScaleMat[MAXSIZE][MAXSIZE];
InvRotMat[0][1] = -sin(ang); double InvRotMat[MAXSIZE][MAXSIZE];
InvRotMat[1][0] = sin(ang);
InvRotMat[1][1] = cos(ang); closegraph();
cout<<"Enter The Scaling Factor Along X-Axis: ";
ShearMat[0][1] = shx; cin>>sx;
cout<<"Enter The Scaling Factor Along Y-Axis: ";
Print(); cin>>sy;
Draw(GREEN); cout<<"Enter The Direction Of Scaling: ";
MultTwoMat(InvTransMat,InvRotMat); cin>>ang;
MultTwoMat(InvRotMat,ShearMat); ang = (PI * ang)/180.0;
MultTwoMat(ShearMat,RotMat); initialize();
MultTwoMat(RotMat,TransMat);
Mult(TransMat);
Draw(MAGENTA); //Transformation Matrix
} for(int i=0;i<MAXSIZE;i++)
{
void D_2::Scale_Fixed() for(int j=0;j<MAXSIZE;j++)
{ {
double sx,sy; if(i == j)
double xr,yr; {
double TransMat[MAXSIZE][MAXSIZE]; RotMat[i][j] = 1;
double ScaleMat[MAXSIZE][MAXSIZE]; InvRotMat[i][j] = 1;
ScaleMat[i][j] = 1; closegraph();
} break;
else case 4:
{ cleardevice();
RotMat[i][j] = 0; D1.Scale_Dir();
InvRotMat[i][j] = 0; getch();
ScaleMat[i][j] = 0; closegraph();
} break;
} case 5:
} cleardevice();
D1.Rotate();
RotMat[0][0] = cos(ang); getch();
RotMat[0][1] = sin(ang); closegraph();
RotMat[1][0] = -sin(ang); break;
RotMat[1][1] = cos(ang); case 6:
cleardevice();
InvRotMat[0][0] = cos(ang); D1.Reflect();
InvRotMat[0][1] = -sin(ang); getch();
InvRotMat[1][0] = sin(ang); closegraph();
InvRotMat[1][1] = cos(ang); break;

ScaleMat[0][0] = sx; case 7:


ScaleMat[1][1] = sy; cleardevice();
D1.Shear();
Draw(GREEN); getch();
Print(); closegraph();
MultTwoMat(RotMat,ScaleMat); break;
MultTwoMat(ScaleMat,InvRotMat); case 8:
Mult(InvRotMat); return;
Draw(MAGENTA); default:
} cout<<"WRONG CHOICE.";
getch();
void main() break;
{ }
D_2 D1; }while(1);
D1.DrawCord(); }
getch();
int ch; Program for 3-D Transformation

D1.GetPoints(); #include<iostream.h>
D1.Draw(GREEN); #include<dos.h>
getch(); #include<stdio.h>
#include<math.h>
do #include<conio.h>
{ #include<graphics.h>
closegraph(); #include<process.h>
clrscr();
cout<<"1.To ReDraw The Triangle."; int gd=DETECT,gm;
cout<<"2.Translate The Triangle."; double x1,x2,y1,y2;
cout<<"3.Scaling The Triangle About Fixed Point.";
cout<<"4.Scaling The Triangle In A Direction."; void show_message()
cout<<"5.Rotating The Triangle About Arbitrary {
Point."; char *mess[]={"-","=","[","
cout<<"6.Reflecting The Triangle About Arbitrary ","3","D","-","T","r","a","n","s","f","o","r","m","a","t","i","o","n","
Line."; ","]","=","-"};
cout<<"7.Shearing Of The Triangle."; int xx=28,xxx=52,i,j;
cout<<"8.Exit."; _setcursortype(_NOCURSOR);
cout<<"Enter The Choice: "; for(i=0,j=24;i<15,j>=12;i++,j--)
cin>>ch; {
D1.initialize(); gotoxy(xx,1);
switch(ch) cout<<mess[i];
{ xx++;
case 1: gotoxy(xxx,1);
D1.GetPoints(); cout<<mess[j];
D1.Draw(GREEN); xxx--;
getch(); delay(50);
break; }
_setcursortype(_NORMALCURSOR);
case 2: }
cleardevice();
D1.Translate();
getch(); void draw_cube(double edge[20][3])
closegraph(); {
break; initgraph(&gd,&gm,"..\bgi");
case 3: int i;
cleardevice(); clearviewport();
D1.Scale_Fixed(); for(i=0;i<19;i++)
getch(); {
x1=edge[i][0]+edge[i][2]*(cos(2.3562)); edge[i][2]=temp*sin(theta)
y1=edge[i][1]-edge[i][2]*(sin(2.3562)); +temp1*cos(theta);
x2=edge[i+1][0]+edge[i+1][2]*(cos(2.3562)); }
y2=edge[i+1][1]-edge[i+1][2]*(sin(2.3562)); draw_cube(edge);
line(x1+320,240-y1,x2+320,240-y2); break;
}
line(320,240,320,25); case 2:
line(320,240,550,240); cout<<" " Enter The Angle
line(320,240,150,410); ":=";
getch(); cin>>theta;
closegraph(); theta=(theta*3.14)/180;
} for(i=0;i<20;i++)
{
void scale(double edge[20][3]) edge[i][1]=edge[i][1];
{ temp=edge[i][0];
double a,b,c; temp1=edge[i][2];
int i; edge[i][0]=temp*cos(theta)
cout<<" +temp1*sin(theta);
" Enter The Scaling Factors ":="; edge[i][2]=-temp*sin(theta)
cin>>a>>b>>c; +temp1*cos(theta);
initgraph(&gd,&gm,"..\bgi"); }
clearviewport(); draw_cube(edge);
for(i=0;i<20;i++) break;
{
edge[i][0]=edge[i][0]*a; case 3:
edge[i][1]=edge[i][1]*b; cout<<"
edge[i][2]=edge[i][2]*c; " Enter The Angle ":=";
} cin>>theta;
draw_cube(edge); theta=(theta*3.14)/180;
closegraph(); for(i=0;i<20;i++)
} {
edge[i][2]=edge[i][2];
void translate(double edge[20][3]) temp=edge[i][0];
{ temp1=edge[i][1];
int a,b,c; edge[i][0]=temp*cos(theta)-
int i; temp1*sin(theta);
cout<<" edge[i][1]=temp*sin(theta)
" Enter The Translation Factors ":="; +temp1*cos(theta);
cin>>a>>b>>c; }
initgraph(&gd,&gm,"..\bgi"); draw_cube(edge);
clearviewport(); break;
for(i=0;i<20;i++) }
{ }
edge[i][0]+=a;
edge[i][0]+=b; void reflect(double edge[20][3])
edge[i][0]+=c; {
} int ch;
draw_cube(edge); int i;
closegraph(); clrscr();
} cout<<" -=[ Reflection About ]=-";
cout<<" 1:==>" X-Axis "";
void rotate(double edge[20][3]) cout<<" 2:==>" Y-Axis "";
{ cout<<" 3:==>" Z-Axis "";
int ch; cout<<" " Enter Your Choice ":=";
int i; cin>>ch;
double temp,theta,temp1; switch(ch)
clrscr(); {
cout<<" case 1:
-=[ Rotation About ]=-"; for(i=0;i<20;i++)
cout<<" 1:==>" X-Axis ""; {
cout<<" 2:==>" Y-Axis ""; edge[i][0]=edge[i][0];
cout<<" 3:==>" Z-Axis ""; edge[i][1]=-edge[i][1];
cout<<" " Enter Your Choice ":="; edge[i][2]=-edge[i][2];
cin>>ch; }
switch(ch) draw_cube(edge);
{ break;
case 1:
cout<<" " Enter The Angle case 2:
":="; for(i=0;i<20;i++)
cin>>theta; {
theta=(theta*3.14)/180; edge[i][1]=edge[i][1];
for(i=0;i<20;i++) edge[i][0]=-edge[i][0];
{ edge[i][2]=-edge[i][2];
edge[i][0]=edge[i][0]; }
temp=edge[i][1]; draw_cube(edge);
temp1=edge[i][2]; break;
edge[i][1]=temp*cos(theta)-
temp1*sin(theta); case 3:
for(i=0;i<20;i++) void main()
{ {
edge[i][2]=edge[i][2]; int choice;
edge[i][0]=-edge[i][0]; double edge[20][3]=
edge[i][1]=-edge[i][1]; {
} 100,0,0,
draw_cube(edge); 100,100,0,
break; 0,100,0,
} 0,100,100,
} 0,0,100,
0,0,0,
void perspect(double edge[20][3]) 100,0,0,
{ 100,0,100,
int ch; 100,75,100,
int i; 75,100,100,
double p,q,r; 100,100,75,
clrscr(); 100,100,0,
cout<<" -=[ Perspective Projection 100,100,75,
About ]=-"; 100,75,100,
cout<<" 1:==>" X-Axis ""; 75,100,100,
cout<<" 2:==>" Y-Axis ""; 0,100,100,
cout<<" 3:==>" Z-Axis ""; 0,100,0,
cout<<" " Enter Your Choice ":="; 0,0,0,
cin>>ch; 0,0,100,
switch(ch) 100,0,100
{ };
case 1: while(1)
cout<<" {
" Enter P ":="; clrscr();
cin>>p; show_message();
for(i=0;i<20;i++) cout<<" 1:==>" Draw Cube "";
{ cout<<" 2:==>" Scaling "";
edge[i][0]=edge[i][0]/(p*edge[i] cout<<" 3:==>" Rotation "";
[0]+1); cout<<" 4:==>" Reflection "";
edge[i][1]=edge[i][1]/(p*edge[i] cout<<" 5:==>" Translation "";
[0]+1); cout<<" 6:==>" Perspective Projection "";
edge[i][2]=edge[i][2]/(p*edge[i] cout<<" 7:==>" Exit "";
[0]+1); cout<<" " Enter Your Choice ":=";
} cin>>choice;
draw_cube(edge); switch(choice)
break; {
case 1:
case 2: draw_cube(edge);
cout<<" break;
" Enter Q ":=";
cin>>q; case 2:
for(i=0;i<20;i++) scale(edge);
{ break;
edge[i][1]=edge[i][1]/(edge[i]
[1]*q+1); case 3:
edge[i][0]=edge[i][0]/(edge[i] rotate(edge);
[1]*q+1); break;
edge[i][2]=edge[i][2]/(edge[i]
[1]*q+1); case 4:
} reflect(edge);
draw_cube(edge); break;
break;
case 5:
case 3: translate(edge);
cout<<" break;
" Enter R ":=";
cin>>r; case 6:
for(i=0;i<20;i++) perspect(edge);
{ break;
edge[i][2]=edge[i][2]/(edge[i]
[2]*r+1); case 7:
edge[i][0]=edge[i][0]/(edge[i] exit(0);
[2]*r+1);
edge[i][1]=edge[i][1]/(edge[i] default:
[2]*r+1); cout<<"
} a" Press A Valid Key...!!! "";
draw_cube(edge); getch();
break; break;
} }
closegraph(); closegraph();
} }
}
A Graphics Illustration Program cout<<" g. Back";
call_assign();
#include<stdio.h> ch1=getch();
#include<iostream.h> clearviewport();
#include<dos.h> if(ch1=='g')
#include<process.h> goto L2;
#include<conio.h> if(ch1=='a')
#include<graphics.h> tx=5;
#include<math.h> if(ch1=='b')
//void render(float,float,float, float,float,float, float,float,float, tx=-5;
float,float,float); if(ch1=='c')
void initialize(void); ty=5;
void firstpage(void); if(ch1=='d')
void call_first(void); ty=-5;
float intensity,alpha,thita,tempy,tempz,tempx; if(ch1=='e')
char ch='4'; tz=10;
char ch1='1'; if(ch1=='f')
char ch2='1'; tz=-10;
int pts1[5][3];
float tx,ty,tz,d=.5; for(i=0;i<5;i++)
void assign(float,float,float,float,float,float,float,float,float); {
void scan_line(float,float,float,float,float,float,float,float,float); pts[i][0]+=tx;
void drawpyramid(float,float,float,float,float,float); pts[i][1]+=ty;
void call_assign(void); pts[i][1]+=tz;
void display(void); }
void tranform(void); }
void draw(void); }
void drawscale(void); if(ch1=='3')
float pts[5][3]={-100,0,0, 0,0,45, 100,0,0, 0,0,-45, 0,130,0}; {
float pts2[5][3]={228,273,0, 305,295,0, 428,273,0, 350,250,0 ,328,143,0}; clearviewport();
float pt[5][3]={-100,0,0, 0,0,45,100,0,0,0,0-45,0,130,0}; cout<<"Enter sx:";
cin>>sx;
void main() cout<<"Enter sy:";
{ cin>>sy;
int i; for(i=0;i<5;i++)
float sx,sy,sz=1; {
struct palettetype pal; pts2[i][0]=abs(pts2[i][0]*sx+200*(1-sx));
int gd,gm; pts2[i][1]=abs(pts2[i][1]*sy+200*(1-sy));
detectgraph(&gd,&gm); }
initgraph(&gd,&gm,"d:\backups\borlandc\bgi"); drawscale();
getpalette(&pal); getch();
firstpage(); }
for(i=16;i>0;i--)
setrgbpalette(pal.colors[i],0,4*i,0); if(ch1=='2')
{
while(ch2!='4')
L1: display(); {
clearviewport();
while(ch1!='4') gotoxy(1,2);
{ cout<<"1.X-axis rotation";
ch='2'; gotoxy(1,3);
L2: call_assign(); cout<<"2.Y-axis rotation";
clearviewport(); gotoxy(1,4);
gotoxy(1,2); cout<<"3.Z-axis rotation";
cout<<"1. Translation gotoxy(1,5);
"; cout<<"4.Back";
cout<<"2. Rotation ch2=getch();
"; if(ch2=='4')
cout<<"3. Scaling break;
"; if(ch2=='1')
cout<<"4. Back {
"; alpha=0;
ch1=getch(); while(alpha<360)
if(ch1=='4') {
{ alpha=alpha+10;
clearviewport(); thita=(alpha*3.142)/180;
goto L1; initialize();
} for(i=0;i<5;i++)
{
if(ch1=='1') tempy=(pts1[i][1]*cos(thita)+pts1[i][2]*sin(thita));
{ pts1[i][2]=(pts1[i][1]*sin(thita)-pts1[i][2]*cos(thita));
clearviewport(); pts1[i][1]=tempy;
while(ch1!='4') }
{ clearviewport();
gotoxy(2,2); draw();
cout<<"a. X+"; cout<<" b. X-"; delay(100);
cout<<" c. Y+"; cout<<" d. Y-"; }
cout<<" e. Z+"; cout<<" f. Z-"; }
rectangle(300,120,580,320);
if(ch2=='2') rectangle(295,115,585,325);
{ setcolor(6);
alpha=0; settextstyle(4,HORIZ_DIR,3);
while(alpha<360) outtextxy(50,100, "OPTIONS");
{ settextstyle(3,HORIZ_DIR,1);
alpha=alpha+10; setcolor(11);
thita=(alpha*3.142)/180; outtextxy(20,150,"1. VISIBLE SURFACE DETECTION");
initialize(); outtextxy(20,190,"2. SURFACE RENDERING");
for(i=0;i<5;i++) outtextxy(20,230,"3. TRANSFORMATIONS");
{ outtextxy(20,270,"4. WIREFRAME DISPLAY");
tempz=(pts1[i][2]*cos(thita)+pts1[i][0]*sin(thita)); outtextxy(20,310,"5. EXIT");
pts1[i][0]=(pts1[i][2]*sin(thita)-pts1[i][0]*cos(thita)); settextstyle(2,HORIZ_DIR,4);
pts1[i][2]=tempz; outtextxy(400,370,"Group Memebers");
} setcolor(YELLOW);
clearviewport(); call_first();
draw(); //display();
delay(100); setcolor(WHITE);
} getch();
} cleardevice();
clearviewport();
if(ch2=='3')
{ }
alpha=0;
while(alpha<360) void display(void)
{ { while(ch!='3')
alpha=alpha+10; { clearviewport();
thita=(alpha*3.142)/180; gotoxy(2,2);
initialize(); cout<<"1. Visible Surface Detection";
for(i=0;i<5;i++) gotoxy(2,3);
{ cout<<"2. Surface Rendering";
tempx=(pts1[i][0]*cos(thita)-pts1[i][1]*sin(thita)); gotoxy(2,4);
pts1[i][1]=(pts1[i][0]*sin(thita)+pts1[i][1]*cos(thita)); cout<<"3. Transformations";
pts1[i][0]=tempx; gotoxy(2,5);
} cout<<"4. Wireframe Display";
clearviewport(); gotoxy(2,6);
draw(); cout<<"5. Exit";
delay(100); call_assign();
clearviewport(); ch=getch();
draw(); if(ch=='5')
} exit(0);
} clearviewport();
if(ch=='3')
} break;
} }
} }
closegraph(); void call_assign(void)
restorecrtmode(); {
} assign(pts[0][0],pts[0][1],pts[0][2],pts[1][0],pts[1][1],pts[1][2],pts[4][
void initialize() 0],pts[4][1],pts[4][2]);
{
pts1[0][0]=-100; assign(pts[1][0],pts[1][1],pts[1][2],pts[2][0],pts[2][1],pts[2][2],pts[4][
pts1[0][1]=-65; 0],pts[4][1],pts[4][2]);
pts1[0][2]=0;
pts1[1][0]=0; assign(pts[2][0],pts[2][1],pts[2][2],pts[3][0],pts[3][1],pts[3][2],pts[4][
pts1[1][1]=-65; 0],pts[4][1],pts[4][2]);
pts1[1][2]=-45;
pts1[2][0]=100; assign(pts[0][0],pts[0][1],pts[0][2],pts[4][0],pts[4][1],pts[4][2],pts[3][
pts1[2][1]=-65; 0],pts[3][1],pts[3][2]);
pts1[2][2]=0; }
pts1[3][0]=0; void call_first(void)
pts1[3][1]=-65; {
pts1[3][2]=45; assign(pt[0][0],pt[0][1],pt[0][2],pt[1][0],pt[1][1],pt[1][2],pt[4][0],pt[4
pts1[4][0]=0; ][1],pt[4][2]);
pts1[4][1]=65;
pts1[4][2]=0; assign(pt[1][0],pt[1][1],pt[1][2],pt[2][0],pt[2][1],pt[2][2],pt[4][0],pt[4
][1],pt[4][2]);
}
assign(pt[2][0],pt[2][1],pt[2][2],pt[3][0],pt[3][1],pt[3][2],pt[4][0],pt[4
void firstpage() ][1],pt[4][2]);
{
clearviewport(); assign(pt[0][0],pt[0][1],pt[0][2],pt[4][0],pt[4][1],pt[4][2],pt[3][0],pt[3
setcolor(WHITE); ][1],pt[3][2]);
settextstyle(2,HORIZ_DIR,5); }
outtextxy(250,15,"A Project on");
setcolor(GREEN);
settextstyle(3,HORIZ_DIR,4);
outtextxy(170,25,"PYRAMID MODELING");
{
int i;
void drawpyramid(float x1,float y1,float x2,float y2,float x3,float y3) float tempx,tempx1,tempy;
{ float m1,m2,thita,alpha;
line(x1,y1,x2,y2); alpha=0;
line(x2,y2,x3,y3);
line(x3,y3,x1,y1); tempx=x1; tempx1=x1; tempy=y1;
} m1=(y2-y1)/(x2-x1);
m2=(y3-y1)/(x3-x1);
void assign(float x1,float y1,float z1,float x2,float y2,float z2,float
x3,float y3,float z3) while((int)tempy!=(int)y2)
{ { alpha=alpha+5;
float A,B,C; thita=(alpha*3.14/180);
float temp,An,Bn,Cn,X,Y,Z; tempx=tempx-1/m1;
float Xl=-6,Yl=10,Zl=50; tempx1=tempx1-1/m2;
float templ; if(tempx<tempx1)
{
for(i=0;i+tempx<=tempx1;i++)
A=y1*(z2-z3)+y2*(z3-z1)+y3*(z1-z2); {
B=z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2); putpixel(tempx+i,tempy,intensity);
C=x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2); }
}
temp=sqrt(A*A+B*B+C*C); else
templ=sqrt(Xl*Xl+Yl*Yl+Zl*Zl); if (tempx1<tempx)
{ for(i=0;i+tempx1<=tempx;i++)
X=(float)Xl/templ; Y=(float)Yl/templ; Z=(float)Zl/templ; {
An=(A/temp); Bn=(float)B/temp; Cn=(float)C/temp; putpixel(tempx1+i,tempy,intensity);
}
intensity=15*(An*X+Bn*Y+Cn*Z); }
tempy--;
if (intensity<0) }
intensity=0;
if (intensity>15) m1=(float)(y3-y2)/(x3-x2);
intensity=15;
while((int)tempy!=(int)y3)
z1=55-z1; {
x1=x1+300+(d*z1); y1=300-y1-(d*z1); tempx=tempx-1/m1;
z2=55-z2; tempx1=tempx1-1/m2;
x2=x2+300+(d*z2); y2=300-y2-(d*z2); if(tempx<tempx1)
z3=55-z3; {
x3=x3+300+(d*z3); y3=300-y3-(d*z3); for(i=0;i+tempx<=tempx1;i++)
putpixel(tempx+i,tempy,intensity);
if(ch=='1') }
{ if(intensity==0) return; else
drawpyramid(x1,y1,x2,y2,x3,y3); {
return; for(i=0;i+tempx1<=tempx;i++)
} putpixel(tempx1+i,tempy,intensity);
if(ch=='3') }
exit(0); tempy--;
}
if(ch=='4') }
drawpyramid(x1,y1,x2,y2,x3,y3);
void draw()
if(ch=='2') { int i;
{ for(i=0;i<5;i++)
if(intensity==0) return; {
if ((y1>y2) && (y1>y3) && (y2>y3)) pts1[i][2]=50+pts1[i][2]+50;
scan_line(x1,y1,z1,x2,y2,z2,x3,y3,z3); pts1[i][0]=pts1[i][0]+300+.5*pts1[i][2];
pts1[i][1]=200+65-pts1[i][1]-.5*pts1[i][2];
if ((y1>y2) && (y1>y3) && (y3>y2)) }
scan_line(x1,y1,z1,x3,y3,z3,x2,y2,z2); line(pts1[0][0],pts1[0][1],pts1[1][0],pts1[1][1]);
line(pts1[1][0],pts1[1][1],pts1[2][0],pts1[2][1]);
if ((y2>y1) && (y2>y3) && (y1>y3)) line(pts1[2][0],pts1[2][1],pts1[3][0],pts1[3][1]);
scan_line(x2,y2,z2,x1,y1,z1,x3,y3,z3); line(pts1[3][0],pts1[3][1],pts1[0][0],pts1[0][1]);
line(pts1[0][0],pts1[0][1],pts1[4][0],pts1[4][1]);
if ((y2>y1) && (y2>y3) && (y3>y1)) line(pts1[1][0],pts1[1][1],pts1[4][0],pts1[4][1]);
scan_line(x2,y2,z2,x3,y3,z3,x1,y1,z1); line(pts1[2][0],pts1[2][1],pts1[4][0],pts1[4][1]);
line(pts1[3][0],pts1[3][1],pts1[4][0],pts1[4][1]);
if ((y3>y1) && (y3>y2) && (y1>y2)) }
scan_line(x3,y3,z3,x1,y1,z1,x2,y2,z2); void drawscale()
{
if ((y3>y1) && (y3>y2) && (y2>y1)) line(pts2[0][0],pts2[0][1],pts2[1][0],pts2[1][1]);
scan_line(x3,y3,z3,x2,y2,z2,x1,y1,z1); line(pts2[1][0],pts2[1][1],pts2[2][0],pts2[2][1]);
} line(pts2[2][0],pts2[2][1],pts2[3][0],pts2[3][1]);
} line(pts2[3][0],pts2[3][1],pts2[0][0],pts2[0][1]);
line(pts2[0][0],pts2[0][1],pts2[4][0],pts2[4][1]);
void scan_line(float x1,float y1,float z1,float x2,float y2,float z2,float line(pts2[1][0],pts2[1][1],pts2[4][0],pts2[4][1]);
x3,float y3,float z3) line(pts2[2][0],pts2[2][1],pts2[4][0],pts2[4][1]);
line(pts2[3][0],pts2[3][1],pts2[4][0],pts2[4][1]);
}

Progress bar

#include<graphics.h>
#include<conio.h>
#include<alloc.h>
#include<dos.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\tc "); //put your directory where egavga.bgi
is
void *buffer;
unsigned int size;
setbkcolor(BLUE);
line(230,330,370,330);
line(230,350,370,350);

line(226,335,226,345);

line(226,335,230,330);
line(226,345,230,350);

line(374,335,374,345);
line(374,335,370,330);
line(374,345,370,350);
outtextxy(275,365,"Loading"); //put you text here
int x=232,y=336,x1=236,y1=344;
for(int i=1;i<5;i++)
{
setfillstyle(1,RED);
bar(x,y,x1,y1);
x=x1+2;
x1=x1+6;
}
size=imagesize(232,336,256,344);
buffer=malloc(size);
getimage(232,336,256,344,buffer);
x=232;
int m=0;
while(!kbhit())
{
putimage(x,336,buffer,XOR_PUT);
x=x+2;
if(x>=350)
{
m++;
x=232;
if(m==5) // m is no of times bar moves
return;
}
putimage(x,336,buffer,XOR_PUT);
delay(20); // delay(time) is the speed of moving
bar
// less delay means fast and vice versa
}
getch();
}

You might also like