You are on page 1of 14

/*PROGRAM TO PERFORM SCALING TRANSFORMATION ON A

OBJECT*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
main()
{
float x1,x2,y1,y2;
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
printf("enter the positions \n");
scanf("%f%f%f%f",&x1,&y1,&x2,&y2);
rectangle(x1,y1,x2,y2);
x1=x1*0.5;
y1=y1*0.5;
x2=x2*1.2;
y2=y2*1.2;
rectangle(x1,y1,x2,y2);
getch();
closegraph();
}
   Output:-

Enter the positions


100 100 250 250
/*PRORGAM TO GET REFLECT AN OBJECT PERPENDICULAR TO X-Y
PLANE */

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
int gd=0,gm,x1,y1,x2,y2,x3,y3;
initgraph(&gd,&gm," ");
moveto(320,0);
lineto(320,480);
moveto(0,240);
lineto(640,240);
printf("enter the three line coodinates");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
outtextxy(470,170,"original");
outtextxy(100,330,"reflected");
x1=-x1;
x2=-x2;
x3=-x3;
y1=-y1;
y2=-y2;
y3=-y3;
settextstyle(2,1,1);
line(x1+650,y1+480,x2+650,y2+480);
line(x2+650,y2+480,x3+650,y3+480);
line(x3+650,y3+480,x1+650,y1+480);
getch();
}
OUTPUT:-

Enter the Three line coordinates:230 130 280 200 180 200

Original

Reflected
/*PROGRAM TO DRAW THE BASIC SHAPES*/

#include<graphics.h>
#include<conio.h>

void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430,
350,450 };
initgraph(&gd, &gm, "");
circle(100,100,50);
outtextxy(75,170, "Circle");
rectangle(200,50,350,150);
outtextxy(240, 170, "Rectangle");
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, "Ellipse");
line(100,250,540,250);
outtextxy(300,260,"Line");
sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, "Sector");
drawpoly(6, poly);
outtextxy(340, 460, "Polygon");
getch();
closegraph();
}
Output:-

                                             
/*PROGRAM TO DRAW LINE USING SIMPLE DDA ALGORITHM*/

#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
int gd=DETECT,gm;
int i,len,x,y,xinc,yinc,x1,x2,y1,y2;
initgraph(&gd,&gm,"");
printf("enter the points [x1,y1]\n");
scanf("%d%d",&x1,&y1);
printf("enter the points [x2,y2]\n");
scanf("%d%d",&x2,&y2);
x=x1;
y=y1;
len=abs(x2-x1);
if(abs(y2-y1)>len)
{
len=abs(y2-y1);
}
xinc=(x2-x1)/len;
yinc=(y2-y1)/len;
x=x1+0.5;
y=y1+0.5;
for(i=1;i<=len;i++)
{
putpixel(x,y,10);
x=x+xinc;
y=y+yinc;
}
getch();
closegraph();
}
OUTPUT:-

Enter the points [x1,y1]


100 100
Enter the points [x2.y2]
200 200
/*PROGRAM TO DRAW LINE USNG BRESENHAM’S LINE DRAWING
ALGORITHM*/

#include<stdio.h>
#include<math.h>
#include<graphics.h>
main()
{
int x,y,x1,y1,x2,y2,dx,dy,e;
int i,gd,gm;
clrscr();
printf("enter the values of x1,y1,x2,y2");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
dx=abs(x2-x1);
dy=abs(y2-y1);
x=x1;
y=y1;
e=2*dy-dx;
i=1;
do
{
putpixel(x,y,15);
while(e>=0)
{
y=y+1;
e=e-2*dx;
}
x=x+1;
e=e+2*dy;
i=i+1;
}
while(i<=dx);
getch();
closegraph();
}
Output:-

Enter the values of x1,y1,x2,y2

350 150 150 350


/*PROGRAM TO DRAW CIRCLE USING BRESENHAMS CIRCLE
DRAWING ALGORITHM*/

# include<stdio.h>
# include<conio.h>
# include<graphics.h>
# include<math.h>
void main()
{
int gd=DETECT,gm;
int r,x,y,p,xc=320,yc=240;
initgraph(&gd,&gm,"e:Turboc2\BGI");
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,15);
putpixel(xc-x,yc-y,15);
putpixel(xc+x,yc+y,15);
putpixel(xc-x,yc+y,15);
putpixel(xc+y,yc-x,15);
putpixel(xc-y,yc-x,15);
putpixel(xc+y,yc+x,15);
putpixel(xc-y,yc+x,15);
}
getch();
closegraph();
}
Output:-

Enter The radius

200
/*PROGRAM FOR WINDOW AND VIEW PORT*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
main()
{
float sx,sy;
int w1,w2,w3,w4,x1,x2,x3,x4,y1,y2,y3,y4,v1,v2,v3,v4;
int gd=DETECT,gm;
initgraph(&gd,&gm,"e:/turboc2/bgi");
printf("enter coodinates x1,y1,x2,y2,x3,y3\n");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
cleardevice();
w1=5;
w2=5;
w3=635;
w4=465;
rectangle(w1,w2,w3,w4);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
v1=425;v2=75;
v3=550;v4=250;
sx=(float)(v3-v1)/(w3-w1);
sy=(float)(v4-v2)/(w4-w2);
rectangle(v1,v2,v3,v4);
x1=v1+floor(((float)(x1-w1)*sx)+0.5);
x2=v1+floor(((float)(x2-w1)*sx)+0.5);
x3=v1+floor(((float)(x3-w1)*sx)+0.5);
y1=v2+floor(((float)(y1-w2)*sy)+0.5);
y2=v2+floor(((float)(y2-w2)*sy)+0.5);
y3=v2+floor(((float)(y3-w2)*sy)+0.5);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
closegraph();
return 0;
}
Output:-

Enter coodinates x1,y1,x2,y2,x3,y3


100 150 120 200 180 150

You might also like