From 1da9ba0af64dd1ff07c9fda6226689b4e8701e43 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 25 Feb 2020 15:23:41 -0500 Subject: Minor refactoring of sphere commands and animation class, and introduction of Dimers --- animation.hpp | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 animation.hpp (limited to 'animation.hpp') diff --git a/animation.hpp b/animation.hpp new file mode 100644 index 0000000..857354e --- /dev/null +++ b/animation.hpp @@ -0,0 +1,111 @@ + +#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₀⁻¹(0), 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).template cast() / 2.0; + double θ = atan2(r(1), r(0)); + Vector v1 = s₀⁻¹.template act({r(0) + L * sin(θ), r(1) - L * cos(θ)}); + Vector v2 = s₀⁻¹.template 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++; + } +}; -- cgit v1.2.3-54-g00ecf