1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#pragma once
#include "spheres.hpp"
#include <GL/glut.h>
void draw(const Sphere<2>& s, std::array<double, 3> 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 <Particle<2> 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();
}
|