C++ Graphics Program to Implement Line and Point Translation of Objects and Shapes in Screen

Shall I start the article to teach the topic “C++ Graphics Program to Implement Line and Point Translation of Objects and Shapes in Screen” to you? Come on! Let’s go for an article to see the possibilities to learn about it.

Program Code

// C++ program for translation
// of a single coordinate
#include<bits/stdc++.h>
#include<graphics.h>

using namespace std;

// function to translate point
void translatePoint ( int P[], int T[])
{
/* init graph and putpixel are used for
representing coordinates through graphical
functions
*/
int gd = DETECT, gm, errorcode;
initgraph (&gd, &gm, "c:\tc\bgi");

cout<<"Original Coordinates :"<<P<<","<<P;

putpixel (P, P, 1);

// calculating translated coordinates
P = P + T;
P = P + T;

cout<<"nTranslated Coordinates :"<< P<<","<< P;

// Draw new coordinatses
putpixel (P, P, 3);
closegraph();
}

// driver program
int main()
{
int P = {5, 8}; // coordinates of point
int T[] = {2, 1}; // translation factor
translatePoint (P, T);
return 0;
}
// cpp program for translation
// of a single line
#include<bits/stdc++.h>
#include<graphics.h>

using namespace std;

// function to translate line
void translateLine ( int P[], int T[])
{
/* init graph and line() are used for
representing line through graphical
functions
*/
int gd = DETECT, gm, errorcode;
initgraph (&gd, &gm, "c:\tc\bgi");

// drawing original line using graphics functions
setcolor (2);
line(P, P, P, P);

// calculating translated coordinates
P = P + T;
P = P + T;
P = P + T;
P = P + T;

// drawing translated line using graphics functions
setcolor(3);
line(P, P, P, P);
closegraph();
}

// driver program
int main()
{
int P = {5, 8, 12, 18}; // coordinates of point
int T[] = {2, 1}; // translation factor
translateLine (P, T);
return 0;
}

Final Words

I hope this article helps you to know about “C++ Graphics Program to Implement Line and Point Translation of Objects and Shapes in Screen”. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks. Thank You!

Share on: Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.