Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Document

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

#include<stdio.

h>

#include<graphics.h>

#include<conio.h>

#include<stdlib.h>

Int main()

Int gd,gm,n,*x,I,k=0;

//window coordinates int


wx1=220,wy1=140,wx2=420,wy2=140,wx3=420,wy3=340,wx4=220,wy4=340;

Int w[]={220,140,420,140,420,340,220,340,220,140};//array for drawing window

Detectgraph(&gd,&gm);

Initgraph(&gd,&gm,”c:\\turboc3\\bgi”); //initializing graphics

Printf(“Window:-“);

Setcolor(RED); //red colored window

Drawpoly(5,w); //window drawn

Printf(“Enter the no. of vertices of polygon: “);

Scanf(“%d”,&n);

X = malloc(n*2+1);

Printf(“Enter the coordinates of points:\n”);

K=0;

For(i=0;i<n*2;i+=2) //reading vertices of polygon

Printf(“(x%d,y%d): “,k,k);

Scanf(“%d,%d”,&x[i],&x[i+1]);

K++;

}
X[n*2]=x[0]; //assigning the coordinates of first vertex to last additional vertex for
drawpoly method.

X[n*2+1]=x[1];

Setcolor(WHITE);

Drawpoly(n+1,x);

Printf(“\nPress a button to clip a polygon..”);

Getch();

Setcolor(RED);

Drawpoly(5,w);

Setfillstyle(SOLID_FILL,BLACK);

Floodfill(2,2,RED);

Gotoxy(1,1); //bringing cursor at starting position

Printf(“\nThis is the clipped polygon..”);

Getch();

Cleardevice();

Closegraph();

Return 0;

}#include<stdio.h>

#include<graphics.h>

#include<conio.h>

#include<stdlib.h>

Int main()

Int gd,gm,n,*x,I,k=0;

//window coordinates int


wx1=220,wy1=140,wx2=420,wy2=140,wx3=420,wy3=340,wx4=220,wy4=340;
Int w[]={220,140,420,140,420,340,220,340,220,140};//array for drawing window

Detectgraph(&gd,&gm);

Initgraph(&gd,&gm,”c:\\turboc3\\bgi”); //initializing graphics

Printf(“Window:-“);

Setcolor(RED); //red colored window

Drawpoly(5,w); //window drawn

Printf(“Enter the no. of vertices of polygon: “);

Scanf(“%d”,&n);

X = malloc(n*2+1);

Printf(“Enter the coordinates of points:\n”);

K=0;

For(i=0;i<n*2;i+=2) //reading vertices of polygon

Printf(“(x%d,y%d): “,k,k);

Scanf(“%d,%d”,&x[i],&x[i+1]);

K++;

X[n*2]=x[0]; //assigning the coordinates of first vertex to last additional vertex for
drawpoly method.

X[n*2+1]=x[1];

Setcolor(WHITE);

Drawpoly(n+1,x);

Printf(“\nPress a button to clip a polygon..”);

Getch();

Setcolor(RED);

Drawpoly(5,w);
Setfillstyle(SOLID_FILL,BLACK);

Floodfill(2,2,RED);

Gotoxy(1,1); //bringing cursor at starting position

Printf(“\nThis is the clipped polygon..”);

Getch();

Cleardevice();

Closegraph();

Return 0;

You might also like