Program : Translation
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h> //header file inclusion
#include<dos.h>
#include<math.h>
int x1,x2,y1,y2,midx,midy,r; //variable initializations
int i,xt,yt;
void input() //function for input
{
printf("Enter the coordinates of the line:");
scanf("%d%d",&x1,&y1);
scanf("%d%d",&x2,&y2); //Inputting line endpoints
printf("Enter the centre of circle:");
scanf("%d%d",&midx,&midy); //Inputting center coordinates
printf("Enter the radius:");
scanf("%d",&r); //Inputting circle radius
printf("Enter the translation coordinates:");
scanf("%d%d",&xt,&yt); //Inputting translation values
}
void trans() //function for translation
{
input(); //calling input() function
setcolor(RED);
line(x1,y1,x2,y2); //draw line
circle(midx,midy,r); //draw circle
setcolor(GREEN);
x1+=xt; x2+=xt; //translate x coordinate
y1+=yt; y2+=yt; //translate y coordinate
midx+=xt;
midy+=yt; //translating circle center
line(x1,y1,x2,y2);
circle(midx,midy,r); //draw line and circle
getch();
}
void main(void) //main function
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "E:\\TC\\BGI"); //initializing graphics window
trans(); //calling trans() function
getch();
}
0 comments:
Post a Comment