Tuesday, November 6, 2007

Scaling and Rotation

Program : Rotation



#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h> //header file inclusion

#include<dos.h>

#include<math.h>

int x1,x2,x3,y1,y2,y3;

int xs,ys; //variable initializations


void input() //function for input

{

printf("Enter the coordinates of the triangle:");

scanf("%d%d",&x1,&y1);

scanf("%d%d",&x2,&y2); //Inputting triangle coordinates

scanf("%d%d",&x3,&y3);

printf("Enter the scaling factor:");

scanf("%d%d",&xs,&ys); //Inputting scaling factor

}



void scale() //function to scale

{

input(); //calling input()

setcolor(RED);

line(x1,y1,x2,y2);

line(x2,y2,x3,y3); //drawing triangle

line(x3,y3,x1,y1);

x1*=xs; x2*=xs; x3*=xs; //scaling x values

y1*=ys; y2*=ys; y3*=ys; //scaling y values

setcolor(GREEN);

line(x1,y1,x2,y2);

line(x2,y2,x3,y3); //drawing scaled triangle

line(x3,y3,x1,y1);

getch();

}


void main(void) //main function

{

int gdriver = DETECT, gmode, errorcode;

initgraph(&gdriver, &gmode, "D:\\TC\\BGI"); //initializing graphics window

scale(); //calling scale() function

getch();

}

0 comments: