Q:

Write a C Program to perform 2D Transformations using Scaling

0

Write a C Program to perform 2D Transformations using Scaling. Here’s simple C Program to perform 2D Transformations using Scaling in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Below is the source code for C Program to perform 2D Transformations using Scaling which is successfully compiled and run on Windows System to produce desired output as shown below :

 
 


SOURCE CODE : :

/* C Program to perform 2D Transformations using Scaling  */

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void scale( int figure[], int edges, int dx, int dy, int cx, int cy ) {
        for (int i=0; i < edges; i++) {
                figure[2*i] = (figure[2*i] - cx) * dx + cx;
                figure[2*i+1] = (figure[2*i+1] - cy) * dy + cy;
        }
}
void main() {
        int figure[20], edges;
        // A Figure with Max 10 edges.
        int dx, dy, cx=0, cy=0;
        int gd = DETECT, gm;
        clrscr();
        printf( "Number of edges: " );
        scanf( "%d", &edges );
        for (int i=0; i < edges; i++) {
                printf( "Enter edge (x%d,y%d) : ", i , i );
                scanf( "%d %d", &figure[2*i], &figure[2*i+1] );
        }
        figure[2*i] = figure[0];
        figure[2*i+1] = figure[1];
        edges += 1;
        printf( "Enter dx: ");
        scanf( "%d", &dx);
        printf( "Enter dy: ");
        scanf( "%d", &dy);
        printf( "Enter the center of scaling: \n");
        printf( "cx: ");
        scanf( "%d", &cx);
        printf( "cy: ");
        scanf( "%d", &cy);
        initgraph( &gd, &gm, "" );
        cleardevice();
        setbkcolor(WHITE);
        setcolor(GREEN);
        setlinestyle(SOLID_LINE, 0, 3);
        drawpoly( edges, figure );
        getch();
        scale(figure,edges,dx,dy,cx,cy);
        setcolor(RED);
        drawpoly( edges, figure );
        getch();
}

Above is the source code for C Program to perform 2D Transformations using Scaling which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Graphic Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program to perform 2D Transformations in... >>
<< Write a C Program to perform 2D Transformations in...