Você está na página 1de 23

PRACTICAL No : 1:

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
int x1,x2,y1,y2,gd=DETECT,gm;
void linebres(int x1 ,int x2, int yl ,int y2);
clrscr();
printf("enter the coordinates of starting points :\n");
scanf("%d %d %d %d",&x1,&x2,&y1,&y2);
initgraph(&gd,&gm,"c:\\tc\\bgi");
linebres(x1,x2,y1,y2);
getch();
closegraph();
}
void linebres(int x1,int x2,int y1,int y2)
{
int dx,dy,x,y;
float xend,p;
dx=abs(x2-x1);
dy=abs(y2-y1);

p=2*dy-dx;
if(x1>x2)
{
x=x2;
y=y2;
xend=x1;

}
else
{
x=x1;
y=y1;
xend=x1;
}
putpixel(x,y,14);
while(x<xend)
{
x=x+1;
if(p<0)
p=p+2*dy;
else
{
x=x+1;

if(p<0)
p=p+2*(dy-dx);
}
putpixel(x,y,14);
}
}

PRACTICAL No : 2:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
int xl,x2,yl,y2,gd=DETECT,gm;
void drawingline(int xl ,int x2, int yl ,int y2);
printf("enter the coordinates of starting points :\n");
scanf("%d %d %d %d",&xl,&x2,&yl,&y2);
initgraph(&gd,&gm,"c:\\tc\\bgi");
drawingline(xl,x2,yl,y2);
getch();
closegraph();
}
void drawingline(int xl ,int x2,int yl ,int y2)
{
int s;
double dy,dx,m,y;
dy=abs(y2-yl);
dx=abs(x2-xl);
m=dy/dx;

y=yl;
for(s=xl;s<=x2;s++)
{
putpixel(s,abs(y),12);
y+=m;
}
}

PRACTICAL No : 3:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
plot (int xc,int yc,int x,int y);
void bcircle(int xc,int yc,int r);
void main()
{
int xc,yc,r;
int gd=DETECT,gm;
printf("enter the centre coordinates & radius");
scanf("%d %d %d",&xc,&yc,&r);
initgraph(&gd,&gm,"c:\\tc\\bgi");
bcircle(xc,yc,r);
putpixel(xc,yc,4);
getch();
closegraph();
}
void bcircle(int xc,int yc,int r)
{
int x,y=r,p=1-r;
for(x=0;x<y;x++)

{
y=(p<0)?y:y-1;
p=(p<0)?p+2*(x+1):(x+1)+1-2*(y-1);
plot(xc,yc,x,y);
}
}
plot (int xc,int yc,int y,int x)
{
putpixel(xc+x,yc+y,30);
putpixel(xc-x,yc+y,30);
putpixel(xc+x,yc-y,30);
putpixel(xc-x,yc-y,30);
putpixel(xc+y,yc+x,30);
putpixel(xc-y,yc+x,30);
putpixel(xc+y,yc-x,30);
putpixel(xc-y,yc-x,30);
return 0;
}

PRACTICAL No : 4:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdlib.h>
void setcolour();
void main()
{
int xl ,x2,yl ,y2,gd=DETECT,gm,c,tx,ty,m,t,xf,yf;
float sx,sy;
void linebres(int x1 ,int yl ,int x2,int y2);
clrscr();
printf("Enter the co ordinates of starting & ending points");
scanf("%d %d %d %d"&x1,&x2,&y1,&y2);
xxx:printf("\t\t PRESS 1--- TRANSLATION \n\n");
prinff("\t\t PRESS 2 ---ROTATION \n\n");
printf("\t\t PRESS 1 ---SCALING \n\n");
printf("\t\t PRESS 1 ---EXIT \n\n");
scanf("%d", &c);
switch(c);
{
case 1:
printf("Enter the number of pixel to be translated");
scanf("%d %d",&tx,&ty);
initgraph(&gd,&gm,"");
setcolor(6);
line(xl ,x2,yl ,y2);
getch();
cleardevice();
setcolor(6);
lie(xl +tx,x2+tx,yl +ty,y2+ty);
getch();
closegraph(); -

break;
case 2:
printf("enter the angle of rotation :n");
scanf("%d",&t);
printf("if you want a simple rotation press 1 :\n");
printf("else for fixed point press 2: \n");
scanf("%d",&m);
switch(m)
{
case 1:
initgraph(&gd,&gm,"");
setcolor(6);
getch();
cleardevice();
xl =x1 *cos(t) yl *sin(t);
yl =xl *smn(t)+yl *cos(t);
setcolor(6);
line(xl ,x2,yl ,y2);
getch();
closegraph();
break;
}
case 2:
printf("Enter the coordinates of the fixed points");
scanf("%d %d", &xf,&yf);
initgraph(&gd,&gm,"");
setcolor(6);
line(xl ,x2,yl ,y2);
getch();
cleardevice();
xl =xf+abs(((xl- xf))*cos(t)-(yl- yf)*sin(t));
x2=xf+abs(((x2-xf))*cos(t)-(y2-yf)*sin(t));
yl =yf+abs(((xl -xf))*cos(t)-(yl- yf)*cos(t));
yl =yf+abs(((x2-xf))*sin(t)-(y2-yf)*cos(t));

setcolor(6);
line(xl ,x2,yl ,y2);
getch();
closegraph();
break;
default:
printf("ERROR!! !")
}
case 3:
printf("Enetr the value of scaling factor :\n");
scanf("%d %f",&sx,&sy);
printf("if you want simple scaling press 1 :\n");
printf("else for fixed point scaling then press 2:\n");
scanf(%d",&m);
switch(m);
{
case 1:
initgraph(&gd,&gm,"");
setcolor(6);
getch();
cleardevice();
setcolor(6);
line(xl ,x2,yl ,y2);
getch();
closegraph();
break;
case 2:
printf("Enter the coordinates of the fixed points");
scanf("%d %d", &xf,&yf);
initgraph(&gd,&gm,"");
setcolor(6);
line(xl ,x2,yl,y2);
getch();
cleardevice();
xl =xl *sx+xf*(1-sx);

x2=x2*sx+xf*( 1-sx);
yl =yl *sy+yf*( 1 -sy);
yl=yl*sy+yf*(1 -sy);
setcolor(6);
line(xl ,x2,yl ,y2);
getch();
closegraph();
break;
default:
printf("ERROR !!!);
getch();
}
case 4:
exit(O);
default:
printf("ERROR ");
break;
}
goto xxx;
}

PRACTICAL No : 5:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdlib.h>
void setcolour();
void main()
{
int gd=DETECT,gm,a,b,c,d,e,i,h,j,k,l,s,r,o;
float x,y,z,m,n;
char msg[80];
printf("Enter five numbers");
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
if(a>1200||b>1200||c>1200||d>1200||e>1200)
{
printf("\n\n\n\n\n\t\t **** VALUE BEYOND THE
GRAPH****");
getch();
closegraph();
}

x=a/27+60;
h=480-x;
y=b/2.7+60;
i=480-y;
z=c/0.7+60;
j=480-z;
m=d/2.7+60;
k=480-m;
n=e/2.7+60;
l=480-n;
setcolor(0);
sprintf(msg,"%d",o);
outtextxy(50,432,msg);
for(r=160,s=l;r<=560,s<6;r+=100,s++)
sprintf(msg,"%d",s);
outtextxy(50 ,432 ,msg);
for(r=382,s=100;r<=40,s<=1000;r-=38,s+=100)
{
setcolor(10);
sprintf(msg,"%d",s);
outtextxy(30,r,msg);
}
setcolor(4);

line(0,420,640,420);
line(60,20,60,480);
for(r=382;r>=40;r-=38)
putpixel(60, r, 14);
for(r=60;r<=560;r+100)
putpixel(r,420,14);
setfillstyle(2,1);
bar3d(150,h,170,420,10,1);
setfillstyle(1,13);
bar3d(250,l,270,420,10,1);
setfillstyle(3,14);
bar3d(350,j,370,420,10,1);
setfillstyle(8,10);
bar3d(450,k,470,420,10,1);
setfillstyle(11,12);
bar3d(550,l,570,420,10,1);
getch();
closegraph();
}

PRACTICAL No : 6:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdlib.h>
void setcolour();
void main()
{
int x1,x2,y1,y2,gd=DETECT,gm,x,y,m,t,xf,yf;
float a,b;
clrscr();
printf("Enter the co ordinates of starting & ending points");
scanf("%d %d %d %d",&x1,&x2,&y1,&y2);
printf("Enter the angle of rotation :\n\n");
scanf("%d",&t);
a=cos(t*0.017453);
b=sin(t*0.017453);
printf("if you want a simple rotation press 1 :\n");
printf("else for fixed point rotation press 2: \n");
scanf("%d",&m);
switch(m)
{

case 1:
initgraph(&gd,&gm,"c:\\tc\\bgi");
line(x1,x2,y1,y2);
getch();
cleardevice();
x=x1*a-y1*b;
y=x1*b+y1*a;
line(x,y,x2,y2);
getch();
closegraph();
break;
case 2:
printf("Enter the coordinates of the fixed points");
scanf("%d %d",&xf,&yf);
initgraph(&gd,&gm,"c:\\tc\\bgi");
line(x1,x2,y1,y2);
getch();
cleardevice();
x=xf+(x2-xf)*a+(y2-yf)*b;
y=yf-(x2-xf)*b+(y2-yf)*a;
line(x1,y1,x,y);
getch();
closegraph();

break;
default:
printf("ERROR!!!!");
}
}

PRACTICAL No : 7:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int x1,x2,y1,y2,gd=DETECT,gm,m,t,xf,yf;
float sx,sy;

void linebres(int x1,int y1,int x2,int y2);


clrscr();
printf("Enter the co ordinate of starting & endingpoints");
scanf("%d %d %d %d",&x1,&x2,&y1,&y2);
printf("Enter the scaling factor :\n\n");
scanf("%f %f",&sx,&sy);
printf("if you want a simple scaling press 1 :\n");
printf("else for fixed point scaling press 2: \n");
scanf("%d",&m);
switch(m)
{
case 1:

initgraph(&gd,&gm,"c:\\tc\\bgi");
line(x1,x2,y1,y2);
getch();
cleardevice();

linebres(x1*sx,y1*sy,x2*sx,y2*sy);
getch();
closegraph();
break;
case 2:
printf("Enter the coordinates of the fixed points");
scanf("%d %d", &xf,&yf);
initgraph(&gd,&gm,"c:\\tc\\bgi");
linebres(x1,x2,y1,y2);
getch();
cleardevice();
x1 =x1*sx+xf*(1-sx);
y1 =y1*sy+yf*(1-sy);
x2 =x2*sx+xf*(1-sx);
y2 =y2*sx+yf*(1-sy);
linebres(x1,y1,x2,y2);
getch();
closegraph();

break;
default:
printf("ERROR!!!!");

}
getch();
}
void linebres(int x1,int y1,int x2,int y2)
{
int dx,dy,x,y,xend,p;
dx=abs(x2-x1);
dy=abs(y2-y1);
p=2*dy-dx;
if(x1>x2)
{
x=x2;
y=y2;
xend=x1;
}
else
{
x=x1;
y=y1;

xend=x2;
}
putpixel(x,y,14);
while(x<xend)
{

x=x+1;
if(p<0)
p=p+2*dy;
else
{
y=y+1;
p=p+2*(dy-dx);
}
putpixel(x,y,14);
}
}

PRACTICAL No : 8:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdlib.h>
void bcircle(int xc,int yc,int r);
void main()
{
int gd=DETECT, gm, c,xc, yc;
float tx,ty,r;
printf("Enter the co ordinate & radius");
scanf("%d %d %d ",&xc,&yc,&r);
printf("Enter the number of pixel to be translated :\n\n");
scanf("%f %f",&tx,&ty);
initgraph(&gd, &gm ,"c:\\tc\\bgi");
bcircle(xc,yc,r);
putpixel(xc,yc,4);
getch();
closegraph();
}
void bcircle(int xc,int yc,int r)
{

int x,y=r,p=1-r;
for(x=0;x<y;x++)
{
y=(p<=0)?y:y-1;
p=(p<0)?p+2*(x+1 ):p+2*(x+1 )+1-2*(y-1);
plot(xc,yc,x,y);
}
}
plot(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y, 30);
putpixel(xc-x,yc-y, 30);
putpixel(xc+x,yc-y, 30);
putpixel(xc-x, yc+y, 30);
putpixel(xc+x,yc+x, 30);
putpixel(xc-y, yc+x, 30);
putpixel(xc+y,yc-x, 30);
putpixel(xc-y, yc-x, 30);
return 0;
}

Você também pode gostar