0% found this document useful (0 votes)
40 views

Graphics Ass Docs

1. The document contains code for implementing Bresenham's and DDA line drawing algorithms in C++. It takes input coordinates from the user and draws a line between those points. 2. It also contains code for animating 3D shapes like a box using OpenGL. It allows transformations like translation, rotation and scaling of the box based on user key presses. 3. Additional code draws various 2D shapes like lines, circles, arcs, triangles, rectangles, polygons using C++ graphics functions. It supports transformations like translation, rotation and scaling of these shapes.

Uploaded by

Sufiyan Mohammed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Graphics Ass Docs

1. The document contains code for implementing Bresenham's and DDA line drawing algorithms in C++. It takes input coordinates from the user and draws a line between those points. 2. It also contains code for animating 3D shapes like a box using OpenGL. It allows transformations like translation, rotation and scaling of the box based on user key presses. 3. Additional code draws various 2D shapes like lines, circles, arcs, triangles, rectangles, polygons using C++ graphics functions. It supports transformations like translation, rotation and scaling of these shapes.

Uploaded by

Sufiyan Mohammed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

COLLEGE OF ENGINERING AND TECHNOLOGY

DEPARTEMENT OF COMPUTER SCIENCE

INDIVIDUAL ASSIGNMET OF COMPUTER GRAPHICS

NAME IDNO

SUFIYAN MOHAMMED RU/4770/12

Submitted to: DEJENE.B


1, Implement Brenham’s and DDA line drawing algorithm using c++ code that take the
coordinate from the user

#include <graphics.h>

#include <iostream>

#include <conio.h>

#include <math.h>

using namespace std;

void bresenham(int x0, int y0, int xEnd, int yEnd)

int dx = fabs(xEnd - x0), dy = fabs(yEnd - y0);

int p = 2 * dy - dx;

int twoDy = 2 * dy, twoDyMinusDx = 2 * (dy - dx);

int x, y; /* Determine which endpoint to use as start position. */

if (x0 > xEnd)

x = xEnd;

y = yEnd;

xEnd = x0;
}

else

x = x0;

y = y0;

putpixel(x, y, WHITE);

// cout <<"k pk x y \n";

// cout << -1 << " " << p << " " << x << " " << y << "\n";

int cnt = 0;

while (x < xEnd)

x++;

if (p < 0)

p += twoDy;

else

y++;

p += twoDyMinusDxh;

putpixel(x, y, WHITE);

// cout <<cnt++ <<" " <<p<<" " << x << " " << y << "\n";

int main()
{

int gd = DETECT, gm;

initgraph(&gd, &gm, "");

int x0, y0, xend, yend;

cout << "Enter x0, y0 :";

cin >> x0 >> y0;

cout << "Enter xend, yend :";

cin >> xend >> yend;

bresenham(x0, y0, xend, yend);

getch();

closegraph();

return 0;

For DDA:
#include<graphics.h>

#include<iostream>

#include<conio.h>

#include<math.h>

using namespace std;

void dda(int x0, int y0, int xend, int yend){

int dx = xend - x0;

int dy = yend - y0;


float xinc, yinc, x = x0, y = y0;

int steps = (fabs(dx) > fabs(dy))? fabs(dx): fabs(dy);

xinc = (float) dx / (float) steps;

yinc = (float) dy / (float) steps;

putpixel(round(x), round(y), WHITE);

for(int i=0;i<steps;i++){

x += xinc;

y += yinc;

// cout << round (x) <<" " << round(y) << "\n";

putpixel(round(x), round(y), WHITE);

int main(){

int gd = DETECT, gm;

initgraph(&gd, &gm, "");

int x0, y0, xend, yend;

cout << "Enter x0, y0 :";


cin >> x0 >> y0 ;

cout << "Enter xend, yend :";

cin >> xend >> yend;

dda(x0, y0, xend, yend);

getch();

closegraph();

return 0;

2, Implement the animation of any primitives using OpenGL library by taking input from console
line (from user)

#include<stdio.h>

#include <gl/glut.h>

#define KEY_ESC 27 /* GLUT doesn't supply this */

int fullscreen = 0;

int mouseDown = 0;

float xrot = 100.0f;

float yrot = -100.0f;

float xdiff = 100.0f;

float ydiff = 100.0f;

float tra_x = 0.0f;

float tra_y = 0.0f;


float tra_z = 0.0f;

float grow_shrink = 70.0f;

float resize_f = 1.0f;

void drawBox()

glTranslatef(tra_x, tra_y, tra_z);

glBegin(GL_QUADS);

glColor3f(1.0f, 0.0f, 0.0f);

// FRONT

glVertex3f(-0.5f, -0.5f, 0.5f);

glColor3f(0.0f, 1.0f, 0.0f);

glVertex3f( 0.5f, -0.5f, 0.5f);

glVertex3f( 0.5f, 0.5f, 0.5f);

glColor3f(1.0f, 0.0f, 0.0f);

glVertex3f(-0.5f, 0.5f, 0.5f);

// BACK
glVertex3f(-0.5f, -0.5f, -0.5f);

glVertex3f(-0.5f, 0.5f, -0.5f);

glColor3f(0.0f, 1.0f, 0.0f);

glVertex3f( 0.5f, 0.5f, -0.5f);

glVertex3f( 0.5f, -0.5f, -0.5f);

glColor3f(0.0f, 1.0f, 0.0f);

// LEFT

glVertex3f(-0.5f, -0.5f, 0.5f);

glVertex3f(-0.5f, 0.5f, 0.5f);

glColor3f(0.0f, 0.0f, 1.0f);

glVertex3f(-0.5f, 0.5f, -0.5f);

glColor3f(1.0f, 0.0f, 0.0f);

glVertex3f(-0.5f, -0.5f, -0.5f);

// RIGHT

glVertex3f( 0.5f, -0.5f, -0.5f);

glVertex3f( 0.5f, 0.5f, -0.5f);

glColor3f(0.0f, 1.0f, 0.0f);

glVertex3f( 0.5f, 0.5f, 0.5f);

glColor3f(0.0f, 0.0f, 1.0f);

glVertex3f( 0.5f, -0.5f, 0.5f);

glColor3f(0.0f, 0.0f, 1.0f);

// TOP

glVertex3f(-0.5f, 0.5f, 0.5f);


glVertex3f( 0.5f, 0.5f, 0.5f);

glColor3f(0.0f, 1.0f, 0.0f);

glVertex3f( 0.5f, 0.5f, -0.5f);

glVertex3f(-0.5f, 0.5f, -0.5f);

glColor3f(1.0f, 0.0f, 0.0f);

// BOTTOM

glVertex3f(-0.5f, -0.5f, 0.5f);

glColor3f(0.0f, 0.0f, 1.0f);

glVertex3f(-0.5f, -0.5f, -0.5f);

glVertex3f( 0.5f, -0.5f, -0.5f);

glVertex3f( 0.5f, -0.5f, 0.5f);

glEnd();

int init(void)

glClearColor(0.93f, 0.93f, 0.93f, 0.0f);

glEnable(GL_DEPTH_TEST);

glDepthFunc(GL_LEQUAL);

glClearDepth(1.0f);

return 1;

}
void display(void)

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

gluLookAt(

0.0f, 0.0f, 3.0f,

0.0f, 0.0f, 0.0f,

0.0f, 1.0f, 0.0f);

glRotatef(xrot, 1.0f, 0.0f, 0.0f);

glRotatef(yrot, 0.0f, 1.0f, 0.0f);

drawBox();

glFlush();

glutSwapBuffers();

void resize(int w, int h)

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glViewport(0, 0, w, h);
gluPerspective(grow_shrink, resize_f * w / h, resize_f, 100 * resize_f);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

void idle(void)

if (!mouseDown)

xrot += 0.3f;

yrot += 0.4f;

glutPostRedisplay();

void mySpecialFunction(int key, int x, int y)

//if (key == GLUT_KEY_F1)

//{

printf("U -----------> rotate clockwise\n");

printf("Y -----------> rotate counter clockwise\n");


printf("W or w ------> Up\n");

printf("S or s -----> Down\n");

printf("D or d ------> Right\n");

printf("A or a ------> Left\n");

printf("Z or z ------> Shrink\n");

printf("X or x ------> Grow\n");

printf("Escape Key ---> exit the program\n\n");

//}

void keyboard(unsigned char key, int x, int y)

switch(key)

case 27 :

exit(1);

break;

case 'w':

case 'W':

tra_x += 0.1f;

break;

case 's':
case 'S':

tra_x -= 0.1f;

break;

case 'a':

case 'A':

tra_z -= 0.1f;

break;

case 'd':

case 'D':

tra_z += 0.1f;

break;

case 'u':

case 'U':

xrot += 1.0f;

yrot += 1.0f;

xdiff += 1.0f;

ydiff += 1.0f;

break;

case 'y':

case 'Y':

xrot -= 1.0f;

yrot -= 1.0f;

xdiff += 1.0f;

ydiff += 1.0f;
break;

case 'h':

case 'H':

mySpecialFunction(key, x, y);

break;

case 'Z':

case 'z':

grow_shrink--;

resize(500, 500);

break;

case 'X':

case 'x':

grow_shrink++;

resize(500, 500);

break;

glutPostRedisplay();

}
void specialKeyboard(int key, int x, int y)

if (key == GLUT_KEY_F1)

fullscreen = !fullscreen;

if (fullscreen)

glutFullScreen();

else

glutReshapeWindow(500, 500);

glutPositionWindow(50, 50);

void mouse(int button, int state, int x, int y)

if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)

mouseDown = 1;

xdiff = x - yrot;

ydiff = -y + xrot;

}
else

mouseDown = 0;

void mouseMotion(int x, int y)

if (mouseDown)

yrot = x - xdiff;

xrot = y + ydiff;

glutPostRedisplay();

int main(int argc, char *argv[])

glutInit(&argc, argv);

glutInitWindowPosition(50, 50);

glutInitWindowSize(500, 500);

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

glutCreateWindow("13 - Solid Shapes");


glutDisplayFunc(display);

glutKeyboardFunc(keyboard);

glutSpecialFunc(specialKeyboard);

glutMouseFunc(mouse);

glutMotionFunc(mouseMotion);

glutReshapeFunc(resize);

//glutIdleFunc(idle);

if (!init())

return 1;

glutMainLoop();

return 0;

3, Draw line, circle, arc, triangle, rectangle, polygon, sphere and do all the transformation of it
(translate, rotate, scale) using c++ graphics code.

For line:
#include<iostream>

#include<graphics.h>

#include<math.h>

using namespace std;

class transform

{
public:

int m,a[20][20],c[20][20];

int i,j,k;

public:

void object();

void accept();

void operator *(float b[20][20])

for(int i=0;i<m;i++)

for(int j=0;j<m;j++)

c[i][j]=0;

for(int k=0;k<m;k++)

c[i][j]=c[i][j]+(a[i][k]*b[k][j]);

};

void transform::object()

int gd,gm;
gd=DETECT;

initgraph(&gd,&gm,NULL);

line(300,0,300,600);

line(0,300,600,300);

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

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

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

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

line(300+c[i][0],300-c[i][1],300+c[i+1][0],300-c[i+1][1]);

line(300+c[0][0],300-c[0][1],300+c[i][0],300-c[i][1]);

int temp;

cout << "Press 1 to continue";

cin >> temp;

closegraph();

void transform::accept()

cout<<"\n";

cout<<"Enter the Number Of Edges:";

cin>>m;
cout<<"\nEnter The Coordinates :";

for(int i=0;i<m;i++)

for(int j=0;j<3;j++)

if(j>=2)

a[i][j]=1;

else

cin>>a[i][j];

int main()

int ch,tx,ty,sx,sy;

float deg,theta,b[20][20];

transform t;

t.accept();

cout<<"\nEnter your choice";

cout<<"\n1.Translation"

"\n2.Scaling"

"\n3.Rotation";

cin>>ch;

switch(ch)
{

case 1: cout<<"\nTRANSLATION OPERATION\n";

cout<<"Enter value for tx and ty:";

cin>>tx>>ty;

b[0][0]=b[2][2]=b[1][1]=1;

b[0][1]=b[0][2]=b[1][0]=b[1][2]=0;

b[2][0]=tx;

b[2][1]=ty;

t * b;

t.object();

break;

case 2: cout<<"\nSCALING OPERATION\n";

cout<<"Enter value for sx,sy:";

cin>>sx>>sy;

b[0][0]=sx;

b[1][1]=sy;

b[0][1]=b[0][2]=b[1][0]=b[1][2]=0;

b[2][0]=b[2][1]=0;

b[2][2] = 1;

t * b;

t.object();

break;

case 3: cout<<"\nROTATION OPERATION\n";


cout<<"Enter value for angle:";

cin>>deg;

theta=deg*(3.14/100);

b[0][0]=b[1][1]=cos(theta);

b[0][1]=sin(theta);

b[1][0]=sin(-theta);

b[0][2]=b[1][2]=b[2][0]=b[2][1]=0;

b[2][2]=1;

t * b;

t.object();

break;

default:

cout<<"\nInvalid choice";

getch();

return 0;

B,for rectangle:
#include<iostream>

#include<graphics.h>

#include<math.h>

using namespace std;


int main()

int gd=DETECT,gm,s;

initgraph(&gd,&gm,(char*)"");

cout<<"1.Translation\n2.Rotation\n3.Scaling\n4.Reflection\n5.Shearing "<<endl;

cout<<"Selection:";

cin>>s;

switch(s)

case 1:

{ int x1=200,y1=150,x2=300,y2=250;

int tx=50,ty=50;

cout<<"Rectangle before translation"<<endl;

setcolor(3);

rectangle(x1,y1,x2,y2);

setcolor(4);

cout<<"Rectangle after translation"<<endl;

rectangle(x1+tx,y1+ty,x2+tx,y2+ty);

getch();

break;

case 2:

{ long x1=200,y1=200,x2=300,y2=300;

double a;

cout<<"Rectangle with rotation"<<endl;


setcolor(3);

rectangle(x1,y1,x2,y2);

cout<<"Angle of rotation:";

cin>>a;

a=(a*3.14)/180;

long xr=x1+((x2-x1)*cos(a)-(y2-y1)*sin(a));

long yr=y1+((x2-x1)*sin(a)+(y2-y1)*cos(a));

setcolor(2);

rectangle(x1,y1,xr,yr);

getch();

break;

case 3:

int x1=30,y1=30,x2=70,y2=70,y=2,x=2;

cout<<"Before scaling"<<endl;

setcolor(3);

rectangle(x1,y1,x2,y2);

cout<<"After scaling"<<endl;

setcolor(10);

rectangle(x1*x,y1*y,x2*x,y2*y);

getch();

break;

case 4:
{

int x1=200,y1=300,x2=500,y2=300,x3=350,y3=400;

cout<<"triangle before reflection"<<endl;

setcolor(3);

line(x1,y1,x2,y2);

line(x1,y1,x3,y3);

line(x2,y2,x3,y3);

cout<<"triangle after reflection"<<endl;

setcolor(5);

line(x1,-y1+500,x2,-y2+500);

line(x1,-y1+500,x3,-y3+500);

line(x2,-y2+500,x3,-y3+500);

getch();

break;

case 5:

int x1=400,y1=100,x2=600,y2=100,x3=400,y3=200,x4=600,y4=200,shx=2;

cout<<"Before shearing of rectangle"<<endl;

setcolor(3);

line(x1,y1,x2,y2);

line(x1,y1,x3,y3);

line(x3,y3,x4,y4);

line(x2,y2,x4,y4);

cout<<"After shearing of rectangle"<<endl;


x1=x1+shx*y1;

x2=x2+shx*y2;

x3=x3+shx*y3;

x4=x4+shx*y4;

setcolor(13);

line(x1,y1,x2,y2);

line(x1,y1,x3,y3);

line(x3,y3,x4,y4);

line(x2,y2,x4,y4);

getch();

default:

cout<<"Invalid Selection"<<endl;

break;

closegraph();

return 0;

A,rectangle:

#include<stdio.h>

#include<math.h>

#include<graphics.h>
char s[100];

void translation(int x1, int y1, int x2, int y2)

int x,y;

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

setcolor(GREEN);

sprintf(s,"Translated Rectangle");

outtextxy(80,100,s);

sprintf(s,"At X: %d, Y: %d",x,y);

outtextxy(80,110,s);

rectangle(x1+x,y1+y,x2+x,y2+y);

return;

void rotation(int x1, int y1, int x2, int y2)

int t,mx,my,rx1,ry1,rx2,ry2,rx3,ry3,rx4,ry4;

float a;

scanf("%d",&t);

setcolor(YELLOW);

sprintf(s,"Rotated Rectangle");

outtextxy(80,390,s);

sprintf(s,"At %d Degree",t);

outtextxy(90,400,s);
while(t>90)

t = t - 90;

a = (float)t*3.14/180;

mx = (x1+x2)/2;

my = (y1+y2)/2;

circle(mx,my,2);

rx1 = (x1 - mx)*cos(a) - (y1 - my)*sin(a);

ry1 = (x1 - mx)*sin(a) + (y1 - my)*cos(a);

rx2 = (x2 - mx)*cos(a) - (y2 - my)*sin(a);

ry2 = (x2 - mx)*sin(a) + (y2 - my)*cos(a);

rx3 = (x2 - mx)*cos(a) - (y1 - my)*sin(a);

ry3 = (x2 - mx)*sin(a) + (y1 - my)*cos(a);

rx4 = (x1 - mx)*cos(a) - (y2 - my)*sin(a);

ry4 = (x1 - mx)*sin(a) + (y2 - my)*cos(a);

rx1 = rx1 + mx;

rx2 = rx2 + mx;

rx3 = rx3 + mx;

rx4 = rx4 + mx;

ry1 = ry1 + my;

ry2 = ry2 + my;

ry3 = ry3 + my;

ry4 = ry4 + my;


line(rx1,ry1,rx3,ry3);

line(rx2,ry2,rx4,ry4);

line(rx3,ry3,rx2,ry2);

line(rx4,ry4,rx1,ry1);

return;

void scaling(int x1, int y1, int x2, int y2)

int mx,my,sx,sy;

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

setcolor(GREEN);

sprintf(s,"Scaled Rectangle");

outtextxy(300,400,s);

sprintf(s,"At X: %d, Y: %d",sx,sy);

outtextxy(300,410,s);

mx = abs(x2 - x1)*sx/4;

my = abs(y2 - y1)*sy/4;

rectangle(x1-mx,y1-my,x2+mx,y2+my);

return;

int main()

{
int x1,x2,y1,y2,gd=DETECT,gm;

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

sprintf(s,"Orignal Rectangle");

outtextxy(300,100,s);

line(0,250,500,250);

line(250,0,250,500);

setcolor(RED);

x1 = 300;

y1 = 150;

x2 = 400;

y2 = 200;

rectangle(x1,y1,x2,y2);

x1 = 100;

y1 = 150;

x2 = 200;

y2 = 200;

rectangle(x1,y1,x2,y2);

translation(x1,y1,x2,y2);

x1 = 100;

y1 = 350;

x2 = 200;

y2 = 300;

setcolor(RED);
rectangle(x1,y1,x2,y2);

circle((x1+x2)/2,(y1+y2)/2,2);

rotation(x1,y1,x2,y2);

x1 = 300;

y1 = 300;

x2 = 400;

y2 = 350;

setcolor(RED);

rectangle(x1,y1,x2,y2);

scaling(x1,y1,x2,y2);

getch();

return 0;

C,For triangle:
#include<iostream>

#include<graphics.h>

#include<math.h>

using namespace std;

class transform

public:

int m,a[20][20],c[20][20];

int i,j,k;

public:
void object();

void accept();

void operator *(float b[20][20])

for(int i=0;i<m;i++)

for(int j=0;j<m;j++)

c[i][j]=0;

for(int k=0;k<m;k++)

c[i][j]=c[i][j]+(a[i][k]*b[k][j]);

};

void transform::object()

int gd,gm;

gd=DETECT;

initgraph(&gd,&gm,NULL);

line(300,0,300,600);
line(0,300,600,300);

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

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

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

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

line(300+c[i][0],300-c[i][1],300+c[i+1][0],300-c[i+1][1]);

line(300+c[0][0],300-c[0][1],300+c[i][0],300-c[i][1]);

int temp;

cout << "Press 1 to continue";

cin >> temp;

closegraph();

void transform::accept()

cout<<"\n";

cout<<"Enter the Number Of Edges:";

cin>>m;

cout<<"\nEnter The Coordinates :";

for(int i=0;i<m;i++)
{

for(int j=0;j<3;j++)

if(j>=2)

a[i][j]=1;

else

cin>>a[i][j];

int main()

int ch,tx,ty,sx,sy;

float deg,theta,b[20][20];

transform t;

t.accept();

cout<<"\nEnter your choice";

cout<<"\n1.Translation"

"\n2.Scaling"

"\n3.Rotation";

cin>>ch;

switch(ch)

{
case 1: cout<<"\nTRANSLATION OPERATION\n";

cout<<"Enter value for tx and ty:";

cin>>tx>>ty;

b[0][0]=b[2][2]=b[1][1]=1;

b[0][1]=b[0][2]=b[1][0]=b[1][2]=0;

b[2][0]=tx;

b[2][1]=ty;

t * b;

t.object();

break;

case 2: cout<<"\nSCALING OPERATION\n";

cout<<"Enter value for sx,sy:";

cin>>sx>>sy;

b[0][0]=sx;

b[1][1]=sy;

b[0][1]=b[0][2]=b[1][0]=b[1][2]=0;

b[2][0]=b[2][1]=0;

b[2][2] = 1;

t * b;

t.object();

break;

case 3: cout<<"\nROTATION OPERATION\n";


cout<<"Enter value for angle:";

cin>>deg;

theta=deg*(3.14/100);

b[0][0]=b[1][1]=cos(theta);

b[0][1]=sin(theta);

b[1][0]=sin(-theta);

b[0][2]=b[1][2]=b[2][0]=b[2][1]=0;

b[2][2]=1;

t * b;

t.object();

break;

default:

cout<<"\nInvalid choice";

getch();

return 0;

CIRCLE:

#include<iostream>

#include<graphics.h>

#include<math.h>
using namespace std;

int main()

int gd=DETECT,gm,s;

initgraph(&gd,&gm,(char*)"");

cout<<"1.Translation\n2.Rotation\n3.Scaling "<<endl;

cout<<"Selection:";

cin>>s;

switch(s)

case 1:

{ int x1=200,y1=150,r=50;

int tx=50,ty=50;

cout<<"circle before translation"<<endl;

setcolor(3);

circle(x1,y1,r);

setcolor(4);

cout<<"circle after translation"<<endl;

circle(x1+tx,y1+ty,r);

getch();

break;

case 2:

{ long x1=200,y1=200,r=50;
double a;

cout<<"circle with rotation"<<endl;

setcolor(3);

circle(x1,y1,r);

cout<<"Angle of rotation:";

cin>>a;

a=(a*3.14)/180;

long xr=x1+((x1)*cos(a)-(y1)*sin(a));

long yr=y1+((x1)*sin(a)+(y1)*cos(a));

setcolor(2);

circle(x1+xr,y1+yr,r);

getch();

break;

case 3:

int x1=30,y1=30,r=20,x=2,y=2;

cout<<"Before scaling"<<endl;

setcolor(3);

circle(x1,y1,r);

cout<<"After scaling"<<endl;

setcolor(10);

circle(x1,y1,r);
getch();

default:

cout<<"Invalid Selection"<<endl;

break;

closegraph();

return 0;

For arc:

#include<iostream>

#include<graphics.h>

#include<math.h>

using namespace std;

int main()

int gd=DETECT,gm,s;

int x1,y1,tx,ty,r,x,y,a1,a2;

long xr,yr;

initgraph(&gd,&gm,(char*)"");

cout<<"enter the x axis and y axis "<<endl;

cin>>x1>>y1;
cout<<"enter the angle one and two"<<endl;

cin>>a1>>a2;

cout<<"enter the radius"<<endl;

cin>>r;

cout<<"1.Translation\n2.Rotation\n3.Scaling "<<endl;

cout<<"Selection:";

cin>>s;

switch(s)

case 1:

{ cout<<"enter the translation x axis and y axis"<<endl;

cin>>tx>>ty;

cout<<"arc before translation"<<endl;

setcolor(3);

arc(x1,y1,a1,a2,r);

setcolor(4);

cout<<"arc after translation"<<endl;

arc(x1+tx,y1+ty,a1,a2,r);

getch();

break;

case 2:

double a;
cout<<"arc before rotation"<<endl;

setcolor(3);

arc(x1,y1,a1,a2,r);

cout<<"Angle of rotation:";

cin>>a;

a=(a*3.14)/180;

xr=x1+((x1)*cos(a)-(y1)*sin(a));

yr=y1+((x1)*sin(a)+(y1)*cos(a));

cout<<"arc after rotation"<<endl;

setcolor(2);

arc(x1+xr,y1+yr,a1,a2,r);

getch();

break;

case 3:

cout<<"enter the scalling number"<<endl;

cin>>x>>y;

cout<<"arc Before scaling"<<endl;

setcolor(3);

arc(x1,y1,a1,a2,r);

cout<<"arc After scaling"<<endl;

setcolor(10);

arc(x1*x,y1*y,a1,a2,r*2);
getch();

default:

cout<<"Invalid Selection"<<endl;

break;

closegraph();

return 0;

You might also like