Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Grapic.h>
- #include <cmath>
- using namespace grapic;
- #define _USE_MATH_DEFINES
- #define DIMW 500
- struct Complex
- #pragma region complex
- {
- int x, y;
- };
- Complex make_complex(float x, float y)
- {
- Complex tmp;
- tmp.x = x;
- tmp.y = y;
- return tmp;
- }
- Complex make_complex_exp(float r, float theta)
- {
- Complex tmp;
- tmp.x = cos(theta) * r;
- tmp.y = sin(theta) * r;
- return tmp;
- }
- Complex operator+(Complex a, Complex b)
- {
- Complex tmp = { a.x + b.x, a.y + b.y };
- return tmp;
- }
- Complex operator-(Complex a, Complex b)
- {
- Complex tmp = { a.x - b.x, a.y - b.y };
- return tmp;
- }
- Complex operator*(float a, Complex b)
- {
- Complex tmp = { a * b.x, a * b.y };
- return tmp;
- }
- Complex operator/(Complex a, float b)
- {
- Complex tmp = { a.x / b, a.y / b };
- return tmp;
- }
- Complex translate(Complex p, float dx, float dy)
- {
- return p + make_complex(dx, dy);
- }
- Complex scale(Complex p, float cx, float cy, float sc)
- {
- Complex tr = make_complex(cx, cy);
- return sc * (p - tr) + tr;
- }
- Complex operator*(Complex a, Complex b)
- {
- Complex tmp = make_complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
- return tmp;
- }
- float to_deg(float rad)
- {
- return (180.f * rad / M_PI);
- }
- float to_rad(float deg)
- {
- return M_PI * deg / 180.f;
- }
- Complex rotate(Complex p, float cx, float cy, float theta, bool deg = true)
- {
- Complex rot;
- if (deg) rot = make_complex_exp(1, to_rad(theta));
- else rot = make_complex_exp(1, theta);
- Complex tr = make_complex(cx, cy);
- return (p - tr) * rot + tr;
- }
- #pragma endregion
- void init()
- {
- }
- void update()
- {
- }
- void draw()
- {
- }
- int main(int, char**)
- {
- bool stop = false;
- winInit("Complex", DIMW, DIMW);
- init();
- while (!stop)
- {
- winClear();
- draw();
- update();
- stop = winDisplay();
- }
- winQuit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement