Complete Comp - Graphics File
Complete Comp - Graphics File
Navneet Sinha
August 11 , 2008
Write a program to divide the screen into four equivalent quadrants by using
graphics.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int a,b;
int gd = DETECT, gm;
initgraph(&gd, &gm, “c:\\tc\\bgi”);
a = getmaxx();
b = getmaxy();
line(a/2, 0, a/2, b);
line(0, b/2, a, b/2);
getch();
}
Navneet Sinha
August 11 ,2008
OUTPUT:
Navneet Sinha
August 18 ,2008
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
float x1, x2, y1, y2, steps, dx, dy, x, y;
xin, yin, I;
int gd = DETECT, gm;
initgraph(&gd, &gm, “c:\\tc\\bgi”);
printf(“Enter the value of x1 and y1”);
scanf(“%d%d”, &x1, &y1);
printf(“Enter the value of x2 and y2”);
scanf(“%d%d”, &x2, &y2);
dx = x2-x1;
dy = y2-y1;
if(dx>=dy)
steps = dx;
else
steps = dy;
xin = dx/steps;
yin = dy/steps;
x = x1;
y = y1;
for(I=0; I<steps; I++)
{
putpixel(x, y, 78);
x = x+xin;
y = y+yin;
}
getch();
}
Navneet Sinha
August 18 ,2008
OUTPUT:
August 25 ,2008
Navneet Sinha
Write a program to implement Bresenhem’s algorithm for drawing a line.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int x1, x2, y1, y2, dx, dy, x, y, p;
int gd = DETECT, gm;
initgraph(&gd, &gm, “c:\\tc\\bgi”);
printf(“Enter the value of x1 and y1”);
scanf(“%d%d”, &x1, &y1);
printf(“Enter the value of x2 and y2”);
scanf(“%d%d”, &x2, &y2);
dx = x2-x1;
dy = y2-y1;
p = 2*dy-dx;
x = x1;
y = y1;
while(x<=x2)
{
if(p<=0)
p = p + 2*dy;
else
{
y++;
p = p + 2*dy – 2*dx;
}
x++;
putpixel(x, y, 1);
}
getch();
}
August 25 ,2008
Navneet Sinha
OUTPUT:
September 1 ,2008
Navneet Sinha
Write a program to implement Bresenhem’s circle algorithm.
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void circlepoint(int,int,int,int);
void main()
{
int x=0,r,y,x1,y1,p,;
int gdrive=DETECT,gm;
initgraph(&gdrive,&gm,"c:\\tc\\bgi");
clrscr();
printf("enter the value of x1 and y1”);
scanf("%d%d",&x1,&y1);
printf("enter the radius");
scanf("%d",&r);
y=r;
d = 2-3r;
while(x<=y)
{
circlepoint(x,y,x1,y1);
if(d<0)
{
d=d+4*x+6;
}
else
{
d=d+4 *(x-y)+10;
y=y-1;
}
x++;
}
getch();
}
September 1 ,2008
Navneet Sinha
void circlepoint(int x ,int y,int x1,int y1 )
{
putpixel(x+x1,y+y1,1);
putpixel(y+x1,x+y1,1 );
putpixel(-y+x1,x+y1,1);
putpixel(-x+x1,y+y1,1);
putpixel(-x+x1,-y+y1,1);
putpixel(-y+x1,-x+y1,1);
putpixel(y+x1,-x+y1,1);
putpixel(x+x1,-y+y1,1);
}
OUTPUT:
September 8 ,2008
Navneet Sinha
Write a program to implement Mid Point circle algorithm.
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void circlepoint(int,int,int,int);
void main()
{
int x=0,r,y,x1,y1,p;
int gdrive=DETECT,gm;
initgraph(&gdrive,&gm,"c:\\tc\\bgi");
clrscr();
printf("enter the value of x and y");
scanf("%d%d",&x1,&y1);
printf("enter the radius");
scanf("%d",&r);
y=r;
p=1-r;
while(x<=y)
{
circlepoint(x,y,x1,y1);
if(p<=0)
p=p+(2*x)+3;
else
{
p=p+2*(x-y)+5;
y=y-1;
}
x=x+1;
}
getch();
}
September 8 ,2008
September 8 ,2008
Navneet Sinha
OUTPUT:
Navneet Sinha
September 15, 2008
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void pp(int xx,int yy);
void epoints(float xc,float yc,float x,float y)
{
pp((int)(xc+x+getmaxx()/2),(int)(-yc-y+getmaxy()/2));
pp((int)(xc-x+getmaxx()/2),(int)(-yc+y+getmaxy()/2));
pp((int)(xc+x+getmaxx()/2),(int)(-yc+y+getmaxy()/2));
pp((int)(xc-x+getmaxx()/2),(int)(-yc-y+getmaxy()/2));
}
void pp(int xx, int yy)
{
putpixel(xx,yy,7300);
}
void mdpt(float xc,float yc,float rx,float ry)
{
float x=0,y=ry,p1,p2,t1,t2;
int k;
p1=ry*ry-rx*rx*ry+0.25*rx*rx;
epoints(xc,yc,x,y);
for(k=0;(2*ry*ry*x)<=(2*rx*rx*y);k++)
{
t1=2*ry*ry*x+2*ry*ry;
t2=2*rx*rx*y-2*rx*rx;
if(p1<0)
p1=p1+t1+ry*ry;
else
{
p1=p1+t1-t2+ry*ry;
y--;
}
x++;
epoints(xc,yc,x,y);
}
Navneet Sinha
p2=ry*ry*(x+.5)*(x+.5)+rx*rx*(y-1)*(y-1)-rx*rx*ry*ry;
epoints(xc,yc,x,y);
for(k=0;y>=0;k++)
{
t1=2*ry*ry*x+2*ry*ry;
t2=2*rx*rx*y-2*rx*rx;
if(p2>0)
p2=p2-t2+rx*rx;
else
{
p2=p2+t1-t2+rx*rx;
x++;
}
y--;
epoints(xc,yc,x,y);
}
}
void main()
{
int gd=DETECT,gm;
float xc,yc,rx,ry;
initgraph(&gd,&gm, "c:\\tc\\bgi");
printf("Enter center coordinate xc : ");
scanf("%f",&xc);
printf("Enter center coordinate yc : ");
scanf("%f",&yc);
printf("Enter Radius rx : ");
scanf("%f",&rx);
printf("Enter Radius ry : ");
scanf("%f",&ry);
mdpt(xc,yc,rx,ry);
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
getch();
closegraph();
}
Navneet Sinha
Write a program to implement the Rotation on an object about the origin.
# include <iostream.h>
#include<stdio.h>
# include <conio.h>
# include <graphics.h>
# include <math.h>
char IncFlag;
int PolygonPoints[4][2] =
{{10,100},{110,100},{110,200},{10,200}};
void PolyLine()
{
int iCnt;
cleardevice();
line(0,240,640,240);
line(320,0,320,480);
for (iCnt=0; iCnt<4; iCnt++)
{
line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],
PolygonPoints[(iCnt+1)%4][0],PolygonPoints[(iCnt+1)%4][1]);
}
}
void Rotate()
{
float r,Angle;
int iCnt;
int Tx,Ty;
cout<<endl;
printf("enter the angle of rotation");
scanf("%f",&r);
Angle = r*(22.0/7.0)/180.0;
for (iCnt=0; iCnt<4; iCnt++)
{
Tx = PolygonPoints[iCnt][0];
Ty = PolygonPoints[iCnt][1];
Navneet Sinha
PolygonPoints[iCnt][0] = (Tx - 320)*cos(Angle) -
(Ty - 240)*sin(Angle) + 320;
PolygonPoints[iCnt][1] = (Tx - 320)*sin(Angle) +
(Ty - 240)*cos(Angle) + 240;
}
}
void main()
{
int gDriver = DETECT, gMode;
int iCnt;
initgraph(&gDriver, &gMode, "D:\\TC\\BGI");
for (iCnt=0; iCnt<4; iCnt++)
{
PolygonPoints[iCnt][0] += 320;
PolygonPoints[iCnt][1] = 240 - PolygonPoints[iCnt][1];
}
PolyLine();
getch();
Rotate();
PolyLine();
getch();
}
Navneet Sinha
OUTPUT:
Navneet Sinha
September 22, 2008
# include <iostream.h>
Navneet Sinha
#include<stdio.h>
# include <conio.h>
# include <graphics.h>
# include <math.h>
char IncFlag;
int PolygonPoints[4][2] =
{{10,100},{110,100},{110,200},{10,200}};
void PolyLine()
{
int iCnt;
cleardevice();
line(0,240,640,240);
line(320,0,320,480);
for (iCnt=0; iCnt<4; iCnt++)
{
line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],
PolygonPoints[(iCnt+1)%4][0],PolygonPoints[(iCnt+1)%4][1]);
}
}
void SpolyLine()
{
int iCnt;
float sx,sy;
cleardevice();
line(0,240,640,240);
line(320,0,320,480);
printf("enterthe value of sx & sy");
scanf("%f %f",&sx,&sy);
for (iCnt=0; iCnt<4; iCnt++)
{
line(PolygonPoints[iCnt][0]*sx,PolygonPoints[iCnt][1]*sy,
PolygonPoints[(iCnt+1)%4][0]*sx,PolygonPoints[(iCnt+1)%4][1]*sy);
}
}
September 22, 2008
void Rotate()
{
float r,Angle;
int iCnt;
Navneet Sinha
int Tx,Ty;
cout<<endl;
printf("enter the angle of rotation");
scanf("%f",&r);
Angle = r*(22.0/7.0)/180.0;
for (iCnt=0; iCnt<4; iCnt++)
{
Tx = PolygonPoints[iCnt][0];
Ty = PolygonPoints[iCnt][1];
PolygonPoints[iCnt][0] = (Tx - 320)*cos(Angle) -
(Ty - 240)*sin(Angle) + 320;
PolygonPoints[iCnt][1] = (Tx - 320)*sin(Angle) +
(Ty - 240)*cos(Angle) + 240;
}
}
void main()
{
int gDriver = DETECT, gMode;
int iCnt;
initgraph(&gDriver, &gMode, "D:\\TC\\BGI");
for (iCnt=0; iCnt<4; iCnt++)
{
PolygonPoints[iCnt][0] += 320;
PolygonPoints[iCnt][1] = 240 - PolygonPoints[iCnt][1];
}
PolyLine();
getch();
SpolyLine();
getch();
}
OUTPUT:
Navneet Sinha
September 22, 2008
Navneet Sinha
September 29, 2008
# include <dos.h>
# include <stdio.h>
Navneet Sinha
# include <graphics.h>
# include <iostream.h>
# include <conio.h>
# include <math.h>
struct Polygon
{
int x;
int y;
};
struct edRecord
{
int YUpper;
float XIntersect;
float dxperscan;
struct edRecord *Next;
};
void Scanfill();
void InsertEdge(Edge*,Edge*);
void BuildEdgeList(int,Nodes*);
int YNext(int);
void MakeEdgeRec(Nodes,Nodes,int,Edge*);
void BulidActiveList(int);
void UpdateActiveList(int);
void DeleteAfter(Edge*);
September 29, 2008
void ResortActiveList(void);
void ResortActiveList(int);
void main()
{
int gDriver = DETECT, gMode;
int n,xArray[12];
Navneet Sinha
int iCntr,jCntr;
initgraph(&gDriver,&gMode,"c:\\tc\\bgi");
for(iCntr=0,jCntr=0;iCntr<12;iCntr+=2,jCntr++)
xArray[iCntr] = NodesObj[jCntr].x;
for(iCntr=1,jCntr=0;iCntr<12;iCntr+=2,jCntr++)
xArray[iCntr] = NodesObj[jCntr].y;
drawpoly(6,xArray);
line(NodesObj[5].x,NodesObj[5].y,NodesObj[0].x,NodesObj[0].y); //TO
CLOSE POLYGON
getch();
Scanfill();
getch();
closegraph();
restorecrtmode();
return;
}
void Scanfill()
{
int iCntr,Scan;
//initialize edgelists with dummy nodes
Edges=new Edge*[getmaxy()];
for(iCntr=0;iCntr<getmaxy();iCntr++)
{
Edges[iCntr] = new Edge;
Edges[iCntr]->Next = NULL;
}
//initialize Active edgeList with dummy nodes
Active = new Edge;
Active->Next = NULL;
BuildEdgeList(Cntr,NodesObj);
for(Scan=0;Scan<getmaxy();Scan++)
{
BulidActiveList(Scan);
if (Active->Next != NULL)
{
Navneet Sinha
ResortActiveList(Scan);
UpdateActiveList(Scan);
ResortActiveList();
}
}
}
QEdges=edgeList;
PEdge=QEdges->Next;
while(PEdge!=NULL)
if(InitialEdge->XIntersect < PEdge->XIntersect)
PEdge=NULL;
else
{
QEdges=PEdge;
PEdge=PEdge->Next;
}
InitialEdge->Next = QEdges->Next;
QEdges->Next = InitialEdge;
}
YPrev = Vertices[Cntr-2].y;
for(iCntr=0;iCntr<Cntr;iCntr++)
{
Vertex2.x = Vertices[iCntr].x;
Vertex2.y = Vertices[iCntr].y;
if(Vertex1.y != Vertex2.y)
{
Navneet Sinha
NewEdge = new Edge;
if(Vertex1.y < Vertex2.y)
MakeEdgeRec(Vertex1,Vertex2,YNext(iCntr),NewEdge);
else
MakeEdgeRec(Vertex2,Vertex1,YPrev,NewEdge);
}
YPrev = Vertex1.y;
Vertex1.x = Vertex2.x;
Vertex1.y = Vertex2.y;
}
}
for(iCntr=iEdge->XIntersect;iCntr<=jEdge->XIntersect-1;iCntr++)
putpixel(iCntr,Scan,RED);
iEdge=jEdge->Next;
}
}
void ResortActiveList()
{
Edge *PEdge,*QEdges;
PEdge=Active->Next;
Active->Next=NULL;
while(PEdge!=NULL)
{
QEdges=PEdge->Next;
InsertEdge(Active,PEdge);
PEdge=QEdges;
}
}
September 29, 2008
PEdge = QEdges->Next;
QEdges->Next = PEdge->Next;
delete PEdge;
}
OUTPUT:
Navneet Sinha
September 29, 2008
Navneet Sinha
September 29, 2008
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
Navneet Sinha
#include<dos.h>
class Circle
{
int XCoord;
int YCoord;
int Radius;
void PlotPoint(int,int,int);
public:
Circle()
{
XCoord=0;
YCoord=0;
Radius=0;
}
void CircleMidpoint();
void InitGraphs();
void BoundryFill(int,int,int,int);
void BoundryFillRound();
};
initgraph(&gDriver,&gMode,"c:\\tc\\bgi");
errorcode = graphresult();
p=1-Radius;
while(x<y)
{
if(p<0)
x+=1;
else
{
x+=1;
y-=1;
}
if(p<0)
p=p+2*x+1;
Navneet Sinha
else
{
p=p + 2 *(x-y) + 1;
}
PlotPoint(x,y,15);
}
}
p=1-iCntr;
while(x<y)
{
if(p<0)
x+=1;
else
{
x+=1;
y-=1;
}
if(p<0)
p=p+2*x+1;
September 29, 2008
else
{
p=p + 2 *(x-y) + 1;
}
PlotPoint(x,y,5);
}
}
}
Navneet Sinha
void Circle :: BoundryFill(int x, int y,int fill,int bound)
{
int cur;
cur=getpixel(x,y);
if(cur!=bound && cur!= fill)
{
putpixel(x,y,fill);
Circle :: BoundryFill(x+1, y,fill,bound);
Circle :: BoundryFill(x-1, y,fill,bound);
Circle :: BoundryFill(x, y-1,fill,bound);
Circle :: BoundryFill(x, y+1,fill,bound);
Circle :: BoundryFill(x+1, y+1,fill,bound);
Circle :: BoundryFill(x+1, y+1,fill,bound);
Circle :: BoundryFill(x-1, y-1,fill,bound);
Circle :: BoundryFill(x-1, y+1,fill,bound);
}
}
void main()
{
Circle cObj(250,250,42);
cObj.InitGraphs();
cObj.CircleMidpoint();
cObj.BoundryFillRound();
//cObj.BoundryFill(250,250,11,15);
getch();
closegraph();
}
OUTPUT:
Navneet Sinha
September 29, 2008
# include <iostream.h>
# include <conio.h>
# include <graphics.h>
# include <math.h>
Navneet Sinha
char IncFlag;
int PolygonPoints[3][2] =
{{10,100},{110,100},{110,200}};
void PolyLine()
{
int iCnt;
cleardevice();
line(0,240,640,240);
line(320,0,320,480);
for (iCnt=0; iCnt<3; iCnt++)
{
line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],
PolygonPoints[(iCnt+1)%3][0],PolygonPoints[(iCnt+1)%3][1]);
}
}
void Reflect()
{
float Angle;
int iCnt;
int Tx,Ty;
cout<<endl;
for (iCnt=0; iCnt<3; iCnt++)
PolygonPoints[iCnt][1] = (480 - PolygonPoints[iCnt][1]);
}
void main()
{
int gDriver = DETECT, gMode;
int iCnt;
initgraph(&gDriver, &gMode, "C:\\TC\\BGI");
OUTPUT:
Navneet Sinha
September 29, 2008
# include <iostream.h>
# include <conio.h>
# include <graphics.h>
# include <math.h>
Navneet Sinha
char IncFlag;
int PolygonPoints[3][2] =
{{10,100},{110,100},{110,200}};
void PolyLine()
{
int iCnt;
cleardevice();
line(0,240,640,240);
line(320,0,320,480);
for (iCnt=0; iCnt<3; iCnt++)
{
line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],
PolygonPoints[(iCnt+1)%3][0],PolygonPoints[(iCnt+1)%3][1]);
}
}
void Reflect()
{
float Angle;
int iCnt;
int Tx,Ty;
cout<<endl;
for (iCnt=0; iCnt<3; iCnt++)
PolygonPoints[iCnt][0] = (640 - PolygonPoints[iCnt][0]);
}
void main()
{
int gDriver = DETECT, gMode;
int iCnt;
initgraph(&gDriver, &gMode, "C:\\TC\\BGI");
OUTPUT:
Navneet Sinha
October 1, 2008
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
Navneet Sinha
#include<process.h>
int pixels[2][4];
float xn1,xn2,yn1,yn2,x3,y3,m;
void show_quadrant()
{
cleardevice();
rectangle(120,40,320,240);
rectangle(320,40,520,240);
rectangle(120,240,320,440);
rectangle(320,240,520,440);
for(int i=130;i<=510;i+=10)
{
if(i==320)
continue;
outtextxy(i,237,"+");
}
for(i=50;i<=430;i+=10)
{
if(i==240)
continue;
outtextxy(317,i,"-");
}
outtextxy(310,230,"O");
outtextxy(530,240,"X");
outtextxy(320,450,"-Y");
outtextxy(100,240,"-X");
outtextxy(320,30,"Y");
}
October 1, 2008
void su_co(int x1,int y1,int x2,int y2,int xmin,int ymin,int xmax,int ymax)
{
int i,j,fl;
for(i=0;i<2;i++)
for(j=0;j<4;j++)
pixels[i][j]=0;
if(y1>ymax)
pixels[0][0]=1;
Navneet Sinha
if(y1<ymin)
pixels[0][1]=1;
if(x1>xmax)
pixels[0][2]=1;
if(x1<xmin)
pixels[0][3]=1;
if(y2>ymax)
pixels[1][0]=1;
if(y2<ymin)
pixels[1][1]=1;
if(x2>xmax)
pixels[1][2]=1;
if(x2<xmin)
pixels[1][3]=1;
for(j=0;j<4;j++)
{
if(pixels[0][j]==0&&pixels[1][j]==0)
continue;
if(pixels[0][j]==1&&pixels[1][j]==1)
{
fl=3;
break;
}
fl=2;
}
switch(fl)
{
case 1:
line(320+x1,240-y1,320+x2,240-y2);
break;
October 1, 2008
case 3:
cout<<"\n\n\a\" Line Is Not Visible...:-(";
break;
case 2:
m=(y2-y1)/(x2-x1);
xn1=x1;
yn1=y1;
xn2=x2;
Navneet Sinha
yn2=y2;
if(pixels[0][0]==1)
{
xn1=x1+(ymax-y1)/m;
yn1=ymax;
}
if(pixels[0][1]==1)
{
xn1=x1+(ymin-y1)/m;
yn1=ymin;
}
if(pixels[0][2]==1)
{
yn1=y1+(xmax-x1)*m;
xn1=xmax;
}
if(pixels[0][3]==1)
{
yn1=y1+(xmin-x1)*m;
xn1=xmin;
}
if(pixels[1][0]==1)
{
xn2=x2+(ymax-y2)/m;
yn2=ymax;
}
if(pixels[1][1]==1)
{
xn2=x2+(ymin-y2)/m;
October 1, 2008
yn2=ymin;
}
if(pixels[1][2]==1)
{
yn2=y2+(xmax-x2)*m;
xn2=xmax;
}
if(pixels[1][3]==1)
{
yn2=y2+(xmin-x2)*m;
Navneet Sinha
xn2=xmin;
}
line(320+xn1,240-yn1,320+xn2,240-yn2);
break;
}
}
void midpt(int x1,int y1,int x2,int y2,int xmin,int ymin,int xmax,int ymax)
{
int fl=1;
int i,j;
int ox1=x1,ox2=x2,oy1=y1,oy2=y2;
for(i=0;i<2;i++)
for(j=0;j<4;j++)
pixels[i][j]=0;
if(y1>ymax)
pixels[0][0]=1;
if(y1<ymin)
pixels[0][1]=1;
if(x1>xmax)
pixels[0][2]=1;
if(x1<xmin)
pixels[0][3]=1;
if(y2>ymax)
pixels[1][0]=1;
if(y2<ymin)
pixels[1][1]=1;
October 1, 2008
if(x2>xmax)
pixels[1][2]=1;
if(x2<xmin)
pixels[1][3]=1;
for(j=0;j<4;j++)
{
if(pixels[0][j]==0&&pixels[1][j]==0)
continue;
if(pixels[0][j]==1&&pixels[1][j]==1)
Navneet Sinha
{
fl=3;
break;
}
fl=2;
}
switch(fl)
{
case 1:
line(320+x1,240-y1,320+x2,240-y2);
break;
case 3:
cout<<"\n\n\a\" Line Is Not Visible...:-(";
break;
case 2:
xn1=x1;
yn1=y1;
xn2=x2;
yn2=y2;
fl=0;
x3=x1;
y3=y1;
while(1)
{
if(!(y1>ymax || y1<ymin || x1>xmax || x1<xmin) && (x3 || y3)!=0.1)
break;
October 1, 2008
x3=(x1+x2)/2;
y3=(y1+y2)/2;
if(!(y3>ymax || y3<ymin || x3>xmax || x3<xmin))
fl=1;
else
fl=0;
if(fl)
{
x2=x3;
y2=y3;
}
else
Navneet Sinha
{
x1=x3;
y1=y3;
}
}
xn1=x3;
yn1=y3;
fl=0;
x1=ox1;
x2=ox2;
y1=oy1;
y2=oy2;
x3=x2;
y3=y2;
while(1)
{
if(!(y2>ymax || y2<ymin || x2>xmax || x2<xmin) && (x3 || y3)!=0.1)
break;
x3=(x1+x2)/2;
y3=(y1+y2)/2;
if(fl)
October 1, 2008
{
x1=x3;
y1=y3;
}
else
{
x2=x3;
y2=y3;
}
}
xn2=x3;
yn2=y3;
line(320+xn1,240-yn1,320+xn2,240-yn2);
Navneet Sinha
break;
}
}
void show_message()
{
char *mess[]={"-","=","["," ","L","i","n","e"," ","C","l","i",
"p","p","i","n","g"," ","]","=","-",};
int xx=29,xxx=50,i,j;
_setcursortype(_NOCURSOR);
for(i=0,j=21;i<13,j>=11;i++,j--)
{
gotoxy(xx,1);
cout<<mess[i];
xx++;
gotoxy(xxx,1);
cout<<mess[j];
xxx--;
delay(50);
}
_setcursortype(_NORMALCURSOR);
}
October 1, 2008
void main()
{
clrscr();
int gd=DETECT,gm,i,j;
int xmin,ymin,xmax,ymax,x1,y1,x2,y2;
int choice,ed[20],num;
show_message();
cout<<"\n\n\t\t\" Enter The Co-Ordinates Of The Clipping Window.\"";
cout<<"\n\n\t\t\" Enter X(min) & Y(min) \":=";
cin>>xmin>>ymin;
cout<<"\n\t\t\" Enter X(max) & Y(max) \":=";
cin>>xmax>>ymax;
October 1, 2008
show_quadrant();
line(320+xmin,240-ymin,320+xmin,240-ymax);
line(320+xmin,240-ymax,320+xmax,240-ymax);
line(320+xmax,240-ymax,320+xmax,240-ymin);
line(320+xmax,240-ymin,320+xmin,240-ymin);
su_co(x1,y1,x2,y2,xmin,ymin,xmax,ymax);
getch();
break;
case 2:
initgraph(&gd,&gm,"..\\bgi");
clearviewport();
show_quadrant();
line(320+xmin,240-ymin,320+xmin,240-ymax);
line(320+xmin,240-ymax,320+xmax,240-ymax);
Navneet Sinha
line(320+xmax,240-ymax,320+xmax,240-ymin);
line(320+xmax,240-ymin,320+xmin,240-ymin);
line (320+x1,240-y1,320+x2,240-y2);
getch();
cleardevice();
show_quadrant();
line(320+xmin,240-ymin,320+xmin,240-ymax);
line(320+xmin,240-ymax,320+xmax,240-ymax);
line(320+xmax,240-ymax,320+xmax,240-ymin);
line(320+xmax,240-ymin,320+xmin,240-ymin);
midpt(x1,y1,x2,y2,xmin,ymin,xmax,ymax);
getch();
break;
case 3:
exit(0);
default:
cout<<"\n\t\a\" Press A Valid Key...!!! \"";
getch();
main();
break;
}
closegraph();
}
October 1, 2008
OUTPUT:
Navneet Sinha
October 1, 2008
Navneet Sinha
October 1, 2008
Navneet Sinha
October 1, 2008
Navneet Sinha
October 8, 2008
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
#define ROUND(a) ((int)(a+0.5))
Navneet Sinha
#define n 4
void main()
{
int gd=DETECT,gm;
int left,top,right,bottom;
int x1,x2,y1,y2;
int maxx, maxy;
/* our polygon array */
int poly[10];
void clipline(dcpt,dcpt,wcpt2,wcpt2);
clrscr();
October 8, 2008
initgraph(&gd,&gm,"c:\\tc30\\bgi");
maxx = getmaxx()/4;
maxy = getmaxy()/4;
Navneet Sinha
poly[2] = maxx - 10; /* 2nd */
poly[3] = 10;
rectangle(20,25,80,125);
wcpt2 pt1,pt2;
dcpt winmin,winmax;
winmin.x=20;
winmin.y=25;
winmax.x=80;
winmax.y=125;
pt1.x=20;
pt1.y=maxy/2;
pt2.x=maxx-10;
pt2.y=10;
October 8, 2008
// clipline(winmin,winmax,pt1,pt2);
int i=0;
for(int index=0;index<n;index++)
{
if(index==n-1)
{
pt1.x=poly[i];
pt1.y=poly[i+1];
Navneet Sinha
i=0;
pt2.x=poly[i];
pt2.y=poly[i+1];
clipline(winmin,winmax,pt1,pt2);
}
else
{
pt1.x=poly[i];
pt1.y=poly[i+1];
pt2.x=poly[i+2];
pt2.y=poly[i+3];
clipline(winmin,winmax,pt1,pt2);
}
i+=2;
}
pt1.x=poly[i];
pt1.y=poly[i+1];
clipline(winmin,winmax,pt1,pt2);
getch();
}
October 8, 2008
while(!done)
{
code1 = encode(p1,winmin,winmax);
code2 = encode(p2,winmin,winmax);
if(ACCEPT(code1,code2))
{
draw = 1;
October 8, 2008
done = 1;
}
else if(REJECT(code1,code2))
done = 1;
else if(INSIDE(code1))
{
swappts(&p1,&p2);
swapcode(&code1,&code2);
}
if(code1 & LEFT_EDGE)
{
Navneet Sinha
p1.y += (winmin.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x);
p1.x = winmin.x;
}
else if(code1 & RIGHT_EDGE)
{
p1.y += (winmax.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x);
p1.x = winmax.x;
}
else if(code1 & TOP_EDGE)
{
if(p2.x != p1.x)
p1.x += (winmin.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y);
p1.y = winmin.y;
}
else if(code1 & BOTTOM_EDGE)
{
if(p2.x != p1.x)
p1.x += (winmax.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y);
p1.y = winmax.y;
}
}
if(draw)
{
setcolor(5);
line(p1.x,p1.y,p2.x,p2.y);
}
}
October 8, 2008
OUTPUT:
Navneet Sinha
Navneet Sinha