Kajal

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 74

Question 1 :- Write a program to show the implementation of Line Drawing

algoritham (Bresenhams Line Drawing)?


Solution :#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int dx,dy,x,y,p,x1,y1,x2,y2;
int gd,gm;
clrscr();
printf("\n\n\t Enter the co-orinates of the first point : ");
scanf("%d%d",&x1,&y1);
printf("\n\n\t Enter the co-orinates of the second point :");
scanf("%d%d",&x2,&y2);
dx=(x2-x1);
dy=(y2-y1);
p=2*(dy)-(dx);
x=x1;
y=y1;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
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);
}
getch();
closegraph();
}

OUTPUT:-

Question 2:-Write a program to show the implementation of circle drawing using


mid point circle algorithm ?
Solution :#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void Drawcircle(int,int,int);
void main()
{
int gd=DETECT,gm;
int x,y,r;
printf("Enter the x and y coordinates of the circle :");
scanf("%d%d",&x,&y);
printf("\n Enter the Radius :");
scanf("%d",&r);
initgraph(&gd,&gm,"C:\\TC\\BGI");
Drawcircle(x,y,r);
getch();
closegraph();
}
void Drawcircle(int x1,int y1,int r)
{
int x=0,y=r,p=1-r;
putpixel(x,y,RED);
while(x<y)

{
x++;
if(p<0)
p+=2 * x+1;
else
{
y--;
p+=2 * (x-y)+1;
}
putpixel(x1 +x,y1 +y,RED);
putpixel(x1 -x,y1 +y,RED);
putpixel(x1 +x,y1 -y,RED);
putpixel(x1 -x,y1 -y,RED);
putpixel(x1 +y,y1 +x,RED);
putpixel(x1 -y,y1 +x,RED);
putpixel(x1 +y,y1 -x,RED);
putpixel(x1 -y,y1 -x,RED);
}
}

OUTPUT:-

Question 3:- Write a program to show the implementation of circle drawing using
bresenhams circle drawing algorithm ?
Solution :#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void breshcir(int xc,int yc,int r);
void main()
{
int r,xc,yc,gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");
printf("\nEnter the x and y coorinates of the circle :");
scanf("%d%d",&xc,&yc);
printf("Enter the radius of the circle\n :");
scanf("%d",&r);
breshcir(xc,yc,r);
getch();
}
void breshcir(int xc,int yc,int r)
{
int p,x,y;
x=0;
y=r;

p=3 - 2*r;
while(x<=y)
{
putpixel(xc+x,yc-y,2);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,2);
putpixel(xc-x,yc+y,2);
putpixel(xc+y,yc-x,2);
putpixel(xc-y,yc-x,2);
putpixel(xc+y,yc+x,2);
putpixel(xc-y,yc+x,2);
If (p<0)
p=p + 4*x + 6;
else
{
p=p + 4*(x-y) +10;
y=y-1;
}
x=x+1;
}
}

OUTPUT:-

Question 4:- Write a program to show the implementation of Ellipse drawing using
Mid Point algorithm?
Solution :#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>
int main(void)
{
int gd=DETECT,gm;
int cenx,ceny;
float Pk,a,b,x,y;
clrscr();

printf("\n\n Enter 'a' and 'b': ");


scanf("%f%f",&a,&b);

initgraph(&gd,&gm,"c:\\tc\\bgi");

cenx=getmaxx()/2;
ceny=getmaxy()/2;

Pk=b*b-b*a*a+0.25*a*a;
x=0;
y=b;
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
while (2*x*b*b <= 2*y*a*a)
{
if (Pk<0)
{
x=x+1;
y=y;
Pk=Pk+2*x*b*b+3*b*b;
}
else
{
x=x+1;
y=y-1;
Pk=Pk+2*x*b*b+3*b*b-2*y*a*a+2*a*a;
}
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);

delay(40);
}
Pk=(x+0.5)*(x+0.5)*b*b+(y-1)*(y-1)*a*a-a*a*b*b;
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
while (y>0)
{
if (Pk>0)
{
x=x;
y=y-1;
Pk=Pk-2*y*a*a+3*a*a;
}
else
{
x=x+1;
y=y-1;
Pk=Pk-2*y*a*a+3*a*a+2*x*b*b+2*b*b;
}
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);

delay(40);
}
gotoxy(1,25);
printf ("\npress any key to exit.");
getch();
closegraph();
return 0;
}

OUTPUT:

Question 5:- Write a program to show the implementation of 2D transformation of


the following :
(A) Translation,Scaling ,Rotation
(B) Reflection and Shearing
Solution:
(A)
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void translate();
void scale();
void rotate();
void main()
{
int ch;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(6);
outtextxy (100,88,"Object.");
rectangle(100,150,150,100);
printf("---MENU---");
printf("\n 1)Translate\n 2)Scale\n 3)Rotate");
printf("\nEnter your choice: ");
scanf("%d",&ch);

cleardevice();
switch(ch)
{
case 1: translate();
break;
case 2: scale();
break;
case 3: rotate();
break;
default: printf("you have enterd wrong choice");
break;
}
getch();
closegraph();
}
void translate()
{
int tx,ty;
setcolor(2);
outtextxy(240,10,"TRANSLATION");
outtextxy(238,20,"------------");
printf("\nEnter tx: ");
scanf("%d",&tx);
printf("\nEnter ty: ");
scanf("%d",&ty);

cleardevice();
rectangle(100,150,150,100);
printf("\nAfter Translation");
rectangle(100+tx,150+ty,150+tx,100+ty);
}
void scale()
{
int sx,sy;
setcolor(2);
outtextxy(240,10,"SCALING");
outtextxy(238,20,"--------");
printf("\nEnter sx: ");
scanf("%d",&sx);
printf("\nEnter sy: ");
scanf("%d",&sy);
cleardevice();
rectangle(100,150,150,100);
printf("\nAfter Scaling");
rectangle(100*sx,150*sy,150*sx,100*sy);
}
void rotate()
{
float theta;
int x1,x2,x3,x4;
int y1,y2,y3,y4;

int ax1,ax2,ax3,ax4,ay1,ay2,ay3,ay4;
int refx,refy;
printf("\nEnter the angle for rotation: ");
scanf("%f",&theta);
theta=theta*(3.14/180);
cleardevice();
setcolor(2);
outtextxy(240,10,"ROTATE");
outtextxy(238,20,"-------");
refx=100;
refy=100;

x1=100;
y1=100;
x2=150;
y2=100;
x3=150;
y3=150;
x4=100;
y4=150;

ax1=refy+(x1-refx)*cos(theta)-(y1-refy)*sin(theta);
ay1=refy+(x1-refx)*sin(theta)+(y1-refy)*cos(theta);
ax2=refy+(x2-refx)*cos(theta)-(y2-refy)*sin(theta);
ay2=refy+(x2-refx)*sin(theta)+(y2-refy)*cos(theta);

ax3=refy+(x3-refx)*cos(theta)-(y3-refy)*sin(theta);
ay3=refy+(x3-refx)*sin(theta)+(y3-refy)*cos(theta);
ax4=refy+(x4-refx)*cos(theta)-(y4-refy)*sin(theta);
ay4=refy+(x4-refx)*sin(theta)+(y4-refy)*cos(theta);
rectangle(100,150,150,100);
line(ax1,ay1,ax2,ay2);
line(ax2,ay2,ax3,ay3);
line(ax3,ay3,ax4,ay4);
line(ax4,ay4,ax1,ay1);
}

OUTPUT:

(B)
#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-AXIS");
printf("n\t2) ABOUT Y-AXIS");
printf("\n\t3) ABOUT ORIGIN");
printf("\n\t4) ABOUT X=Y");

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;
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:\\TC\\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 * * *");
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();
}

OUTPUT:-

Question 6:- Write a program to implement Cohen Sutherland Line Clipping?


Solution :#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
#include<process.h>
int pixels[2][4];
float xn1,xn2,yn1,yn2,x3,y3,m;
int xmin,ymin,xmax,ymax,x1,y1,x2,y2;
int choice,ed[20],num;
void su_co(int x1,int y1,int x2,int y2,int xmin,int ymin,int xmax,int ymax)
{
int i,j,fl;
for(i=0;i<2;i++)
for(j=0;j<4;j++)
pixels[i][j]=0;
if(y1>ymax)
pixels[0][0]=1;
if(y1<ymin)
pixels[0][1]=1;
if(x1>xmax)
pixels[0][2]=1;
if(x1<xmin)

pixels[0][3]=1;
if(y2>ymax)
pixels[1][0]=1;
if(y2<ymin)
pixels[1][1]=1;
if(x2>xmax)
pixels[1][2]=1;
if(x2<xmin)
pixels[1][3]=1;
for(j=0;j<4;j++)
{
if(pixels[0][j]==0&&pixels[1][j]==0)
continue;
if(pixels[0][j]==1&&pixels[1][j]==1)
{
fl=3;
break;
}
fl=2;
}
switch(fl)
{
case 1:
line(320+x1,240-y1,320+x2,240-y2);
break;

case 3:
printf("\n\n\a\ Line Is Not Visible:");
break;
case 2:
m=(y2-y1)/(x2-x1);
xn1=x1;
yn1=y1;
xn2=x2;
yn2=y2;
if(pixels[0][0]==1)
{
xn1=x1+(ymax-y1)/m;
yn1=ymax;
}
if(pixels[0][1]==1)
{
xn1=x1+(ymin-y1)/m;
yn1=ymin;
}
if(pixels[0][2]==1)
{
yn1=y1+(xmax-x1)*m;
xn1=xmax;
}
if(pixels[0][3]==1)

{
yn1=y1+(xmin-x1)*m;
xn1=xmin;
}
if(pixels[1][0]==1)
{
xn2=x2+(ymax-y2)/m;
yn2=ymax;
}
if(pixels[1][1]==1)
{
xn2=x2+(ymin-y2)/m;
yn2=ymin;
}
if(pixels[1][2]==1)
{
yn2=y2+(xmax-x2)*m;
xn2=xmax;
}
if(pixels[1][3]==1)
{
yn2=y2+(xmin-x2)*m;
xn2=xmin;
}
line(320+xn1,240-yn1,320+xn2,240-yn2);

break;
}
}
void cohen()
{
clearviewport();
line(320+xmin,240-ymin,320+xmin,240-ymax);
line(320+xmin,240-ymax,320+xmax,240-ymax);
line(320+xmax,240-ymax,320+xmax,240-ymin);
line(320+xmax,240-ymin,320+xmin,240-ymin);
line (320+x1,240-y1,320+x2,240-y2);
getch();
cleardevice();
line(320+xmin,240-ymin,320+xmin,240-ymax);
line(320+xmin,240-ymax,320+xmax,240-ymax);
line(320+xmax,240-ymax,320+xmax,240-ymin);
line(320+xmax,240-ymin,320+xmin,240-ymin);
su_co(x1,y1,x2,y2,xmin,ymin,xmax,ymax);
getch();
}
void main()
{
int gd=DETECT,gm,i,j;
initgraph(&gd,&gm,"C:\\TC\\BGI");
printf("\n\n\t\t\ Enter The Co-Ordinates Of The Clipping Window");

printf("\n\n\t\t\ Enter X(min) & Y(min) :=");


scanf("%d %d",&xmin,&ymin);
printf("\n\t\t\" Enter X(max) & Y(max) \":=");
scanf("%d %d",&xmax,&ymax);
printf("\n\t\t\" Enter The Co-Ordinates Of The Line.");
printf("\n\n\t\t\" Enter X(1) & Y(1) :=");
scanf("%d %d",&x1,&y1);
printf("\n\t\t\" Enter X(2) & Y(2) \":=");
scanf("%d %d",&x2,&y2);
clrscr();
cohen();
}

OUTPUT :-

Question 7:- Write a program to show the implementation of 3D transformation?


Solution :#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int maxx,maxy,midx,midy;
void axis()
{
getch();
cleardevice(); //clear the graphics screen
line(midx,0,midx,maxy);
line(0,midy,maxx,midy);
}
void main()
{
int gd,gm,x,y,z,o,x1,x2,y1,y2,ch;
detectgraph(&gd,&gm); //determine graphics driver
initgraph(&gd,&gm,"c:\\tc\\bgi"); //initialize the graphics system
setfillstyle(0,getmaxcolor()); //set fill pattern & colour
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
printf("*****main menu****");

printf("\n 1.TRANSLATION");
printf("\n 2.SCALING");
printf("\n 3.ROTATION");printf("\n\n Enter your choice(1/2/3)");
scanf("%d",&ch);
switch(ch)
{
case 1:
axis();
bar3d(midx+100,midy-150,midx+60,midy-100,10,1);
printf("\Enter the translation factor");
scanf("%d%d",&x,&y);
axis();
printf("After translation");
bar3d(midx+100,midy-150,midx+60,midy-100,10,1);

//draw a bar

bar3d(midx+x+100,midy-(y+150),midx+x+60,midy-(y+100),10,1); //draw a bar


case 2:
axis();
bar3d(midx+100,midy-150,midx+60,midy-100,10,1); //draw a bar
printf("Enter the scaling factor");
scanf("%d%d%d",&x,&y,&z);
axis();
printf("After scaling");
bar3d(midx+100,midy-150,midx+60,midy-100,10,1); //draw a bar
bar3d(midx+(x*100),midy-(y*150),midx+(x*60),midy-(y*100),10*z,1);
case 3:

axis();
bar3d(midx+100,midy-150,midx+60,midy-100,10,1);
printf("Enter the rotation angle");
scanf("%d",&o);
x1=50*cos(o*3.14/180)-100*sin(o*3.14/180);
y1=50*sin(o*3.14/180)+100*cos(o*3.14/180);
x2=60*cos(o*3.14/180)-90*sin(o*3.14/180);
y2=60*sin(o*3.14/180)+90*cos(o*3.14/180);
axis();
printf("After rotating about Z-axis");
bar3d(midx+100,midy-150,midx+60,midy-100,10,1);
bar3d(midx+x1,midy-y1,midx+x2,midy-y2,10,1);
axis();
printf("After rotating about x-axis");
bar3d(midx+100,midy-150,midx+60,midy-100,10,1); //draw a bar
bar3d(midx+100,midy-x1,midx+60,midy-x2,10,1);
axis();
printf("After rotating about Y-axis");
bar3d(midx+100,midy-150,midx+60,midy-100,10,1); //draw a bar
bar3d(midx+x1,midy-150,midx+x2,midy-100,10,1); //draw a bar
}
getch();
closegraph();
}

OUTPUT:-

Question 8:- Write a program of Beizer Curve?


Solution :#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>
#include<conio.h>
void bezier (int x[4], int y[4])
{
int gd = DETECT, gm;
int i;
double t;

initgraph (&gd, &gm, "..\\bgi");

for (t = 0.0; t < 1.0; t += 0.0005)


{
double xt = pow (1-t, 3) * x[0] + 3 * t * pow (1-t, 2) * x[1] +
3 * pow (t, 2) * (1-t) * x[2] + pow (t, 3) * x[3];

double yt = pow (1-t, 3) * y[0] + 3 * t * pow (1-t, 2) * y[1] +


3 * pow (t, 2) * (1-t) * y[2] + pow (t, 3) * y[3];

putpixel (xt, yt, WHITE);


}

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


putpixel (x[i], y[i], YELLOW);

getch();
closegraph();
return;
}

void main()
{
int x[4], y[4];
int i;

printf ("Enter the x- and y-coordinates of the four control points.\n");


for (i=0; i<4; i++)
scanf ("%d%d", &x[i], &y[i]);

bezier (x, y);


}

OUTPUT :-

Question 9:-Write a program of the implementation of the Fan?


Solution :#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
void fan(int );
int main()
{
int gd=DETECT,gm,r;
initgraph(&gd,&gm,"c:\\tc\\bgi");
//initwindow(500, 500, "First Sample");
fan(100);
getch();
}

void fan(int p)
{
int xf,yf;
int x1,y1,x2,y2,x3,y3,x4,y4;
int j=0,i;
float t;
setcolor(12);
xf=150; //Center of circle
yf=150;

t=3.14/180;
while(j==0 )
{
for(;;i++)
{
cleardevice();
circle(150,150,25);
circle(150,150,1);
line(150,126,150,100);
x1=xf+(175-xf)*cos(120*t+i)-(130-yf)*sin(120*t+i);
y1=yf+(175-xf)*sin(120*t+i)+(130-yf)*cos(120*t+i);
x2=xf+(275-xf)*cos(120*t+i)-(130-yf)*sin(120*t+i);
y2=yf+(275-xf)*sin(120*t+i)+(130-yf)*cos(120*t+i);
x3=xf+(175-xf)*cos(120*t+i)-(150-yf)*sin(120*t+i);
y3=yf+(175-xf)*sin(120*t+i)+(150-yf)*cos(120*t+i);
x4=xf+(275-xf)*cos(120*t+i)-(150-yf)*sin(120*t+i);
y4=yf+(275-xf)*sin(120*t+i)+(150-yf)*cos(120*t+i);
line(x1,y1,x2,y2);
line(x2,y2,x4,y4);
line(x4,y4,x3,y3);
line(x3,y3,x1,y1);
x1=xf+(175-xf)*cos(240*t+i)-(130-yf)*sin(240*t+i);
y1=yf+(175-xf)*sin(240*t+i)+(130-yf)*cos(240*t+i);
x2=xf+(275-xf)*cos(240*t+i)-(130-yf)*sin(240*t+i);
y2=yf+(275-xf)*sin(240*t+i)+(130-yf)*cos(240*t+i);

x3=xf+(175-xf)*cos(240*t+i)-(150-yf)*sin(240*t+i);
y3=yf+(175-xf)*sin(240*t+i)+(150-yf)*cos(240*t+i);
x4=xf+(275-xf)*cos(240*t+i)-(150-yf)*sin(240*t+i);
y4=yf+(275-xf)*sin(240*t+i)+(150-yf)*cos(240*t+i);
line(x1,y1,x2,y2);
line(x2,y2,x4,y4);
line(x4,y4,x3,y3);
line(x3,y3,x1,y1);
x1=xf+(175-xf)*cos(360*t+i)-(130-yf)*sin(360*t+i);
y1=yf+(175-xf)*sin(360*t+i)+(130-yf)*cos(360*t+i);
x2=xf+(275-xf)*cos(360*t+i)-(130-yf)*sin(360*t+i);
y2=yf+(275-xf)*sin(360*t+i)+(130-yf)*cos(360*t+i);
x4=xf+(175-xf)*cos(360*t+i)-(150-yf)*sin(360*t+i);
y4=yf+(175-xf)*sin(360*t+i)+(150-yf)*cos(360*t+i);
x3=xf+(275-xf)*cos(360*t+i)-(150-yf)*sin(360*t+i);
y3=yf+(275-xf)*sin(360*t+i)+(150-yf)*cos(360*t+i);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x4,y4);
line(x4,y4,x1,y1);
delay(p);
}
}
}

OUTPUT:-

Question 10:- Write a program to implement a micky mouse?


Solution :#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<alloc.h>
void *buf;
void firstleft();
void secondleft();
void main()
{
int gd=DETECT,gm,i=0,x,y,area;
initgraph(&gd,&gm,"C:\\TC\\BGI");
rectangle(0,0,getmaxx(),getmaxy());
arc(240,120,40,140,70);
ellipse(165,80,10,280,20,20);
ellipse(315,80,-100,170,20,20);
arc(235,120,163,215,70);
arc(245,120,-35,17,70);
ellipse(193,178,85,280,40,20);
ellipse(283,178,-100,95,40,20);
ellipse(238,199,180,0,39,50);
ellipse(213,123,44,240,33,40);
ellipse(262,123,-60,135,33,40);
ellipse(210,123,0,360,13,20);//left eye

ellipse(265,123,0,360,13,20);//right eye
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
ellipse(238,160,0,360,10,13);//nose
arc(240,125,228,312,68);//mouth
arc(240,120,230,310,72);//mouth
setfillstyle(1,4);
floodfill(238,160,15);//nose
setfillstyle(1,15);
floodfill(210,113,15);
floodfill(265,113,15);
setfillstyle(1,9);
floodfill(210,100,15);
setfillstyle(1,1);
floodfill(315,80,15);
moveto(203,220);
lineto(203,260);
lineto(183,260);
lineto(183,350);
lineto(293,350);
lineto(293,260);
lineto(273,260);
lineto(273,220);

moveto(183,350);
lineto(173,460);
lineto(213,460);
lineto(238,400);
lineto(263,460);
lineto(303,460);
lineto(293,350);
moveto(173,460);
lineto(143,478);
lineto(213,478);
lineto(213,460);
moveto(263,460);
lineto(263,478);
lineto(333,478);
lineto(303,460);
line(238,400,238,350);
//right hand
moveto(183,260);
lineto(113,310);
lineto(183,375);
moveto(183,280);
lineto(137,310);
lineto(181,353);
setfillstyle(2,13);
floodfill(190,300,15);

setfillstyle(1,5);
floodfill(223,400,15);
setfillstyle(1,5);
floodfill(253,400,15);
setfillstyle(1,6);
floodfill(173,470,15);
floodfill(303,470,15);
//fingers
secondleft();
ellipse(413.5,228,0,180,3.5,3.5);
line(420,240,433,240);
line(423,247,440,247);
line(413,240,410,228);
line(417,228,420,240);
ellipse(433,243.5,-90,90,3.5,3.5);
line(423,254,440,254);
ellipse(440,250.5,-90,90,3.5,3.5);
ellipse(430,257,-90,90,3,3);
line(413,260,430,260);
area=imagesize(409,224,444,261);
buf=malloc(area);
getimage(409,224,444,261,buf);
while(!kbhit())
{
if(i==0)

{
setfillstyle(1,15);
setcolor(15);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
setcolor(0);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(391,209,buf,1);
firstleft();
setcolor(15);
secondleft();
putimage(409,224,buf,0);
i=1;
}
else
{
setfillstyle(1,0);
setcolor(0);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
floodfill(210,133,0);

floodfill(265,133,0);
setcolor(15);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(409,224,buf,1);
secondleft();
setcolor(15);
firstleft();
putimage(391,209,buf,0);
i=0;
}
delay(300);
}
getch();
}
void firstleft()
{
moveto(293,260);
lineto(353,276);
lineto(395,223);
moveto(293,280);
lineto(355,296);

lineto(395,245);
}
void secondleft()
{
moveto(293,260);
lineto(363,280);
lineto(413,240);
moveto(293,280);
lineto(363,300);
lineto(413,260);
}

OUTPUT :-

You might also like