You are on page 1of 6

#include<graphics.

h>
#include<conio.h>
#include<iostream.h>
#include<math.h>
void dda(float,float,float,float,int);
void bresdd(float,float,float,float,int);
void circ_midpt(int x,int y,int rad,int color);
void circ_bre(int x,int y,int rad,int color);
void mdisplay(int,int,int,int,int);
void flodFill(int, int, int, int);
void ellipse(int xc,int yc,int rx,int ry,int col);
void parabola();
void semi(int xc,int yc,int r,int col);
void main()
{
int gdriver=DETECT,gmode,gerror;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
bresdd(0,400,640,400,15);
dda(52,0,10,80,6);
dda(450,0,500,80,6);
semi(525,150,12,14);
semi(525,150,11,14);
semi(525,150,10,14);
circ_midpt(200,385,15,3);
semi(525,150,9,14);
semi(525,150,8,14);
semi(525,150,7,14);
circ_midpt(100,385,15,3);
semi(525,150,6,14);
semi(525,150,5,14);
bresdd(65,360,100,355,9);
dda(235,360,200,355,9);
semi(525,150,4,14);
semi(525,150,3,14);
dda(65,385,65,360,9);
dda(235,385,235,360,9);
semi(525,150,2,14);
semi(525,150,1,14);
circ_bre(390,60,15,15);
circle(390,60,15);
flodFill(390,60,15,0);
circ_bre(100,385,5,3);
circ_bre(200,385,5,3);
ellipse(555,125,50,25,7);
dda(65,385,85,385,9);
dda(605,400,605,120,7);
dda(585,400,585,145,7);
dda(115,385,185,385,9);
dda(215,385,235,385,9);
bresdd(100,355,115,335,9);
bresdd(200,355,185,335,9);
dda(115,335,185,335,9);
dda(106,355,118,338,9);
dda(118,338,118,355,9);
dda(106,355,118,355,9);
dda(194,355,182,338,9);
bresdd(179,355,152,355,9);
dda(182,338,182,355,9);
dda(194,355,182,355,9);
dda(121,338,121,355,9);

dda(121,338,148,338,9);
dda(121,355,148,355,9);
dda(148,355,148,338,9);
dda(179,338,179,355,9);
bresdd(179,338,152,338,9);
dda(152,355,152,338,9);
parabola();
getch();
closegraph();
}
void flodFill(int x, int y, int fill, int old)
{
if(getpixel(x,y) == old)
{
putpixel(x,y,fill);
flodFill(x+1,y,fill,old);
flodFill(x-1,y,fill,old);
flodFill(x,y+1,fill,old);
flodFill(x,y-1,fill,old);
}
}
void semi(int xc,int yc,int r,int col)
{
int x,y;
float d;
x=0;
y=r;
d=3-2*r;
do
{
putpixel(xc+x,yc+y,col);
putpixel(xc-x,yc+y,col);
putpixel(xc+y,yc+x,col);
putpixel(xc-y,yc+x,col);
putpixel(xc-y,yc-x,col);
if(d<=0)
{
x=x+1;
d=d+4*x+6;
}
else
{
d=d+4*(x-y)+10;
x=x+1;
y=y-1;
}
}while(x<y);
}
void circ_midpt(int x,int y,int rad,int color)
{
int x1,y1;
float dp;
x1 = 0;
y1 = rad;
dp = 1 - rad;

while(x1<=y1)
{
if(dp<=0)
{
x1++;
dp += (2 * x1) + 1;
}
else
{
x1++;
y1--;
dp += 2*(x1-y1)+1;
}
mdisplay(x1,y1,x,y,color);
}
}
void mdisplay (int x1,int y1,int x,int y,int color)
{
putpixel(x1+x,y1+y,color);
putpixel(x1+x,y-y1,color);
putpixel(x-x1,y1+y,color);
putpixel(x-x1,y-y1,color);
putpixel(x+y1,y+x1,color);
putpixel(x+y1,y-x1,color);
putpixel(x-y1,y+x1,color);
putpixel(x-y1,y-x1,color);
}
void circ_bre(int x,int y,int rad,int color)
{
float dp;
int x1,y1;
x1 = 0;
y1 = rad;
dp = 3 - 2*rad;
while(x1<=y1)
{
if(dp<=0)
dp += (4 * x1) + 6;
else
{
dp += 4*(x1-y1)+10;
y1--;
}
x1++;
mdisplay(x1,y1,x,y,color);
}
}
void parabola()
{
double end_x = 500;
double end_y = 100;
double x = 0;
double y = 0;
int prev_x=0;
int prev_y=0;
for (x=-1*(int)(end_x/1); x<(int)(end_x/2);x+=.1)
{

y = .02*(x*x);
putpixel((int)(end_x-x) ROWN);
putpixel((int)(end_x-x) ROWN);
putpixel((int)(end_x-x) ROWN);
prev_x = (int)(end_x - x)
prev_y = (int)(end_y - y)
}

(int)(end_x/1.3), (int)(end_y-y) - (int)(end_y/6.0), B


(int)(end_x/2.0), (int)(end_y-y) - (int)(end_y/6.0), B
(int)(end_x/4.2), (int)(end_y-y) - (int)(end_y/6.0), B
- (int)(end_x/2.0);
- (int)(end_y/2.0);

}
void dda (float x1,float y1,float x2,float y2,int col)
{
float dx,dy,x=x1,y=y1,m;
int i;
dx=x2-x1;
dy=y2-y1;
if (abs(dx)>=abs(dy))
m=abs(dx);
else
m=abs(dy);
dx=(x2-x1)/m;
dy=(y2-y1)/m;
for(i=1;i<=m;i++)
{
x=x+dx;
y=y+dy;
putpixel(x,y,col);
}
}
void bresdd(float x1,float y1,float x2,float y2,int col)
{
int S,O,End;
int P;
int dx = abs(x1 - x2);
int dy = abs(y1 - y2);
float Slope;
int PInc,NInc,XInc,YInc; char IncFlag;
if (dx == 0) //Slope Infinite
{
}
else
{
Slope = (float)(y1 - y2) / (x1 - x2);
if (Slope>-1 && Slope<1)
{
IncFlag = 'X';
PInc = 2 * (dy - dx);
NInc = 2 * dy;
P = 2 * dy - dx;
if (x1>x2)
{
S = x2;
O = y2;
End = x1;
}
else

{
S = x1;
O = y1;
End = x2;
}
}
else
{
IncFlag = 'Y';
PInc = 2 * (dx - dy);
NInc = 2 * dx;
P = 2 * dx - dy;
if (y1 > y2)
{
O = x2;
S = y2;
End = y1;
}
else
{
O = x1;
S = y1;
End = y2;
}
}
if (IncFlag == 'X')
putpixel(S,O,col);
else
putpixel(O,S,col);
while (S <= End)
{
S++;
if (P<0)
P = P + NInc;
else
{
P = P + PInc;
if (Slope>0.0)
O++;
else
O--;
}
if (IncFlag == 'X')
putpixel(S,O,col);
else
putpixel(O,S,col);
}
}
}
void ellipse(int xc,int yc,int rx,int ry,int col)
{
int x=0;
int y=ry;
float p1,p2;
p1=(ry*ry)-(rx*rx*ry)+((ry*ry)/4);
do
{
putpixel(xc+x,yc+y,col);
putpixel(xc-x,yc+y,col);

putpixel(xc+x,yc-y,col);
putpixel(xc-x,yc-y,col);
if(p1<=0)
{
x++;
p1=p1+(2.0*ry*ry*x)+(ry*ry);
}
else
{
x++;
y--;
p1=p1+(2.0*ry*ry*x)-(2.0*rx*rx*y)+(ry*ry);
}
}while((2.0*ry*ry*x)<=(2.0*rx*rx*y));
x=rx;
y=0;
p2=(rx*rx)+2.0*(ry*ry*rx)+((ry*ry)/4);
do
{
putpixel(xc+x,yc+y,col);
putpixel(xc-x,yc+y,col);
putpixel(xc+x,yc-y,col);
putpixel(xc-x,yc-y,col);
if(p2>0)
{
y++;
p2=p2+(rx*rx)-(2.0*rx*rx*y);
}
else
{
y++;
x--;
p2=p2+(2.0*ry*ry*x)-(2.0*rx*rx*y)+(rx*rx);
}
}while((2.0*ry*ry*x)>(2.0*rx*rx*y));
}