Sie sind auf Seite 1von 32

Program1 WPA to use pixel,circle,line,rectangle,ellipse

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax;

/* initialize graphics and local variables */


initgraph(&gdriver, &gmode, "c:\\turboc3\\BGI");

/* read result of initialization */


errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
/* draw a diagonal line */
setcolor(11);
line(500,20, 500, 300);
cout<<"\n\t Pixel AT(500,20)=>"<<getpixel(500,20);
/* draw the circle */
setcolor(RED);
circle(100, 100, 50);
/* draw a rectangle */
setcolor(22);
rectangle(200,50,300,150);
cout<<"\n\t\t Pixel AT(200,200)=>"<<getpixel(200,200);
/* draw ellipse */
setcolor(33);
ellipse(400,100, 0,360,20, 60);
/* clean up */
getch();
closegraph();
return 0;
}

1
OUTPUT

2
Program 5 program to fill polygon using Flood Fill
//Program for Flood Fill Polygon Filling Algorithm
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>
#include<iostream.h>
void FloodFillAlgo(int x,int y,int new_color,int old_color);
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
/* our polygon array */
int poly[10]={100,100,150,100,150,150,100,150,100,100};
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{ cout<<"Graphics error: %s\n"<<grapherrormsg(errorcode);
cout<<"Press any key to halt:";
getch();
/* terminate with an error code */
exit(1);
}
/* draw the polygon */
drawpoly(5, poly);
// Fill Poly
FloodFillAlgo(poly[0]+10,poly[1]+10,11,0);
/* clean up */
getch();
closegraph();
return 0;
}
void FloodFillAlgo(int x,int y,int new_color,int old_color)
{
if(getpixel(x,y)==old_color)
{
delay(5);
putpixel(x,y,new_color);
FloodFillAlgo(x+1,y,new_color,old_color);
FloodFillAlgo(x,y+1,new_color,old_color);
FloodFillAlgo(x-1,y,new_color,old_color);
FloodFillAlgo(x,y-1,new_color,old_color);
}
}
//OutPut

3
4
Program 6 program to fill polygon using Boundary Fill
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>
#include<iostream.h>
void boundaryFillAlgo(int x,int y,int new_color,int boundary_color);
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
/* our polygon array */
int poly[10]={100,100,150,100,150,150,100,150,100,100};
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
cout<<"Graphics error: %s\n"<<grapherrormsg(errorcode);
cout<<"Press any key to halt:";
getch();
/* terminate with an error code */
exit(1);
}
/* draw the polygon */
cout<<"\n\tBefore Fill=> ";
drawpoly(5, poly);
// Fill Poly
// cout<<getpixel(poly[0],poly[1]);
boundaryFillAlgo(poly[0]+10,poly[1]+10,5,15);
cout<<"\n\tAfter Boundary Fill ";
/* clean up */
getch();
closegraph();
return 0;
}
void boundaryFillAlgo(int x,int y,int new_color,int boundary_color)
{
if(getpixel(x,y)!=new_color && getpixel(x,y)!=boundary_color)
{
delay(5);
putpixel(x,y,new_color);
boundaryFillAlgo(x+1,y,new_color,boundary_color);
boundaryFillAlgo(x,y+1,new_color,boundary_color);
boundaryFillAlgo(x-1,y,new_color,boundary_color);
boundaryFillAlgo(x,y-1,new_color,boundary_color);

5
// OUTPUT

6
Program 7 2D transformation for Translation and Scaling
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
#include<math.h>
void tranlate(int num,int poly[]);
void scale(int num,int poly[]);
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* our polygon array */
int num=4;
int poly[8]={100,100,150,150,200,50,100,100};
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\turboc3\\BGI");

/* read result of initialization */


errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
cout<<"Graphics error: "<<grapherrormsg(errorcode);
cout<<"Press any key to halt:";
getch();
/* terminate with an error code */
exit(1);
}

/* draw the polygon */


outtextxy(40,40,"Original Object IS");
drawpoly(num, poly);
tranlate(num,poly);
cleardevice();
// clrscr();
/* draw the polygon */
outtextxy(40,40,"Original Object IS");
drawpoly(num, poly);
scale(num,poly);
cleardevice();
getch();
closegraph();
return 0;
}
void scale(int num,int poly[])
{
int i,k;
int newpoly[8];

7
int Sx,Sy;
cout<<"\b\t Enter Scaling factor Sx and Sy=> ";
cin>>Sx>>Sy;
k=0;
for(i=0;i<num;i++)
{
newpoly[k]=poly[k]*Sx;
newpoly[k+1]=poly[k+1]*Sy;
// cout<<"\n\tNew "<<newpoly[k]<<"\t"<<newpoly[k+1];
k=k+2;
}
outtextxy(newpoly[0]-10,newpoly[1]-10,"Scaling Object is");
drawpoly(num,newpoly);
getch();

}
void tranlate(int num,int poly[])
{
int i,k;
int newpoly[8];
int tx,ty;
cout<<"\n\t Enter tranlation factor tx and ty=> ";
cin>>tx>>ty;
k=0;
for(i=0;i<num;i++)
{
newpoly[k]=poly[k]+tx;
newpoly[k+1]=poly[k+1]+ty;
// cout<<"\n\tNew "<<newpoly[k]<<"\t"<<newpoly[k+1];
k=k+2;
}
outtextxy(newpoly[0]-10,newpoly[1]-10,"Tranlation Object is");
drawpoly(num,newpoly);
getch();
}

8
9
Program8 Program For 2D transformation of Rotatation
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
#include<math.h>
void rotate(int num,int poly[]);
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* our polygon array */
int num=4;
int poly[8]={0,0,150,150,200,50,0,0};
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\turboc3\\BGI");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
cout<<"Graphics error: "<<grapherrormsg(errorcode);
cout<<"Press any key to halt:";
getch();
/* terminate with an error code */
exit(1);
}
/* draw the polygon */
// outtextxy(40,40,"Original Object IS");
drawpoly(num, poly);
// code for Rotation
rotate(num,poly);
cleardevice();
getch();
closegraph();
return 0;
}
void rotate(int num,int poly[])
{
int i,k;
int newpoly[10];
double Q;
int Sx,Sy;
// moveto(0,0);
//outtextxy(200,50,"Enter Rotation Angle factor Q=>> 20");
cout<<"\b\t Enter Rotation Angle factor Q=>> ";
cin>>Q;
Q=20;
k=0;
double sq=(Q*3.141)/180;
for(i=0;i<num;i++)
{
newpoly[k]=poly[k]*cos(sq)-poly[k+1]*sin(sq);

10
newpoly[k+1]=poly[k]*sin(sq)+poly[k+1]*cos(sq);
// cout<<"\n\tNew "<<newpoly[k]<<"\t"<<newpoly[k+1];
k=k+2;
}
setcolor(RED);
drawpoly(num,newpoly);
getch();
}
// OUTPUT

11
Program 9 : Reflection and Shearing 2D transformation
#include<stdio.h>
#include<process.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void disp(int n,float c[][3])
{
float maxx,maxy;
int i;
maxx=getmaxx();
maxy=getmaxy();
maxx=maxx/2;
maxy=maxy/2;
i=0;
while(i<n-1)
{
line(maxx+c[i][0],maxy-c[i][1],maxx+c[i+1][0],maxy-c[i+1][1]);
i++;
}
i=n-1;
line(maxx+c[i][0],maxy-c[i][1],maxx+c[0][0],maxy-c[0][1]);
setcolor(GREEN);
line(0,maxy,maxx*2,maxy);
line(maxx,0,maxx,maxy*2);
setcolor(WHITE);
}
void mul(int n,float b[][3],float c[][3],float a[][3])
{
int i,j,k;
for(i=0;i<n;i++)
for(j=0;j<3;j++)
a[i][j]=0;
for(i=0;i<n;i++)
for(j=0;j<3;j++)
for(k=0;k<3;k++)
{
a[i][j] = a[i][j] + (c[i][k] * b[k][j]);
}
}
void reflection(int n,float c[][3])
{
float b[10][3],a[10][3];
int i=0,ch,j;
cleardevice();
printf("“\n\t* * MENU * *");
printf("\n\t1) ABOUT X-AXI:");
printf("\n\t2) ABOUT Y-AXIS");
printf("\n\t3) ABOUT ORIGIN");
printf("\n\t4) ABOUT X=Y");

12
printf("\n\t5) ABOUT -X=Y");
printf("\n\t6) EXIT");
printf("\n\tENTER YOUR CHOICE : ");
scanf("%d",&ch);
clrscr();
cleardevice();
disp(n,c);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
b[i][j]=0;
if(i==j)
b[i][j]=1;
}
switch(ch)

{
case 1:
b[1][1]=-1;
break;
case 2:
b[0][0]=-1;
break;
case 3:
b[0][0]=-1;
b[1][1]=-1;
break;
case 4:
b[0][0]=0;
b[1][1]=0;
b[0][1]=1;
b[1][0]=1;
break;
case 5:
b[0][0]=0;
b[1][1]=0;
b[0][1]=-1;
b[1][0]=-1;
break;
case 6:
break;
default:
printf("\n\tINVALID CHOICE ! ");
break;

mul(n,b,c,a);
setcolor(RED);
disp(n,a);
}
void shearing(int n,float c[][3])
{
float b[10][3],sh,a[10][3];
int i=0,ch,j;

13
cleardevice();
printf("\n\t* * * MENU * * *:");
printf("\n\t1) X SHEARING");

printf("\n\t2) Y SHEARING");
printf("\n\t3) EXIT ");
printf("\n\tENTER YOUR CHOICE : ");
scanf("%d",&ch);
if(ch==3)
return;
printf("\n\tENTER THE VALUE for SHEARING: ");
scanf("%f",&sh);
clrscr();
cleardevice();
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
for(i=0;i<3;i++)
b[i][i]=1;
switch(ch)
{
case 1:
b[1][0]=sh;
break;
case 2:
b[0][1]=sh;
break;
case 3:
break;
default:
printf("\n\tINVALID CHOICE ! ");
break;
}
mul(n,b,c,a);
setcolor(RED);
disp(n,a);
}
void main()
{
int i,j,k,cho,n,gd=DETECT,gm;
float c[10][3],tx,ty,sx,sy,ra;
initgraph(&gd,&gm,"c:\\turboc3\\BGI");
printf("\nEnter the number of vertices : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the co-ordinates of the %d vertex :",i+1);
scanf("%f%f",&c[i][0],&c[i][1]);
c[i][2]=1;
}
do
{
clrscr();
cleardevice();
printf("\n\t\t\t * * * MENU * * *");

14
printf("\n\t 1) REFLECTION ");
printf("\n\t 2) SHEARING");
printf("\n\t 3) EXIT");
printf("\n\t ENTER YOUR CHOICE:");
scanf("%d",&cho);
switch(cho)
{
case 1:
clrscr();
cleardevice();
setcolor(BLUE);
disp(n,c);
reflection(n,c);
getch();
break;
case 2:
clrscr();
cleardevice();
setcolor(BLUE);
disp(n,c);
shearing(n,c);
getch();
break;
case 3 :
exit(0);
break;
default:
printf("\n\tInvalid choice !!");
break;
}
}while(cho!=3);
getch();
closegraph();

15
16
17
18
Program 12 WPA to clip line using Cohen Sutherland line clipping algorithm
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
static int LEFT=1,RIGHT=2,BOTTOM=4,TOP=8,xl,yl,xh,yh;
// Generate outcode for Vertices;
int getcode(int x,int y){
int code = 0;
//Perform Bitwise OR to get outcode
if(y > yh) code |=TOP;
if(y < yl) code |=BOTTOM;
if(x < xl) code |=LEFT;
if(x > xh) code |=RIGHT;
return code;
}
void main()
{
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
setcolor(BLUE);
cout<<"Enter bottom left and top right co-ordinates of window: ";
cin>>xl>>yl>>xh>>yh;
rectangle(xl,yl,xh,yh);
int x1,y1,x2,y2;
cout<<"Enter the endpoints of the line: ";
cin>>x1>>y1>>x2>>y2;
line(x1,y1,x2,y2);
getch();
int outcode1=getcode(x1,y1), outcode2=getcode(x2,y2);
int accept = 0; //decides if line is to be drawn USe as Flag true or False
while(1){
float m =(float)(y2-y1)/(x2-x1);
//Both points inside. Accept line
if(outcode1==0 && outcode2==0){
accept = 1;
break;
}
//AND of both codes != 0.Line is outside. Reject line
else if((outcode1 & outcode2)!=0)
{
break;
}
else
{
int x,y;
int temp;
//Decide if point1 is inside, if not, calculate intersection
if(outcode1==0)
temp = outcode2;
else
temp = outcode1;
//Line clips top edge
if(temp & TOP){
x = x1+ (yh-y1)/m;

19
y = yh;
}
else if(temp & BOTTOM){ //Line clips bottom edge
x = x1+ (yl-y1)/m;
y = yl;
}else if(temp & LEFT){ //Line clips left edge
x = xl;
y = y1+ m*(xl-x1);
}else if(temp & RIGHT){ //Line clips right edge
x = xh;
y = y1+ m*(xh-x1);
}
//Check which point we had selected earlier as temp, and replace its co-
ordinates
if(temp == outcode1){
x1 = x;
y1 = y;
outcode1 = getcode(x1,y1);
}else{
x2 = x;
y2 = y;
outcode2 = getcode(x2,y2);
}
}
} // end of while loop
setcolor(WHITE);
cout<<"After clipping:";
if(accept)
line(x1,y1,x2,y2);
getch();
// getch();
closegraph();
}

20
//OUTPUT

21
Program 13: Write a program to clip line using midpoint subdivision algorithm
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#include <graphics.h>
#include<iostream.h>
typedef struct coordinate
{
int x,y;
char code[4];
}PT;
midsub(PT p1,PT p2);
void drawwindow();
void drawline (PT p1,PT p2);
PT setcode(PT p);
int visibility (PT p1,PT p2);
PT resetendpt (PT p1,PT p2);
main()
{
int gd=DETECT, gm,v;
PT p1,p2,ptemp;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
cleardevice();
printf("ENTER END-POINT 1 (x,y): ");
scanf("%d%d",&p1.x,&p1.y);
printf("\nENTER END-POINT 2 (x,y):");
scanf("%d%d",&p2.x,&p2.y);
//cleardevice();
cout<<"\n\t Before Clipping";
drawwindow();
getch();
drawline(p1,p2);
getch();
cleardevice();
drawwindow();
cout<<"\n\t After Clipping";
midsub(p1,p2);
getch();
cleardevice();
closegraph();
return(0);
}
midsub(PT p1,PT p2)
{
PT mid;
int v;
p1=setcode(p1);
p2=setcode(p2);

22
v=visibility(p1,p2);
switch(v)
{
case 0:
drawline(p1,p2);
break;
case 1:break;
case 2:
mid.x = p1.x + (p2.x-p1.x)/2;
mid.y = p1.y + (p2.y-p1.y)/2;
midsub(p1,mid);
mid.x = mid.x+1;
mid.y = mid.y+1;
midsub(mid,p2);
break;
}}
void drawwindow()
{
setcolor(RED);
line(150,100,450,100);
line(450,100,450,400);
line(450,400,150,400);
line(150,400,150,100);
}
void drawline (PT p1,PT p2)
{
setcolor(15);
line(p1.x,p1.y,p2.x,p2.y);
}
PT setcode(PT p)
{
PT ptemp;
if(p.y<=100) ptemp.code[0]='1'; else ptemp.code[0]='0'; if(p.y>=400)
ptemp.code[1]='1';
else
ptemp.code[1]='0';
if (p.x>=450)
ptemp.code[2]='1';
else
ptemp.code[2]='0';
if (p.x<=150)
ptemp.code[3]='1';
else
ptemp.code[3]='0';
ptemp.x=p.x;
ptemp.y=p.y;
return(ptemp);
}
int visibility (PT p1,PT p2)
{
int i,flag=0;

23
for(i=0;i<4;i++)
{
if((p1.code[i]!='0')||(p2.code[i]!='0'))
flag=1;
}
if(flag==0)
return(0);
for(i=0;i<4;i++)
{
if((p1.code[i]==p2.code[i]) &&(p1.code[i]=='1'))
flag=0;
}
if(flag==0)
return(1);
return(2);
}
//OutPut

24
Program 14 : write a program clip polygon using Sutherland-hodgeman polygon clipping
algorithm
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <process.h>
#define TRUE 1
#define FALSE 0
typedef unsigned int outcode;
outcode CompOutCode(float x,float y);
enum { TOP = 0x1,
BOTTOM = 0x2,
RIGHT = 0x4,
LEFT = 0x8
};
float xmin,xmax,ymin,ymax;
void clip(float x0,float y0,float x1,float y1)
{
outcode outcode0,outcode1,outcodeOut;
int accept = FALSE,done = FALSE;
outcode0 = CompOutCode(x0,y0);
outcode1 = CompOutCode(x1,y1);
do
{
if(!(outcode0|outcode1))
{
accept = TRUE;
done = TRUE;
}
else
if(outcode0 & outcode1)
done = TRUE;
else
{
float x,y;

outcodeOut = outcode0?outcode0:outcode1;
if(outcodeOut & TOP)
{
x = x0+(x1-x0)*(ymax-y0)/(y1-y0);
y = ymax;
}
else
if(outcodeOut & BOTTOM)
{
x = x0+(x1-x0)*(ymin-y0)/(y1-y0);
y = ymin;
}
else
if(outcodeOut & RIGHT)
{
y = y0+(y1-y0)*(xmax-x0)/(x1-x0);
x = xmax;

25
}
else
{
y = y0+(y1-y0)*(xmin-x0)/(x1-x0);
x = xmin;
}
if(outcodeOut==outcode0)
{
x0 = x;
y0 = y;
outcode0 = CompOutCode(x0,y0);
}
else
{
x1 = x;
y1 = y;
outcode1 = CompOutCode(x1,y1);
}
}
}while(done==FALSE);
if(accept)
line(x0,y0,x1,y1);
outtextxy(150,20,"POLYGON AFTER CLIPPING");

rectangle(xmin,ymin,xmax,ymax);
}
outcode CompOutCode(float x,float y)
{
outcode code = 0;
if(y>ymax)
code|=TOP;
else
if(y<ymin)
code|=BOTTOM;
if(x>xmax)
code|=RIGHT;
else
if(x<xmin)
code|=LEFT;
return code;
}
void main( )
{
float x1,y1,x2,y2;
/* request auto detection */
int gdriver = DETECT, gmode, n,poly[14],i;
clrscr( );
printf("Enter the no of sides of polygon:");
scanf("%d",&n);
printf("\nEnter the coordinates of polygon\n");
for(i=0;i<2*n;i++)
{
scanf("%d",&poly[i]);
}
poly[2*n]=poly[0];

26
poly[2*n+1]=poly[1];
printf("Enter the rectangular coordinates of clipping window\n");
scanf("%f%f%f%f",&xmin,&ymin,&xmax,&ymax);
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");

outtextxy(150,20,"POLYGON BEFORE CLIPPING");


drawpoly(n+1,poly);
rectangle(xmin,ymin,xmax,ymax);
getch( );
cleardevice( );
for(i=0;i<n;i++)
clip(poly[2*i],poly[(2*i)+1],poly[(2*i)+2],poly[(2*i)+3]);
getch( );
restorecrtmode( );
}
// OUTPUT

27
28
//Program 15: WPA for Hilbert Curve
#include<iostream.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>
#include<dos.h>
void move(int j,int h,int &x,int &y)
{
if(j==1)
y-=h;
else if(j==2)
x+=h;
else if(j==3)
y+=h;
else if(j==4)
x-=h;
lineto(x,y);
}
void hilbert(int r,int d,int l,int u,int i,int h,int &x,int &y)
{
if(i>0)
{
i--;
hilbert(d,r,u,l,i,h,x,y);
move(r,h,x,y);
hilbert(r,d,l,u,i,h,x,y);
move(d,h,x,y);
hilbert(r,d,l,u,i,h,x,y);
move(l,h,x,y);
hilbert(u,l,d,r,i,h,x,y);
}
}
int main()
{
int n,x1,y1;
int x0=50,y0=150,x,y,h=10,r=2,d=3,l=4,u=1;
cout<<"\nGive the value of n: ";
cin>>n;
x=x0;y=y0;
int gm,gd=DETECT;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
moveto(x,y);
hilbert(r,d,l,u,n,h,x,y);
delay(10000);
closegraph();
return 0;
}

29
//OutPut

30
// Program 16: write a program to draw Koch curve and Bezier curve
#include<graphics.h>
#include<conio.h>
#include<math.h>
void koch(int x1, int y1, int x2, int y2, int it)
{ float angle = 60*M_PI/180;
int x3 =(2*x1+x2)/3;
int y3 =(2*y1+y2)/3;
int x4 = (x1+2*x2)/3;
int y4 = (y1+2*y2)/3;
int x = x3 + (x4-x3)*cos(angle)+(y4-y3)*sin(angle);
int y = y3 - (x4-x3)*sin(angle)+(y4-y3)*cos(angle);
if(it > 0)
{ koch(x1, y1, x3, y3, it-1);
koch(x3, y3, x, y, it-1);
koch(x, y, x4, y4, it-1);
koch(x4, y4, x2, y2, it-1); }
else
{ line(x1, y1, x3, y3);
line(x3, y3, x, y);
line(x, y, x4, y4);
line(x4, y4, x2, y2);
}}
int main(void)
{ int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
int x1 = 100, y1 = 300, x2 = 400, y2 = 300;
outtextxy(100,90,"For O Iteration");
koch(100, 100, 400, 100,0);
outtextxy(100,150,"For 1 Iteration");
koch(100, 200, 400, 200,1);
outtextxy(100,250,"For 2 Iteration");
koch(100, 300, 400, 300,2);
outtextxy(100,350,"For 3 Iteration");
koch(100, 400, 400, 400,3);
getch();
cleardevice();
return 0;
} // Output

31
// For Bezier Curve
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main(){
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
int x[4],y[4],px,py,i;
cout<<"\n\tEnter four control points of bezier curve: ";
for(i=0;i<4;i++) cin>>x[i]>>y[i];
double t;
for(t=0.0;t<=1.0;t+=0.001){
px=(1-t)*(1-t)*(1-t)*x[0]+3*t*(1-t)*(1-t)*x[1]+3*t*t*(1-t)*x[2]+t*t*t*x[3];
py=(1-t)*(1-t)*(1-t)*y[0]+3*t*(1-t)*(1-t)*y[1]+3*t*t*(1-t)*y[2]+t*t*t*y[3];
putpixel(px,py,WHITE);
delay(2);
}
getch();
closegraph();
}
// OUTPUT

32

Das könnte Ihnen auch gefallen