0% found this document useful (0 votes)
7 views48 pages

Combo Animation

combo animtion

Uploaded by

rohinichangale2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views48 pages

Combo Animation

combo animtion

Uploaded by

rohinichangale2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

COMBO ANIMATION

/*MINI PROJECT :---COMBO ANIMATION

DEVELOPED BY—ROHINI CHANGALE. SE CSE 69

SHRUTIKA MAKA. SE CSE 68*/


#include<stdio.h>

#include<conio.h>

#include<graphics.h>

int maxx,maxy,midx,midy;

void line_pattern();

void rect_pattern();

void circle_pattern();

void circle_sq_pattern();

void house();

void ship();

void cycle();

void car();

void rocket();

void bouncing_ball();

void dda();

void b_line();

void b_circle();

void polygon();

void transformation_2d();

void transformation_3d();

void sutherland();

//void open_gl();
main()

int i, gd=0,gm=0, ch;

clrscr();

initgraph(&gm,&gd,"C:\\TurboC3\\BGI");

setbkcolor(11);

setcolor(5);

settextstyle(1,0,4);

for( i=0;i<650;i++)

cleardevice();

outtextxy(0+i,50,"COMBO ANIMATION");

delay(30);

settextstyle(7,0,6);

setcolor(6);

outtextxy(80,30,"COMBO ANIMATION");

settextstyle(7,0,1);

outtextxy(400,400,"DEVELOPED BY-");

outtextxy(400,420,"Rohini Changale");

outtextxy(400,440,"Shrutika Maka");

settextstyle(8,0,1);

setcolor(5);

outtextxy(50,110,"1.LINE PATTERN");

outtextxy(50,130,"2.RECTANGLE PATTERN");

outtextxy(50,150,"3.CIRCLE PATTERN");

outtextxy(50,170,"4.CIRCLE SQUARE PATTERN");


outtextxy(50,190,"5.HOUSE");

outtextxy(50,210,"6.SHIP");

outtextxy(50,230,"7.CAR");

outtextxy(50,250,"8.CYCLE");

outtextxy(50,270,"9.ROCKET");

outtextxy(380,110,"10.BOUNCING BALL");

outtextxy(380,130,"11.DDA LINE");

outtextxy(380,150,"12.BRESHENHAMS LINE");

outtextxy(380,170,"13.BRESHENHAMS CIRCLE");

outtextxy(380,190,"14.POLYGON FILLING");

outtextxy(380,210,"15.2D TRANSFORMATION");

outtextxy(380,230,"16.3D TRANSFORMATION");

outtextxy(380,250,"17.SUTHERLAND LINE CLIP");

outtextxy(380,270,"18.OPEN GL");

outtextxy(50,300,"ENTER YOUR CHOICE:");

setcolor(BLACK);

scanf("%d",&ch);

// outtextxy(350,300,"%d,ch");

setbkcolor(BLACK);

setcolor(WHITE);

switch(ch)

case 1:

line_pattern();

break;

case 2: rect_pattern();

break;
case 3: circle_pattern();

break;

case 4: circle_sq_pattern();

break;

case 5: house();

break;

case 6: ship();

break;

case 7: car();

break;

case 8: cycle();

break;

case 9: rocket();

break;

case 10: bouncing_ball();

break;

case 11:dda();

break;

case 12:b_line();

break;

case 13:b_circle();

break;

case 14:polygon();

break;

case 15: transformation_2d();

break;

case 16: transformation_3d();


break;

case 17: sutherland();

break;

/*case 18: open_gl();

break;*/

default:

exit(0);

getch();

closegraph();

return (0);

void line_pattern()

cleardevice();

line(200,80,300,80);

line(150,100,350,100);

line(100,120,400,120);

line(50,140,450,140);

line(0,160,500,160);

line(0,180,500,180);

line(50,200,450,200);

line(100,220,400,220);

line(150,240,350,240);

line(200,260,300,260);

line(0,160,0,180);

line(50,140,50,200);
line(100,120,100,220);

line(150,100,150,240);

line(200,80,200,260);

line(300,80,300,260);

line(350,100,350,240);

line(400,120,400,220);

line(450,140,450,200);

line(500,160,500,180);

outtextxy(300,300,"Line Pattern");

getch();

void rect_pattern()

cleardevice();

setcolor(5);

rectangle(0,0,300,200);

setfillstyle(3,5);

floodfill(100,100,5);

setcolor(2);

rectangle(400,0,630,200);

setfillstyle(3,2);

floodfill(420,150,2);

setcolor(3);

rectangle(0,300,300,470);

setfillstyle(3,3);

floodfill(200,330,3);
setcolor(4);

rectangle(400,300,630,470);

setfillstyle(3,4);

floodfill(450,320,4);

setcolor(7);

rectangle(200,150,450,350);

outtextxy(230,220,"Rectangle Pattern");

void circle_pattern()

cleardevice();

setcolor(6);

circle(200,100,60);

setfillstyle(4,6);

floodfill(200,100,6);

setcolor(7);

circle(270,100,60);

setfillstyle(4,7);

floodfill(270,100,7);

setcolor(8);

circle(340,100,60);

setfillstyle(4,8);

floodfill(340,100,8);

setcolor(9);

circle(230,170,60);

setfillstyle(4,9);
floodfill(230,170,9);

setcolor(10);

circle(300,170,60);

setfillstyle(4,10);

floodfill(300,170,10);

outtextxy(400,300,"CIRCLE PATTERN");

void circle_sq_pattern()

cleardevice();

setcolor(8);

circle(250,250,50);

setfillstyle(4,8);

floodfill(250,250,8);

setcolor(2);

rectangle(200,200,300,300);

setcolor(3);

circle(250,250,70);

setcolor(4);

rectangle(180,180,320,320);

setcolor(5);

circle(250,250,100);

setcolor(6);

rectangle(150,150,350,350);

setcolor(7);

circle(250,250,140);
outtextxy(370,350,"CIRCLE SQUARE PATTERN");

void house()

// cleardevice();

int points[]={200,200,300,50,400,200,200,200};

int p[]={300,50,520,50,630,200,400,200,300,50};

int q[]={250,250,290,290,290,400,250,400,250,250};

cleardevice();

setcolor(5);

drawpoly(4,points);

setfillstyle(1,5);

floodfill(275,178,5);

setcolor(3);

drawpoly(5,q);

setfillstyle(4,3);

floodfill(265,300,3);

setcolor(4);

rectangle(200,200,400,400);

setcolor(9);

drawpoly(5,p);

setfillstyle(5,9);

floodfill(350,100,9);

setcolor(10);

rectangle(400,200,630,400);

setfillstyle(8,10);
floodfill(410,205,10);

setcolor(4);

rectangle(250,250,330,400);

setcolor(3);

rectangle(450,250,550,320);

setfillstyle(3,3);

floodfill(460,260,3);

line(500,250,500,320);

line(505,250,505,320);

line(450,285,550,285);

line(450,290,550,290);

setcolor(3);

circle(300,150,25);

setfillstyle(1,3);

floodfill(300,150,3);

outtextxy(50,150,"HOUSE");

void ship()

cleardevice();

line(175,350,425,350);

line(175,350,140,265);

line(425,350,465,265);

line(140,265,465,265);

line(160,265,160,175);

line(185,265,185,175);

line(160,175,185,175);
line(160,195,185,195);

rectangle(270,300,290,320);

rectangle(320,300,340,320);

rectangle(220,300,240,320);

rectangle(370,300,390,320);

line(350,265,350,100);//main bar

line(300,220,400,220);

line(320,180,380,180);

line(340,140,360,140);

line(300,220,320,180);

line(320,180,340,140);

line(400,220,380,180);

line(380,180,360,140);

line(325,120,375,120);

circle(230,130,5);

circle(200,150,10);

void car()

int i;

cleardevice();

for(i=0;i<700;i++)

clearviewport();

circle(150+i,380,50);//tire1

circle(150+i,380,30);//rim1

circle(140+i,370,3);//nuts
circle(160+i,370,3);//nuts

circle(160+i,390,3);//nuts

circle(140+i,390,3);//nuts

circle(490+i,380,50);//tire2

circle(490+i,380,30);//rim2

circle(480+i,370,3);//nuts

circle(480+i,390,3);//nuts

circle(500+i,370,3);//nuts

circle(500+i,390,3);//nuts

arc(150+i,380,0,180,65);//covertire1

arc(490+i,380,0,180,65);//covertire2

line(215+i,380,425+i,380);//middle line

line(85+i,380,15+i,380);//leftdown

line(15+i,380,15+i,250);//leftside corner

line(15+i,250,123+i,254);//leftup

line(555+i,380,640+i,380);//right down

arc(480+i,380,0,70,159);//bumper

line(535+i,231,465+i,231);//right up

line(380+i,150,465+i,231);//front mirror

line(380+i,150,200+i,150);//middle up

arc(250+i,240,119,180,103);//back mirror

arc(131+i,240,241,360,15);//down of back mirror

line(200+i,165,370+i,165);//windowupperline

line(170+i,240,445+i,240);//windowlowerline

line(370+i,165,445+i,240);//windowfront

line(200+i,165,170+i,240);//windowback

line(285+i,170,285+i,233);//interiorleftwindo wrightside
line(295+i,170,295+i,233);//interiorrightwindowleftside

line(285+i,170,205+i,170);//interiorleftupper

line(295+i,170,368+i,170);//interiorrightupper

line(205+i,170,180+i,233);//back curve window

line(368+i,170,430+i,233);//frontcurvewindow

line(430+i,233,295+i,233);//interiorrightwindowdown

line(285+i,233,180+i,233);

line(290+i,250,290+i,370);//check line

line(285+i,250,160+i,250);//leftdoorupperside

line(160+i,250,160+i,305);//leftdoorleftside

arc(150+i,380,8,82,75);//leftdoorcurve

line(285+i,370,225+i,370);//leftdoordownside

line(285+i,250,285+i,370);//leftdoorrightside

line(295+i,250,450+i,250);//rightdoorupperside

line(295+i,250,295+i,370);//rightdoorleftside

arc(490+i,380,121,171,75);//rightdoorcurve

line(295+i,370,415+i,370);//rightdoordownside

line(450+i,250,450+i,316);//rightdoorrightside

rectangle(175+i,265,205+i,275);//leftdooropen

rectangle(305+i,265,335+i,275);//rightdooropen

i++;

void cycle()

int p[]={420,300,380,200,320,300,420,300};

int q[]={400,200,400,190,370,190,360,200,400,200};
int r[]={230,130,255,130,255,135,230,135,230,130};

cleardevice();

circle(200,300,60);

circle(200,300,15);

circle(420,300,60);

circle(420,300,15);

line(200,300,230,130);

drawpoly(4,p);

circle(320,300,30);

line(320,300,220,200);

arc(335,200,252,350,40);

line(225,150,330,240);

drawpoly(5,q);

line(320,300,350,360);

line(340,360,360,360);

drawpoly(5,r);

outtextxy(100,50,"CYCLE");

void rocket()

cleardevice();

setcolor(5);

line(250,0,225,50);

line(250,0,275,50);

line(225,50,225,125);

line(275,50,275,125);

line(225,125,100,225);
line(275,125,400,225);

line(100,225,100,240);

line(400,225,400,240);

line(100,240,175,200);

line(400,240,320,200);

line(175,200,225,190);

line(320,200,275,190);

line(225,190,225,290);

line(275,190,275,290);

line(225,290,235,310);

line(275,290,265,310);

line(235,310,185,335);

line(265,310,320,335);

line(185,335,185,350);

line(320,335,320,350);

line(185,350,250,330);

line(320,350,250,330);

line(175,150,175,165);

line(175,150,182,150);

line(182,150,182,160);

line(140,194,140,175);

line(140,175,147,175);

line(147,175,147,186);

line(320,150,320,162);

line(320,150,327,150);

line(327,150,327,166);

line(355,175,355,188);
line(355,175,363,175);

line(363,175,363,195);

settextstyle(1,HORIZ_DIR,3);

outtextxy(200,365,"AEROPLANE");

void bouncing_ball()

/* get mid positions in x and y-axis */

int x,y,flag=0;

x = getmaxx()/2;

y = 30;

while (!kbhit())

if(y >= getmaxy()-30 || y <= 30)

flag = !flag;

/* draws the gray board */

setcolor(RED);

setfillstyle(SOLID_FILL, RED);

circle(x, y, 30);

floodfill(x, y, RED);

/* delay for 50 milli seconds */

delay(50);

/* clears screen */

cleardevice();

if(flag)

y = y + 5;
}

else

y = y - 5;

void dda()

float x , y , x1 , y1 , x2 , y2 , dx, dy;

int i,step ;

cleardevice();

printf( "Enter the value of x1:");

scanf ( "%f%f" , & x1 , & y1 );

printf( "Enter the value of x2:");

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 , 5 );

x = x + dx;

y = y + dy;

i=i+1;

delay ( 100 );

void b_line()

int dx,dy,x,y,p,x1,y1,x2,y2;

cleardevice();

printf("\n\n\tEnter the co-ordinates of first point : ");

scanf("%d %d",&x1,&y1);

printf("\n\n\tEnter the co-ordinates of second point : ");

scanf("%d %d",&x2,&y2);

dx = (x2 - x1);

dy = (y2 - y1);

p = 2 * (dy) - (dx);

x = x1;

y = y1;

putpixel(x,y,WHITE);

while(x <= x2)

if(p < 0)
{

x=x+1;

y=y;

p = p + 2 * (dy);

else

x=x+1;

y=y+1;

p = p + 2 * (dy - dx);

putpixel(x,y,WHITE);

void b_circle()

int r,x,y,p,xc=320,yc=240;

cleardevice();

printf("Enter the radius ");

scanf("%d",&r);

x=0;

y=r;

putpixel(xc+x,yc-y,1);

p=3-(2*r);

for(x=0;x<=y;x++)

if (p<0)
{

y=y;

p=(p+(4*x)+6);

else

y=y-1;

p=p+((4*(x-y)+10));

putpixel(xc+x,yc-y,1);

putpixel(xc-x,yc-y,2);

putpixel(xc+x,yc+y,3);

putpixel(xc-x,yc+y,4);

putpixel(xc+y,yc-x,5);

putpixel(xc-y,yc-x,6);

putpixel(xc+y,yc+x,7);

putpixel(xc-y,yc+x,8);

void polygon()

int n,i,j,k,dy,dx;

int x,y,temp;

int a[20][2],xi[20];

float slope[20];

cleardevice();
printf("\n\n\tEnter the no. of edges of polygon : ");

scanf("%d",&n);

printf("\n\n\tEnter the cordinates of polygon :\n\n\n ");

for(i=0;i<n;i++)

printf("\tX%d Y%d : ",i,i);

scanf("%d %d",&a[i][0],&a[i][1]);

a[n][0]=a[0][0];

a[n][1]=a[0][1];

/*- draw polygon -*/

for(i=0;i<n;i++)

line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);

getch();

for(i=0;i<n;i++)

dy=a[i+1][1]-a[i][1];

dx=a[i+1][0]-a[i][0];

if(dy==0) slope[i]=1.0;

if(dx==0) slope[i]=0.0;

if((dy!=0)&&(dx!=0)) /*- calculate inverse slope -*/

slope[i]=(float) dx/dy;

}
for(y=0;y< 480;y++)

k=0;

for(i=0;i<n;i++)

if( ((a[i][1]<=y)&&(a[i+1][1]>y))||

((a[i][1]>y)&&(a[i+1][1]<=y)))

xi[k]=(int)(a[i][0]+slope[i]*(y-a[i][1]));

k++;

for(j=0;j<k-1;j++) /*- Arrange x-intersections in order -*/

for(i=0;i<k-1;i++)

if(xi[i]>xi[i+1])

temp=xi[i];

xi[i]=xi[i+1];

xi[i+1]=temp;

setcolor(35);

for(i=0;i<k;i+=2)

line(xi[i],y,xi[i+1]+1,y);

getch();
}

void transformation_2d()

int ch,x,y,az,i,w,ch1,ch2,xa,ya,ra,a[10],b[10],da,db;

float x1,y1,az1,w1,dx,dy,theta,x1s,y1s,sx,sy,a1[10],b1[10];

cleardevice();

printf("Enter the upper left corner of the rectangle:\n");

scanf("%d%d",&x,&y);

printf("Enter the lower right corner of the rectangle:\n");

scanf("%d%d",&az,&w);

rectangle(x,y,az,w);

da=az-x;

db=w-y;

a[0]=x;

b[0]=y;

a[1]=x+da;

b[1]=y;

a[2]=x+da;

b[2]=y+db;

a[3]=x;b[3]=y+db;

while(1)

printf("******2D Transformations*******\n");

printf("1.Translation\n2.Rotation\n3.Scaling\n4.Reflection\n5.Shearing\n6.Exit\nEnter your
choice:\n");
scanf("%d",&ch);

switch(ch)

case 1:

rectangle(x,y,az,w);

printf("*******Translation*******\n\n");

printf("Enter the value of shift vector:\n");

scanf("%f%f",&dx,&dy);

x1=x+dx;

y1=y+dy;

az1=az+dx;

w1=w+dy;

rectangle(x1,y1,az1,w1);

break;

case 2:

rectangle(x,y,az,w);

printf("*******Rotation*******\n\n");

printf("Enter the value of fixed point and angle of rotation:Enter the value of fixed point and
angle of rotation:\n");

scanf("%d%d%d",&xa,&ya,&ra);

theta=(float)(ra*(3.14/180));

for(i=0;i<4;i++)

a1[i]=(xa+((a[i]-xa)*cos(theta)-(b[i]-ya)*sin(theta)));

b1[i]=(ya+((a[i]-xa)*sin(theta)+(b[i]-ya)*cos(theta)));

for(i=0;i<4;i++)
{

if(i!=3)

line(a1[i],b1[i],a1[i+1],b1[i+1]);

else

line(a1[i],b1[i],a1[0],b1[0]);

break;

case 3:

rectangle(x,y,az,w);

printf("********Scaling*******\n\n");

printf("Enter the value of scaling factor:\n");

scanf("%f%f",&sx,&sy);

x1=x*sx;

y1=y*sy;

az1=az*sx;

w1=w*sy;

rectangle(x1,y1,az1,w1);

break;

case 4:

rectangle(x,y,az,w);

printf("*******Reflection*********\n");

printf("1.About x-axis\n2.About y-axis\n3.About both axis\nEnter your choice:\n");

scanf("%d",&ch1);

switch(ch1)

case 1:

printf("Enter the fixed point\n");


scanf("%d%d",&xa,&ya);

theta=(float)(90*(3.14/180));

for(i=0;i<4;i++)

a1[i]=(xa+((a[i]-xa)*cos(theta)-(-b[i]-ya)*sin(theta)));

b1[i]=(ya+((a[i]-xa)*sin(theta)+(-b[i]-ya)*cos(theta)));

for(i=0;i<4;i++)

if(i!=3)

line(a1[i],b1[i],a1[i+1],b1[i+1]);

else

line(a1[i],b1[i],a1[0],b1[0]);

break;

case 2:

printf("Enter the fixed point\n");

scanf("%d%d",&xa,&ya);

theta=(float)(270*(3.14/180));

for(i=0;i<4;i++)

a1[i]=(xa+((-a[i]-xa)*cos(theta)-(b[i]-ya)*sin(theta)));

b1[i]=(ya+((-a[i]-xa)*sin(theta)+(b[i]-ya)*cos(theta)));

for(i=0;i<4;i++)

if(i!=3)
line(a1[i],b1[i],a1[i+1],b1[i+1]);

else

line(a1[i],b1[i],a1[0],b1[0]);

break;

case 3:

printf("Enter the fixed point\n");

scanf("%d%d",&xa,&ya);

theta=(float)(180*(3.14/180));

for(i=0;i<4;i++)

a1[i]=(xa+((-a[i]-xa)*cos(theta)-(-b[i]-ya)*sin(theta)));

b1[i]=(ya+((-a[i]-xa)*sin(theta)+(-b[i]-ya)*cos(theta)));

for(i=0;i<4;i++)

if(i!=3)

line(a1[i],b1[i],a1[i+1],b1[i+1]);

else

line(a1[i],b1[i],a1[0],b1[0]);

break;

break;

case 5:

rectangle(x,y,az,w);

printf("*******Shearing******\n\n");
printf("1.x-direction shear\n2.y-direction shear\nEnter your choice:\n");

scanf("%d",&ch2);

switch(ch2)

case 1:

printf("Enter the value of shear:\n");

scanf("%f",&x1s);

x1=x+(y*x1s);

y1=y;

az1=az+(w*x1s);

w1=w;

rectangle(x1,y1,az1,w1);

break;

case 2:

printf("Enter the value of shear:\n");

scanf("%f",&y1s);

x1=x;

y1=y+(x*y1s);

az1=az;

w1=w+(az*y1s);

rectangle(x1,y1,az1,w1);

break;

break;

case 6:

exit(0);

}
}

void axis()

getch();

cleardevice();

line(midx,0,midx,maxy);

line(0,midy,maxx,midy);

void transformation_3d()

int x,y,z,ang,x1,x2,y1,y2;

setfillstyle(3,25);

maxx=getmaxx();

maxy=getmaxy();

midx=maxx/2;

midy=maxy/2;

outtextxy(100,100,"ORIGINAL OBJECT");

line(midx,0,midx,maxy);

line(0,midy,maxx,midy);

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

axis();

outtextxy(100,20,"TRANSLATION");

printf("\n\n Enter the Translation vector: ");

scanf("%d%d",&x,&y);

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+(x+100),midy-(y+20),midx+(x+60),midy-(y+90),20,5);

axis();

outtextxy(100,20,"SCALING");

printf("\n Enter the Scaling Factor: ");

scanf("%d%d%d",&x,&y,&z);

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+(x*100),midy-(y*20),midx+(x*60),midy-(y*90),20*z,5);

axis();

outtextxy(100,20,"ROTATION");

printf("\n Enter the Rotation angle: ");

scanf("%d",&ang);

x1=100*cos(ang*3.14/180)-20*sin(ang*3.14/180);

y1=100*sin(ang*3.14/180)+20*sin(ang*3.14/180);

x2=60*cos(ang*3.14/180)-90*sin(ang*3.14/180);

y2=60*sin(ang*3.14/180)+90*sin(ang*3.14/180);

axis();

printf("\n After rotating about z-axis\n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+x1,midy-y1,midx+x2,midy-y2,20,5);

axis();

printf("\n After rotating about x-axis\n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+100,midy-x1,midx+60,midy-x2,20,5);

axis();

printf("\n After rotating about y-axis\n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+x1,midy-20,midx+x2,midy-90,20,5);
axis();

void sutherland()

float i,xmax,ymax,xmin,ymin,x1,y1,x2,y2,m;

float start[4],end[4],code[4];

cleardevice();

printf("\n\tEnter the bottom-left coordinate of viewport: ");

scanf("%f %f",&xmin,&ymin);

printf("\n\tEnter the top-right coordinate of viewport: ");

scanf("%f %f",&xmax,&ymax);

printf("\nEnter the coordinates for starting point of line: ");

scanf("%f %f",&x1,&y1);

printf("\nEnter the coordinates for ending point of line: ");

scanf("%f %f",&x2,&y2);

for(i=0;i <4;i++)

start[i]=0;

end[i]=0;

m=(y2-y1)/(x2-x1);

if(x1 <xmin) start[0]=1;

if(x1 >xmax) start[1]=1;

if(y1 >ymax) start[2]=1;

if(y1 <ymin) start[3]=1;

if(x2 <xmin) end[0]=1;

if(x2 >xmax) end[1]=1;


if(y2 >ymax) end[2]=1;

if(y2 <ymin) end[3]=1;

for(i=0;i <4;i++)

code[i]=start[i]&&end[i];

if((code[0]==0)&&(code[1]==0)&&(code[2]==0)&&(code[3]==0))

if((start[0]==0)&&(start[1]==0)&&(start[2]==0)&&(start[3]==0)&&(end[0]==0)&&(end[1]
==0)&&(end[2]==0)&&(end[3]==0))

cleardevice();

printf("\n\t\tThe line is totally visible\n\t\tand not a clipping candidate");

rectangle(xmin,ymin,xmax,ymax);

line(x1,y1,x2,y2);

getch();

else

cleardevice();

printf("\n\t\tLine is partially visible");

rectangle(xmin,ymin,xmax,ymax);

line(x1,y1,x2,y2);

getch();

if((start[2]==0)&&(start[3]==1))

x1=x1+(ymin-y1)/m;

y1=ymin;

}
if((end[2]==0)&&(end[3]==1))

x2=x2+(ymin-y2)/m;

y2=ymin;

if((start[2]==1)&&(start[3]==0))

x1=x1+(ymax-y1)/m;

y1=ymax;

if((end[2]==1)&&(end[3]==0))

x2=x2+(ymax-y2)/m;

y2=ymax;

if((start[1]==0)&&(start[0]==1))

y1=y1+m*(xmin-x1);

x1=xmin;

if((end[1]==0)&&(end[0]==1))

y2=y2+m*(xmin-x2);

x2=xmin;

if((start[1]==1)&&(start[0]==0))

{
y1=y1+m*(xmax-x1);

x1=xmax;

if((end[1]==1)&&(end[0]==0))

y2=y2+m*(xmax-x2);

x2=xmax;

clrscr();

cleardevice();

printf("\n\t\tAfter clippling:");

rectangle(xmin,ymin,xmax,ymax);

line(x1,y1,x2,y2);

getch();

else

clrscr();

cleardevice();

printf("\nLine is invisible");

rectangle(xmin,ymin,xmax,ymax);

getch();

}
----------------------------OUTPUT---------------------------

You might also like