#include "space_wolff.hpp" #include template void drawSphere(const Vector& x, Radius r, std::array color = {0, 0, 0}, unsigned nPoints = 20) { glColor3d(color[0], color[1], color[2]); glBegin(GL_POLYGON); for (unsigned i = 0; i < nPoints; i++) { glVertex2d(x(0) + r * cos(2 * i * M_PI / nPoints), x(1) + r * sin(2 * i * M_PI / nPoints)); } glEnd(); } template void draw(const Spin& s, std::array color = {0, 0, 0}) { drawSphere(s.x, s.s, color); } template void draw(const Spin>& s, std::array color = {0, 0, 0}) { drawSphere(s.x + s.s.relativePosition, s.s.radius, color); drawSphere(s.x - s.s.relativePosition, s.s.radius, color); } template void draw(const Spin& s, std::array color = {0, 0, 0}) { if (s.s == 1) { glColor3d(color[0], color[1], color[2]); } else if (s.s == -1) { glColor3d(1 - color[0], 1 - color[1], 1 - color[2]); } glRecti(s.x(0), s.x(1), s.x(0) + 1, s.x(1) + 1); } template class Animation : public measurement { private: unsigned n; unsigned wait; double L; R s₀⁻¹; public: Animation(T L, unsigned w, int argc, char* argv[], unsigned wait, bool periodic = false) : s₀⁻¹(L), wait(wait), L(1000 * L) { n = 0; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(w, w); glutCreateWindow("wolffWindow"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (periodic) { gluOrtho2D(0, L, 0, L); } else { gluOrtho2D(-L, L, -L, L); } } void pre_cluster(const Model& m, unsigned, const Transformation* t) override { s₀⁻¹ = m.s0.inverse(); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); for (const Spin* s : m.s) { draw(s₀⁻¹.act(*s)); } if (n > wait) { glColor3d(1.0, 0.0, 0.0); glLineWidth(3); glBegin(GL_LINES); Vector r = t->r.t / 2; double θ = atan2(r(1), r(0)); Vector v1 = s₀⁻¹.act({r(0) + L * sin(θ), r(1) - L * cos(θ)}); Vector v2 = s₀⁻¹.act({r(0) - L * sin(θ), r(1) + L * cos(θ)}); glVertex2d(v1(0), v1(1)); glVertex2d(v2(0), v2(1)); glEnd(); } glFlush(); } void plain_site_transformed(const Model& m, const Transformation& t) override { if (n > wait) { std::array color; if (t.current().size() > 1) { color = {0, 0, 1}; } else { color = {0, 1, 0}; } for (const Spin* s : t.current()) { if (s != NULL) { draw(s₀⁻¹.act(*s), color); } else { } } } } void post_cluster(const Model& m) override { if (n > wait) { glFlush(); sleep(2); } n++; } };