Advertisement
marwanpro

zoyzo

Nov 14th, 2016
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <Grapic.h>
  2. #include <cmath>
  3.  
  4. using namespace grapic;
  5.  
  6. #define _USE_MATH_DEFINES
  7. #define DIMW 500
  8.  
  9.  
  10. struct Complex
  11. #pragma region complex
  12. {
  13.     int x, y;
  14. };
  15.  
  16.  
  17. Complex make_complex(float x, float y)
  18. {
  19.     Complex tmp;
  20.     tmp.x = x;
  21.     tmp.y = y;
  22.     return tmp;
  23. }
  24.  
  25.  
  26. Complex make_complex_exp(float r, float theta)
  27. {
  28.     Complex tmp;
  29.     tmp.x = cos(theta) * r;
  30.     tmp.y = sin(theta) * r;
  31.     return tmp;
  32. }
  33.  
  34.  
  35. Complex operator+(Complex a, Complex b)
  36. {
  37.     Complex tmp = { a.x + b.x, a.y + b.y };
  38.     return tmp;
  39. }
  40.  
  41.  
  42. Complex operator-(Complex a, Complex b)
  43. {
  44.     Complex tmp = { a.x - b.x, a.y - b.y };
  45.     return tmp;
  46. }
  47.  
  48.  
  49. Complex operator*(float a, Complex b)
  50. {
  51.     Complex tmp = { a * b.x, a * b.y };
  52.     return tmp;
  53. }
  54.  
  55.  
  56. Complex operator/(Complex a, float b)
  57. {
  58.     Complex tmp = { a.x / b, a.y / b };
  59.     return tmp;
  60. }
  61.  
  62.  
  63. Complex translate(Complex p, float dx, float dy)
  64. {
  65.     return p + make_complex(dx, dy);
  66. }
  67.  
  68.  
  69. Complex scale(Complex p, float cx, float cy, float sc)
  70. {
  71.     Complex tr = make_complex(cx, cy);
  72.     return sc * (p - tr) + tr;
  73. }
  74.  
  75.  
  76. Complex operator*(Complex a, Complex b)
  77. {
  78.     Complex tmp = make_complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
  79.     return tmp;
  80. }
  81.  
  82.  
  83. float to_deg(float rad)
  84. {
  85.     return (180.f * rad / M_PI);
  86. }
  87.  
  88.  
  89. float to_rad(float deg)
  90. {
  91.     return M_PI * deg / 180.f;
  92. }
  93.  
  94.  
  95. Complex rotate(Complex p, float cx, float cy, float theta, bool deg = true)
  96. {
  97.     Complex rot;
  98.     if (deg) rot = make_complex_exp(1, to_rad(theta));
  99.     else rot = make_complex_exp(1, theta);
  100.     Complex tr = make_complex(cx, cy);
  101.     return (p - tr) * rot + tr;
  102. }
  103. #pragma endregion
  104.  
  105.  
  106. void init()
  107. {
  108.    
  109. }
  110.  
  111.  
  112. void update()
  113. {
  114.    
  115. }
  116.  
  117.  
  118. void draw()
  119. {
  120.    
  121. }
  122.  
  123.  
  124. int main(int, char**)
  125. {
  126.     bool stop = false;
  127.     winInit("Complex", DIMW, DIMW);
  128.     init();
  129.     while (!stop)
  130.     {
  131.         winClear();
  132.         draw();
  133.         update();
  134.         stop = winDisplay();
  135.     }
  136.     winQuit();
  137.     return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement