From 496dcbd9960677db246a84bcd3e4b4230ee28e0a Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 16 Sep 2021 16:47:05 +0200 Subject: Initial commit. --- animation.hpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 animation.hpp (limited to 'animation.hpp') diff --git a/animation.hpp b/animation.hpp new file mode 100644 index 0000000..26b3d55 --- /dev/null +++ b/animation.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "spheres.hpp" +#include + +void draw(const Sphere<2>& s, 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(s.x(0) + s.r * cos(2 * i * M_PI / nPoints), s.x(1) + s.r * sin(2 * i * M_PI / nPoints)); + } + glEnd(); +} + +void initializeAnimation(int argc, char** argv, unsigned window_size = 1000) { + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(window_size, window_size); + glutCreateWindow("spheres"); + glClearColor(0.0, 0.0, 0.0, 0.0); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, 1.0, 0, 1.0); + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); +} + +template T> void draw(const Model<2, T>& m) { + glClear(GL_COLOR_BUFFER_BIT); + for (const Sphere<2>& p : m.particles) { + draw(p); + if (p.intersectsBoundary()) { + for (Vector<2> Δy : {(Vector<2>){1,0}, {-1,0}, {0,1}, {0,-1}, {-1,1}, {1,1}, {1,-1},{-1,-1}}) { + draw({(Vector<2>)p.x + Δy, p.r}); + } + } + } + glFlush(); +} -- cgit v1.2.3-54-g00ecf