C program for scaling of 2D object.

Posted by Mangesh on May 03, 2018

/* program for scaling 2D object. */

Description :

When we say we want to scale some 2D object, it means we want to increase the size of every object on screen.

Program :

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main() {
   int gdriver = DETECT, gmode;
   int point[] = {70,70,70,80,100,80,70,70};
   int i,sx,sy;
   initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
   drawpoly(4,point);
   printf("\n\nEnter the scaling factor of X - axis : ");
   scanf("%d",&sx);
   printf("Enter the scaling factor of Y - axis : ");
   scanf("%d",&sy);
   for(i=0;i<8;i++)
   {
     if(i%2==0)
       point[i] = point[i] * sx;
     else
       point[i] = point[i] * sy;
   }
   drawpoly(4,point);
   getch();
   closegraph();
}

Output :

 c program for transform 2d object output Executed and tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program for scaling of 2D object.
2 C program to tramsform 2D objects.
3 C program to draw a line.
4 C program to draw a circle.
5 C program to draw a rectangle.
6 C program for DDA algorithm to generate line.
7 C program for midpoint circle algorithm.
Latest Post
1 C program to implement Queue using linked list.
2 C program for binary search tree (BST).
3 C program to search an element in linked list.
4 C program for postorder traversal in binary tree.
5 C program for preorder traversal in binary tree.