AIM:
To write a "C++" program for the implementation of 2D Transformation for circle in CS1255 - Graphics and Multimedia Lab.
SOURCE CODE:
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
int x,y,r,midx,midy;
void axis();
void translation()
{
int tx,ty,xn1,yn1,xn2,yn2;
printf("\n Enter the translation:");
scanf("%d%d",&tx,&ty);
cleardevice();
outtextxy(400,100,"TRANSLATION");
axis();
xn1=x+tx;
yn1=y+ty;
circle(xn1,yn1,r);
getch();
}
void scaling()
{
float sc,r1;
printf("Enter the scaling factor");
scanf("%f",&sc);
cleardevice();
outtextxy(300,200,"SCALING");
r1=r*sc;
axis();
circle(midx,midy,r1);
getch();
}
void rotation()
{
int ang;
float rx,xn1,yn1;
printf("\n enter the angle for rotation");
scanf("%d",&ang);
cleardevice();
outtextxy(500,200,"ROTATION");
rx=(ang*3.14)/180;
axis();
xn1=x*cos(rx)-y*sin(rx);
yn1=y*cos(rx)+x*sin(rx);
circle(xn1,yn1,r);
getch();
}
void shearing()
{
float sh,r1;
float xn1,yn1;
printf("\n Enter the value for shearing");
scanf("%f",&sh);
cleardevice();
outtextxy(500,100,"SHEARING");
axis();
xn1=x+sh*y;
yn1=y;
r1=r+sh*x;
ellipse(xn1,yn1,0,360,r,r1);
getch();
}
void reflection()
{
int xn1,yn1;
cleardevice();
outtextxy(300,100,"REFLECTION");
axis();
if((x<y)^(x<y))
{
xn1=x+150;
yn1=y;
}
else
{
xn1=x;
yn1=y+150;
}
circle(xn1,yn1,r);
getch();
}
void get()
{
printf("\n Enter the Raidus(r): ");
scanf("%d",&r);
outtextxy(200,100,"ORIGINAL OBJECT");
axis();
getch();
}
void axis()
{
midx=x= getmaxx() / 2;
midy=y= getmaxy() / 2;
line(0,midy,midx*2,midy);
line(midx,0,midx,midy*2);
circle(midx,midy,r);
}
void main()
{
int ch,gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
get();
do
{
cleardevice();
outtextxy(10,10,"1)TRANSLATION");
outtextxy(10,20,"2)SCALING");
outtextxy(10,30,"3)ROTATION");
outtextxy(10,40,"4)SHEARING");
outtextxy(10,50,"5)REFLECTION");
outtextxy(10,60,"6)EXIT");
outtextxy(10,70,"ENTER UR CHOICE:");
scanf("%d",&ch);
switch(ch)
{
case 1:
translation();
break;
case 2:
scaling();
break;
case 3:
rotation();
break;
case 4:
shearing();
break;
case 5:
reflection();
break;
case 6:
exit(0);
}
}while(ch<6);
}
OUTPUT:
To write a "C++" program for the implementation of 2D Transformation for circle in CS1255 - Graphics and Multimedia Lab.
SOURCE CODE:
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
int x,y,r,midx,midy;
void axis();
void translation()
{
int tx,ty,xn1,yn1,xn2,yn2;
printf("\n Enter the translation:");
scanf("%d%d",&tx,&ty);
cleardevice();
outtextxy(400,100,"TRANSLATION");
axis();
xn1=x+tx;
yn1=y+ty;
circle(xn1,yn1,r);
getch();
}
void scaling()
{
float sc,r1;
printf("Enter the scaling factor");
scanf("%f",&sc);
cleardevice();
outtextxy(300,200,"SCALING");
r1=r*sc;
axis();
circle(midx,midy,r1);
getch();
}
void rotation()
{
int ang;
float rx,xn1,yn1;
printf("\n enter the angle for rotation");
scanf("%d",&ang);
cleardevice();
outtextxy(500,200,"ROTATION");
rx=(ang*3.14)/180;
axis();
xn1=x*cos(rx)-y*sin(rx);
yn1=y*cos(rx)+x*sin(rx);
circle(xn1,yn1,r);
getch();
}
void shearing()
{
float sh,r1;
float xn1,yn1;
printf("\n Enter the value for shearing");
scanf("%f",&sh);
cleardevice();
outtextxy(500,100,"SHEARING");
axis();
xn1=x+sh*y;
yn1=y;
r1=r+sh*x;
ellipse(xn1,yn1,0,360,r,r1);
getch();
}
void reflection()
{
int xn1,yn1;
cleardevice();
outtextxy(300,100,"REFLECTION");
axis();
if((x<y)^(x<y))
{
xn1=x+150;
yn1=y;
}
else
{
xn1=x;
yn1=y+150;
}
circle(xn1,yn1,r);
getch();
}
void get()
{
printf("\n Enter the Raidus(r): ");
scanf("%d",&r);
outtextxy(200,100,"ORIGINAL OBJECT");
axis();
getch();
}
void axis()
{
midx=x= getmaxx() / 2;
midy=y= getmaxy() / 2;
line(0,midy,midx*2,midy);
line(midx,0,midx,midy*2);
circle(midx,midy,r);
}
void main()
{
int ch,gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
get();
do
{
cleardevice();
outtextxy(10,10,"1)TRANSLATION");
outtextxy(10,20,"2)SCALING");
outtextxy(10,30,"3)ROTATION");
outtextxy(10,40,"4)SHEARING");
outtextxy(10,50,"5)REFLECTION");
outtextxy(10,60,"6)EXIT");
outtextxy(10,70,"ENTER UR CHOICE:");
scanf("%d",&ch);
switch(ch)
{
case 1:
translation();
break;
case 2:
scaling();
break;
case 3:
rotation();
break;
case 4:
shearing();
break;
case 5:
reflection();
break;
case 6:
exit(0);
}
}while(ch<6);
}
OUTPUT:
1 comments:
Write commentsShearing() part is not working.... help wit it..
ReplyEmoticonEmoticon