CGR Microproject2
CGR Microproject2
ON
“2D SCALING”
SUBMITTED BY –
“2D SCALING”
Mr.Suraj
Jamadar. Mr. S. V. Chavan
Mr. V. V. Giri
Principal
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
Course Code -
313001
Project Title
“2D SCALING”
Micro
Sr. Roll Enrollment Exam
Name of Student Project Total
No. No. No. Seat No.
Marks
G I 6+4 = 10
PRO’s
COs UOs
Mapping
Sr.
From Date to Date Activity Performed
No.
10
11
INDEX
Sr.
CONTENT Page No.
No.
1 Abstract 1
2 Introduction 2
3 Algorithm 3
4 Program 4
5 Output 6
6 Conclusion 7
7 Reference 7
Abstract
The provided C code utilizes the Turbo C graphics library to create a project on 2d
scalling. 2D Scaling in Computer Graphics involves resizing objects or coordinate
systems in a 2D plane. It allows us to change the size of each point in the object or
coordinate system by applying scaling factors in the x and y directions.
To perform 2D scaling, we utilize scaling factors: sx for the x-axis and sy for the
y-axis. These factors determine how much each coordinate should be scaled along its
respective axis.
Introduction
This is a C program that creates a 2D scaling using the graphics.h header file. The program
initializes the graphics system by loading the passed graphics driver and changing the system
into graphics mode. it allows us to change the size of each point in the object or coordinate
system by applying scaling factors in the x and y directions. To perform 2D scaling, we utilize
scaling factors: sx for the x-axis and sy for the y-axis. I
nitial coordinates of the object O = (Xold, Yold)
Scaling factor for X-axis = Sx
Scaling factor for Y-axis = Sy
New coordinates of the object O after scaling = (Xnew, Ynew)
Step 1 : START.
Step 2 : Initialize graphics using `initgraph`.
Step 3 : set the initial values for graphics driver(‘gd’)and graphics mode(`gm`).
Step 4 : Declare integer type variable n, x[100] ,y[100] and int i. And also declare sfx and sfy
variable of float type.
Step 5 : Take two functions namely:1)Void draw()
2)Void scale()
Step 6:Take a main function and inside it take a number of sides for a rectangle from user,
and also take a co-ordinates of x and y for each point. Clear the screen using `cleardevice`.
Step 7: Taking a fro loop which will execute
until the condition appers to be false.Taking the
scaling factors from user.
Step 8 : Set color(CYAN) and calling the
function draw() and scale().Again setting a color
which will be the inside shape to (YELLOW).
And again calling the function draw().
Step 9 : Taking a function Void draw() inside it we will take a for loop for
drawing a object on output screen taking the coordinates which we have already
taken.
Step 10 : Taking a function namely void scale() inside it for loop to make the
coordinates properly aligned.closing the scale function.
Step 11 :Close the graphics using closegraph.
#include <graphics.h>
#include <math.h>
#include <conio.h>
Int gd=DETECT,gm;
Int n,x[100], y[100],i;
Float sfx,sfy;
Void draw();
Void scale();
Void main()
{
Clrscr();
Printf(“Enter a number of sides :”)
Scanf(“%d”,&n);
Printf(“Enter co-ordinates x,y for each point:”);
for ( i=0 ; i<n ; i++)
scanf(%d%d”, &x[i] ,&y[i]);
printf(“Entar scalling factors: (sfx,sfy)”);
Scanf(“%f%f ”,&sfx,&sfy);
Initgraph(&gd,&gm,”C:\\TC\\BGI”);
Cleardevice();
Setcolor(CYAN);
draw();
scale();
setcolor(YELLOW);
draw();
getch();
}
void draw(){
for(i=0; i<n; i++)
line(x[i], y[i], x[(i+1)%n], y[(i+1)%n]);
}
Void scale()
{
for (i=0; i<n; i++)
{
x[i]= x[0] + (int) ((float) (x[i] - x[0]) * sfx);
In conclusion, the provided C code employs Turbo C's graphics library to create a simple
shape or object using 2D SCALING. Through the utilization of graphics functions, the code
establishes a graphical environment, initializes key parameters, and enters a loop that
orchestrates the 2D SCALING. 2D graphics are widely used in animation and video
games, providing a realistic, but flat, view of movement on the screen. 3D graphics provide
realistic depth that allows the viewer to see into spaces, notice the movement of light and
shadows, and gain a fuller understanding of what's being shown. This code serves as an
illustrative example of basic graphical programming concepts, offering insights into the
practical application of graphics functions for output within the Turbo C environment.
Additionally, the reliance on keyboard input for program termination highlights a user-
interactive aspect in the control flow of the output.
REFERENCES
1.https://www.youtube.com/watch?v=jP19H02Z8oo
2.https://byjus.com/gate/transformation-in-computer-graphics/#:~:text=2D
%20Scaling%20in%20Computer%20Graphics%20involves%20resizing
%20objects%20or%20coordinate,the%20x%20and%20y%20directions.