HARSH CG LAP File
HARSH CG LAP File
PRACTICAL FILE
• YEAR: 3rd
• SEMESTER: 5th
• SESSION: 2021-22
1. Putpixel:- Putpixel function is to draw the pixel on the screen. Pixel is small dot on the screen.
Syntax:-putpixel(x co-orinate, y co-ordinate,COLOR); Example: – putpixel(100,100,BLUE);
2. SetbkColor:- Setbkcolor function is used to set background color of the screen. Syntax:-
setbkcolor(COLOR); Example:-setbkcolor(RED);
3. Setlinestyle:- setlinestyle function is used to set the current line style, width and pattern.
Syntax:-setlinestyle(linestyle, pattern, thickness); Example:-setlinestyle(SOLID_LINE,1,2);
4. Setcolor - setcolor is to set color of the objects which is to be drawn after this setcolor line.
Syntax:-setcolor(COLOR); Example:-setcolor(RED);
5. Rectange:- Rectangle function is used to draw the rectangle on the screen. X1,y1 are the lower
left co-ordinates of the rectangle and the x2,y2 are the upper right co-ordinates of the
rectangle. Syntax:– rectangle(x1,,y1,x2,y2); Example:– rectangle(100,100,200,200);
11. Getmaxy:- getmaxy returns the maximum y co-ordinate on the screen. Syntax:-getmaxy();
Example:-maxy=getmaxy();
12. Line:- Line function is used to draw the line on the screen. Syntax: line(x1,y1,x2,y2); Example:-
line(100,100,200,100);
13. Closegraph:- closegraph function shut down the graphic system. Syntax:-closegraph();
Example:-closegraph();
14. Moveto:- moveto function moves current cursor position on the screen. Syntax:-moveto(x co-
ordinate, y co-ordinate); Example:-moveto(getmaxx/2, getmaxy/2);
15. Settextstyle:- settextstyle sets the current text characteristics like font, direction and size.
Syntax:-settextstyle(font, direction size); Example:-settextstyle(1,1,10);
16. Circle:- Circle function is used to draw the circle on the screen. Syntax:– circle(x,y,radius);
Example:circle(100,100,50);
17. Cleardevice:- cleardevice function is used to clear the contents or graphic images on the screen
in graphics mode. Syntax:cleardevice(); Example:cleardevice();
18. Outtextxy:- outtextxy function is used to print the text on the screen in graphics mode.
Syntax:outtext(x,y,text); Example:-outtextxy(100,100,”HELLO”);
19. Sector: sector function draws and fills an elliptical pie slice. Syntax:sector(x, y, starting angle,
ending angle, xradius, yradius); Example:sector(100,100,45 135 100 50);
20. Arc:- arc draws the arc on the screen, arc is a part of the circle. Syntax:arc(x, y, starting angle,
ending angle, radius); Example:arc( 100,100,90,180,50);
21. Setfillstyle:- setfillstyle is used to set the color and style to be filled in the object using the flood
fill method. Syntax:stefillstyle(STYLE, COLOR); Example:setfillstyle(1,RED)
22. Floodfill:- floodfill function is used to fill the color in the object, object may be circle, rectangle
or any other closed image. Syntax:floodfill(x,y,boundary color); Example:
floodfill(100,100,BLUE);
23. Ellipse:- ellipse function is used to draw the ellipse on the screen. Syntax:ellipse(x, y, starting
angle, ending angle, xradius, yradius); Example:ellipse(100,100,90,200,20,20);
24. Outtext:- outtext function is used to display the text on the screen, using this function text is
display in the current position. Syntax:outtext(STRING); Example:outtex(“HELLO”);
25. Getcolor:- getcolor returns the current drawing color. Syntax:getcolor(); Example:intclr =
getcolor();
26. Getpixel:- getpixel gets the color of a specified pixel. Syntax:getpixel(x,y); Example:
color=getpixel(100,100);
Experiment No. 2
Aim :-
Algorithm:-
Step7: xinc=dx/step
yinc=dy/step
assign x = x1
assign y = y1
Step9: x = x + xinc
y = y + yinc
Set pixels (Round (x), Round (y))
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,step;
int gd=DETECT,gm;
int i;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("HARSH DEVENDRA 19SCSE1110001\n");
printf("Enter the value of x1 and y1:");
scanf("%f%f",&x1,&y2);
printf("Enter the value of x2 and y2:");
scanf("%f%f",&x2,&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
step=dx;
else
step=dy;
dx=dx/step;
dy=dy/step;
x=x1;
y=y1;
i=1;
while(i<=step)
{
putpixel(x,y,WHITE);
x=x+dx;
y=y+dy;
i=i+1;
delay(40);
}
getch();
closegraph();
}
Output:-
Experiment No. 3
Aim :-
Algorithm:-
Step 1: Enter the 2 end points for a line and store the left end point in (X0,Y0).
Step 2: Plot the first point by loading (X0,Y0) in the frame buffer.
Setp 3: determine the initial value of the decision parameter by calculating the constants dx, dy, 2dy
and 2dy-2dx as P0 = 2dy –dx.
Step 4: for each Xk, conduct the following test, starting from k=0. If Pk <0, then the next point to be
plotted is at (Xk+1, Yk) and Pk+1 = Pk + 2dy
Else, the next point is (Xk+1, Yk+1) and Pk+1 = Pk + 2dy –2dx (step 3)
Source Code:-
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,pk;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("HARSH DEVENDRA 19SCSE1110001\n");
printf("Enter the value of x1 and y1:");
scanf("%f%f",&x1,&y2);
printf("Enter the value of x2 and y2:");
scanf("%f%f",&x2,&y2);
dx=x2-x1;
dy=y2-y1;
x=x1;
y=x1;
pk=2*dy-dx;
while(x<=x2)
{
if(pk<=0)
{
pk+=2*dy;
x=x+1;
}
else
{
pk+=2*dy-2*dx;
x=x+1;
y=y+1;
}
putpixel(x,y,WHITE);
}
getch();
closegraph();
}
Output:-
Program No. 4
Aim :-
Algorithm:-
Step2: Declare p, q, x, y, r, d variables , p, q are coordinates of the center of the circle r is the radius of
the circle
Step4: Calculate d = 3 - 2r
Step7: Plot eight points by using concepts of eight-way symmetry. The center is at (p, q). Current active
pixel is (x, y).
Step9: Go to step 6
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
void main(){
float p,q,x,y,r,d; int gd=DETECT,gm;
printf("HARSH DEVENDRA 19SCSE1110001\n");
printf("Enter the coordinate of the centre of a circle:");
scanf("%f%f",&p,&q);
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("Enter the value of radius:");
scanf("%f",&r);
y=r;
x=0;
d=3-2*r;
while(x<=y)
{
putpixel(x+p,y+q,WHITE);
putpixel(y+p,x+q,WHITE);
putpixel(-y+p,x+q,WHITE);
putpixel(-x+p,y+q,WHITE);
putpixel(-x+p,-y+q,WHITE);
putpixel(-y+p,-x+q,WHITE);
putpixel(y+p,-x+q,WHITE);
putpixel(x+p,-y+q,WHITE);
delay(40);
if(d<0)
{
d=d+(4*x)+6;
x=x+1;
}
else
{
d=d+(4*(x-y))+6;
x=x+1;
y=y-1;
}
}
getch();}
Output:
Program No. 5
Aim :-
Algorithm:-
Step 1:- Input radius r and circle center (xc, yc ). set the first point (x0 , y0 ) = (0, r ).
Step 5:- Move each calculated pixel position (x, y) onto the circular path centeWHITE on (xc, yc) and
plot the coordinate values: x = x + xc , y = y + yc
Step 7:- For all points, add the center point (xc, yc )
Source Code:-
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
void main()
{
float p,q,x,y,r,d;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("HARSH DEVENDRA 19SCSE1110001\n");
printf("Enter the coordinate of the centre of a circle:");
scanf("%f%f",&p,&q);
printf("Enter the value of radius:");
scanf("%f",&r);
y=r;
x=0;
d=1-r;
while(x<=y)
{
putpixel(x+p,y+q,WHITE);
putpixel(y+p,x+q,WHITE);
putpixel(-y+p,x+q,WHITE);
putpixel(-x+p,y+q,WHITE);
putpixel(-x+p,-y+q,WHITE);
putpixel(-y+p,-x+q,WHITE);
putpixel(y+p,-x+q,WHITE);
putpixel(x+p,-y+q,WHITE);
delay(40);
if(d<0)
{
}
else
{
}
getch();
}
d=d+(2*x)+1;
x=x+1;
d=d+(2*(x-y))+1;
x=x+1;
y=y-1
Program No. 6
Aim :-
Algorithm:-
Step 1:- Take input radius along x axis and y axis and obtain center of ellipse.
Step 2:- Initially, we assume ellipse to be centeWHITE at origin and the first point as : (x, y0)= (0, ry).
Step 3:- Obtain the initial decision parameter for region 1 as: p10=ry2+1/4rx2-rx 2ry
Step 5:- Obtain the initial value in region 2 using the last point (x0, y0) of region 1 as:
p20=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
Step 7:- Else, the next point is (xk+1, yk -1) and p2k+1=p2k+2ry2xk+1 -2rx2yk+1+rx2
Step 8:- Now obtain the symmetric points in the three quadrants and plot the coordinate value as:
x=x+xc, y=y+yc
Source Code:-
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
void main()
{
float rx,x,y,ry,d1,d2,a,b,p,q;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("HARSH DEVENDRA 19SCSE1110001\n");
printf("Enter the coordinate of the centre of a ellipse:");
scanf("%f%f",&p,&q);
printf("Enter the value of major and minor axis:");
scanf("%f%f",&rx,&ry);
y=ry;
x=0;
d1=(ry*ry)+(0.25*rx*rx)-(rx*rx*ry);
a=2*ry*ry*x;
b=2*rx*rx*y;
while(a<b)
{
putpixel(x+p,y+q,WHITE);
putpixel(-x+p,y+q,WHITE);
putpixel(x+p,-y+q,WHITE);
putpixel(-x+p,-y+q,WHITE);
delay(40);
if(d1<0)
{
x=x+1;
} a=a+(2*ry*ry);
else d1=d1+(2*ry*ry*x)+(ry*ry);
{
a=a+2*ry*ry;
b=b-2*rx*rx;
d1=d1+(2*ry*ry*x)-2*rx*rx*y+(ry*ry);
} x=x+1;
y=y-1;
}
d2=((ry*ry)*((x+0.5)*(x + 0.5)))+((rx * rx)*((y - 1)*(y-1)))-(rx*rx*ry*ry);
while(y>=0)
{
putpixel(x+p,y+q,WHITE);
putpixel(-x+p,y+q,WHITE);
putpixel(x+p,-y+q,WHITE);
putpixel(-x+p,-y+q,WHITE);
delay(40);
if(d2>0)
{
b=b-2*rx*rx;
d2=d2+(rx*rx)-b;
y=y-1;
}
else
{
x=x+1;y=y-1;
a=a+2*ry*ry;
b=b-2*rx*rx;
d2=d2+a-b+(rx*rx);
}
}
getch();
}
Output:
Program No. 7
Aim:-
Algorithm: -
x = rcosB, y = rsinB
x’ = rcos(A+B) = r(cosAcosB – sinAsinB) = rcosBcosA – rsinBsinA = xcosA – ysinA
y’ = rsin(A+B) = r(sinAcosB + cosAsinB) = rcosBsinA + rsinBcosA = xsinA + ycosA
Source Code:-
#include<stdio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=0,gm,x1,y1,x2,y2;
double s,c, angle;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
printf("HARSH DEVENDRA 19SCSE1110001\n");
printf("Enter coordinates of line: ");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
line(x1,y1,x2,y2);
printf("Enter rotation angle: ");
scanf("%lf", &angle);
c = cos(angle *3.14/180);
s = sin(angle *3.14/180);
x1 = floor(x1 * c + y1 * s);
y1 = floor(-x1 * s + y1 * c);
x2 = floor(x2 * c + y2 * s);
y2 = floor(-x2 * s + y2 * c);
line(x1, y1 ,x2, y2);
getch();
closegraph();
}
Output:
Program No. 8
Aim: -
Algorithm: -
Suppose, If point (X, Y) is to be translated by amount Dx and Dy to a new location (X’, Y’) then new
coordinates can be obtained by adding Dx to X and Dy to Y as:
X' = Dx + X
Y' = Dy + Y
or P' = T + P where
P' = (X', Y'),
T = (Dx, Dy ),
P = (X, Y)
Here, P(X, Y) is the original point. T(Dx, Dy) is the translation factor, i.e. the amount by which the point
will be translated. P'(X’, Y’) is the coordinates of point P after translation.
Source Code: -
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
void triangletranslate()
{
int x,y;
line(75,85,90,120);
line(90,120,110,85);
line(110,85,75,85);
printf("Enter translation vector in x direction and y direction:");
scanf("%d%d",&x,&y);
line(75+x,85+y,90+x,120+y);
line(90+x,120+y,110+x,85+y);
line(110+x,85+y,75+x,85+y);
getch();;
closegraph();
}
void rectangletranslate()
{
int x,y;
line(75,85,75,120);
line(75,120,100,120);
line(100,120,100,85);
line(100,85,75,85);
printf("Enter translation vector in x direction and y direction:");
scanf("%d%d",&x,&y);
line(75+x,85+y,75+x,120+y);
line(75+x,120+y,100+x,120+y);
line(100+x,120+y,100+x,85+y);
line(100+x,85+y,75+x,85+y);
getch();;
closegraph();
}
void circletranslate()
{
int x,y,radius;
printf("Enter the radius:");
scanf("%d",&radius);
circle(90,120,radius);
printf("Enter translation vector in x direction and y direction:");
scanf("%d%d",&x,&y);
circle(90+x,120+y,radius);
getch();
closegraph();
}
void main()
{
int ch;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");
printf("HARSH DEVENDRA 19SCSE1110001\n");
printf("1.translate a triangle\n2.translate a Circle\n3.translate a rectangle\n4.exit");
printf("\nEnter choice:");
scanf("%d",&ch);
clrscr();
switch(ch)
{
case 1:triangletranslate();break;
case 2:circletranslate();break;
case 3:rectangletranslate();break;
case 4:printf("THANK YOU");break;
default:printf("INCORRECT INPUT");
}
getch();}
Output:
Program No. 9
Aim :-
Algorithm:-
Scaling operation can be achieved by multiplying each vertex coordinate (x, y) of the polygon by scaling
factor sx and sy to produce the transformed coordinates as (x’, y’).
Source Code:-
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
void main()
{
int gm,gd=DETECT,x=100;
int y=200;
int z=150;
int sx,sy;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
initgraph(&gd,&gm, "");
printf("HARSH DEVENDRA 19SCSE1110001\n");
line(x,x,y,x);
line(x,x,z,z);
line(y,x,z,z);
line(sx*x,sy*x,sx*y,sy*x);
line(sx*x,sy*x,sx*z,sy*z);
line(sx*y,sy*x,sx*z,sy*z);
getch();
closegraph();
}
Output:
Program No. 10
Aim :-
Algorithm:-
Step 1:- Create an object in the 2nd graph quadrant by providing the coordinates.
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
void main()
{
int gm,gd=DETECT,ax,x1=100;
int x2 = 100, x3 = 200, y1 = 100;
int y2 = 200, y3 = 100;
initgraph(&gd, &gm,"C:\\TURBOC3\\BGI");
initgraph(&gd, &gm, "");
printf("HARSH DEVENDRA 19SCSE1110001\n")
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
line(0, getmaxy()/2,getmaxx(),getmaxy()/2);
printf("Before Reflection Object in 2nd Quadrant");
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
getch();
printf("\nAfter Reflection");
// along origin
line(getmaxx()-x1,getmaxy()-y1,getmaxx()-x2,getmaxy()-y2);
line(getmaxx()-x2,getmaxy()-y2,getmaxx()-x3,getmaxy()-y3);
line(getmaxx()-x3,getmaxy()-y3,getmaxx()-x1,getmaxy()-y1);
line(getmaxx()-x1,y1,getmaxx()-x2,y2);
line(getmaxx()-x2,y2,getmaxx()-x3,y3);
line(getmaxx()-x3,y3,getmaxx()-x1,y1);
Algorithm/Theory:-
A number of transformations or sequence of transformations can be combined into single one called as
composition. The resulting matrix is called as composite matrix. The process of combining is called as
concatenation.
Suppose we want to perform rotation about an arbitrary point, then we can perform it by the sequence of
three transformations
1. Translation
2. Rotation
3. Reverse Translation
The ordering sequence of these numbers of transformations must not be changed. If a matrix is
represented in column form, then the composite transformation is performed by multiplying matrix in
order from right to left side. The output obtained from the previous matrix is multiplied with the new
coming matrix.
Source Code:-
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
int xa, xb, xc, ya, yb, yc, y1a, y1b, y1c, x1a, x1b, x1c, x2a, x2b, x2c, y2a, y2b, y2c;
int x3a, x3b, x3c, y3a, y3b, y3c, x4a, x4b, x4c, y4a, y4b, y4c, x5a, x5b, x5c, y5a, y5b, y5c;
int tx, shx, t, ch, shy;
float ang, theta, sx, sy;
int main(void) {
int gdriver = DETECT, gmode, errorcode;
initgraph( & gdriver, & gmode, "C:\\turboc3\\BGI");
printf("HARSH DEVENDRA 19SCSE1110001");
printf("\n\t\t\t 2D Composite Transformations");
printf("\n\n Enter all coordinates values :");
scanf("%d %d %d %d %d %d", & xa, & ya, & xb, & yb, & xc, & yc);
Algorithm:-
Step4:If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)
(a) If bit 1 is "1" line intersects with left boundary of rectangle window
y3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
void drawwindow();
void drawline(PT p1, PT p2);
PT setcode(PT p);
int visibility(PT p1, PT p2);
PT resetendpt(PT p1, PT p2);
void main() {
int gd = DETECT, v, gm;
PT p1, p2, p3, p4, ptemp;
printf("\HARSH DEVENDRA 19SCSE1110001\n");
printf("\nEnter x1 and y1\n");
scanf("%d %d", & p1.x, & p1.y);
printf("\nEnter x2 and y2\n");
scanf("%d %d", & p2.x, & p2.y);
initgraph( & gd, & gm, "c:\\turboc3\\bgi");
drawwindow();
delay(500);
drawline(p1, p2);
delay(500);
cleardevice();
delay(500);
p1 = setcode(p1);
p2 = setcode(p2);
v = visibility(p1, p2);
delay(500);
switch (v) {
case 0:
drawwindow();
delay(500);
drawline(p1, p2);
break;
case 1:
drawwindow();
delay(500);
break;
case 2:
p3 = resetendpt(p1, p2);
p4 = resetendpt(p2, p1);
drawwindow();
delay(500);
drawline(p3, p4);
break;
}
delay(5000);
closegraph();
}
void drawwindow() {
line(150, 100, 450, 100);
line(450, 100, 450, 350);
line(450, 350, 150, 350);
line(150, 350, 150, 100);
}
Algorithm:-
The polygon clipping algorithm deals with four different clipping cases. The output of each case is input for the next
case.
Case1) Left clip: In the left side polygon clipping, we only remove the left part of the polygon, which is outside the
window. We only save the portion which is inside the window.
Case2) Right clip: In the right-side polygon clipping, we only remove the right part of the polygon, which is outside
the window. We only save the portion which is inside the window.
Case3) Top clip: On the top side polygon clipping, we only remove the top part of the polygon, which is outside the
window. We only save the portion which is inside the window.
Case4) Bottom clip: In the bottom side polygon clipping, we only remove the bottom part of the polygon, which is
outside the window. We only save the portion which is inside the window.
Condition 1(Out-In): If the first vertex of the polygon is outside and the second vertex is inside the window, then the
output will be the intersection point and second vertex.
Condition 2(In-Out): If the first vertex of the polygon is inside and the second vertex is outside the window, then the
output will be the intersection point.
Condition 3(In-In): If both vertices of the polygon are inside the window, then the output will be the second vertex.
Condition 4(Out-Out): If both vertices of the polygon are outside the window, then the output will be nothing. It
means we found a clipped polygon.
Source Code:-
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int gd,gm,n,*x,i,k=0;
int w[]={220,140,420,140,420,340,220,340,220,140};
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("Window:-");
setcolor(RED);
drawpoly(5,w);
printf("HARSH DEVENDRA 19SCSE1110001\n");
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){
printf("(x%d,y%d): ",k,k);
scanf("%d,%d",&x[i],&x[i+1]);
k++;
}
x[n*2]=x[0];
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);
printf("\nThis is the clipped polygon..");
getch();
cleardevice();
closegraph();
return 0;
}
Output:
Program No. 14
Aim :-
Algorithm:-
• First make a list of all intersection points namely i1, i2, i3, ...
• Classify those intersection points as entering or exiting.
• Now, make two lists, one for the clipping polygon, and the other for the clipped polygon.
• Fill both the lists up in such a way that the intersection points lie between the correct vertices of each of the
polygon. That is the clipping polygon list is filled up with all the vertices of the clipping polygon along with
the intersecting points lying between the corresponding vertices.
• Now, start at the 'to be clipped' polygon's list.
• Choose the first intersection point which has been labelled as an entering point. Follow the points in the list
(looping back to the top of the list, in case the list ends) and keep on pushing them into a vector or
something similar of the sorts. Keep on following the list until an exiting intersection point is found.
• Now switch the list to the 'polygon that is clipping' list, and find the exiting the intersection that was
previously encountered. Now keep on following the points in this list (similar to how we followed the
previous list) until the entering intersection point is found (the one that was found in the previous 'to be
clipped' polygon's list).
• This vector now formed by pushing all the encountered points in the two lists, is now the clipped polygon
(one of the many clipped polygons if any of the clipping polygons is concave).
• Repeat this clipping procedure (i.e. from step 5) until all the entering intersection points have been visited
once.
Source Code:-
#include<conio.h>
#include <graphics.h>
#include<dos.h>
void weiler_polygon_clipping();
void main()
{ int gd = DETECT, gm;
initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");
outtextxy(50,90,"HARSH DEVENDRA 19SCSE1110001");
clrscr();
outtextxy(50,80,"Weiler-Atherton Polygon Clipping");
cleardevice();
weiler_polygon_clipping();
cleardevice();
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
outtextxy(150,150,"THANK YOU");
getch();
closegraph();
}
void weiler_polygon_clipping()
{
outtextxy(50,90,"HARSH DEVENDRA 19SCSE1110001");
rectangle(70,240,180,360);
line(30,310,110,270);
line(110,270,100,295);
line(100,295,50,330);
line(50,330,110,340);
line(110,340,30,350);
line(30,310,30,350);
outtextxy(20,310,"v1");
outtextxy(110,270,"v2");
outtextxy(105,295,"v3");
outtextxy(45,330,"v4");
outtextxy(115,340,"v5");
outtextxy(20,350,"v6");
outtextxy(65,285,"v1'");
outtextxy(65,305,"v3'");
outtextxy(75,325,"v4'");
outtextxy(50,350,"v5'");
outtextxy(50,469,"Hit any key to continue...");
getch();
cleardevice();
outtextxy(50,90,"HARSH DEVENDRA 19SCSE1110001");
rectangle(70,240,180,360);
setcolor(11);
line(70,290,110,270);
line(110,270,100,295);
line(100,295,70,320);
line(70,290,70,320);
delay(2000);
line(70,330,110,340);
line(70,330,110,340);
line(110,340,70,350);
line(70,330,70,350);
Source Code:-
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main()
{
int gd = DETECT, gm;
char temp;
int i, maxx, midy;
initgraph(&gd, &gm, "c:\\turboc3\\bgi");
printf("HARSH DEVENDRA 19SCSE1110001");
printf("Press any key to start:");
scanf("%c",&temp);
maxx = getmaxx();
midy = getmaxy()/2;
for (i=0; i < maxx-150; i=i+5) {
cleardevice();
setcolor(WHITE);
line(0, midy + 37, maxx, midy + 37);
line(i, midy + 23, i, midy);
line(i, midy, 40 + i, midy - 20);
line(40 + i, midy - 20, 80 + i, midy - 20);
line(80 + i, midy - 20, 100 + i, midy);
line(100 + i, midy, 120 + i, midy);
line(120 + i, midy, 120 + i, midy + 23);
line(0 + i, midy + 23, 18 + i, midy + 23);
arc(30 + i, midy + 23, 0, 180, 12);
line(42 + i, midy + 23, 78 + i, midy + 23);
arc(90 + i, midy + 23, 0, 180, 12);
line(102 + i, midy + 23, 120 + i, midy + 23);
line(28 + i, midy, 43 + i, midy - 15);
line(43 + i, midy - 15, 57 + i, midy - 15);
line(57 + i, midy - 15, 57 + i, midy);
line(57 + i, midy, 28 + i, midy);
Output: