Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. // cpp program for translation
  2. // of a single line
  3. #include<bits/stdc++.h>
  4. #include<graphics.h>
  5.  
  6. using namespace std;
  7.  
  8. // function to translate line
  9. void translateLine ( int P[][2], int T[])
  10. {
  11.     /* init graph and line() are used for
  12.        representing line through graphical
  13.        functions
  14.     */
  15.     int gd = DETECT, gm, errorcode;
  16.     initgraph (&gd, &gm, "c:\\tc\\bgi");
  17.  
  18.     // drawing original line using graphics functions
  19.     setcolor (7);
  20.     line(P[0][0], P[0][1], P[1][0], P[1][1]);
  21.  
  22.     // calculating translated coordinates
  23.     P[0][0] = P[0][0] + T[0];
  24.     P[0][1] = P[0][1] + T[1];
  25.     P[1][0] = P[1][0] + T[0];
  26.     P[1][1] = P[1][1] + T[1];
  27.  
  28.     // drawing translated line using graphics functions
  29.     setcolor(3);
  30.     line(P[0][0], P[0][1], P[1][0], P[1][1]);
  31.     getch();
  32.     closegraph();
  33. }
  34.  
  35. // driver program
  36. int main()
  37. {
  38.     int P[2][2] = {5, 8, 12, 18}; // coordinates of point
  39.     int T[] = {20, 100}; // translation factor
  40.     translateLine (P, T);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement