summaryrefslogtreecommitdiff
path: root/src/animate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/animate.cpp')
-rw-r--r--src/animate.cpp64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/animate.cpp b/src/animate.cpp
index 8c2d12f..26f4996 100644
--- a/src/animate.cpp
+++ b/src/animate.cpp
@@ -1,15 +1,15 @@
#include "animate.hpp"
-animate::animate(unsigned int Lx, unsigned int Ly, unsigned int window_size, int argc, char *argv[]) : Lx(Lx), Ly(Ly), G(Lx * Ly) {
+animate::animate(double Lx, double Ly, unsigned int window_size, int argc, char *argv[]) : G(2 * (unsigned int)ceil(Lx * Ly / 2)) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(window_size, (unsigned int )(window_size * ((double)Ly / (double)Lx)));
+ glutInitWindowSize((unsigned int)(Lx / Ly * window_size), window_size);
glutCreateWindow("wolff");
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluOrtho2D(-1.0, Lx + 3.0, -1.0 , Ly + 3.0);
+ gluOrtho2D(-1, Lx + 3, -1 , Ly + 3);
}
void animate::pre_fracture(const network &n) {
@@ -25,18 +25,18 @@ void animate::pre_fracture(const network &n) {
graph::coordinate r1 = n.G.vertices[n.G.edges[i].v[0]].r;
graph::coordinate r2 = n.G.vertices[n.G.edges[i].v[1]].r;
- if (fabs(r1.x - r2.x) > Lx / 2) {
- if (r1.x < Lx / 2) {
- r1.x += Lx;
+ if (fabs(r1.x - r2.x) > n.G.L.x / 2) {
+ if (r1.x < n.G.L.x / 2) {
+ r1.x += n.G.L.x;
} else {
- r2.x += Lx;
+ r2.x += n.G.L.x;
}
}
- if (fabs(r1.y - r2.y) > Ly / 2) {
- if (r1.y < Ly / 2) {
- r1.y += Ly;
+ if (fabs(r1.y - r2.y) > n.G.L.y / 2) {
+ if (r1.y < n.G.L.y / 2) {
+ r1.y += n.G.L.y;
} else {
- r2.y += Ly;
+ r2.y += n.G.L.y;
}
}
@@ -47,8 +47,8 @@ void animate::pre_fracture(const network &n) {
glFlush();
}
-void animate::bond_broken(const network& net, const current_info& cur, unsigned int i) {
- long double c = logl(cur.conductivity / fabs(cur.currents[i])) + net.thresholds[i];
+void animate::bond_broken(const network& n, const current_info& cur, unsigned int i) {
+ long double c = logl(cur.conductivity / fabs(cur.currents[i])) + n.thresholds[i];
if (c > lv && avalanches.back().size() > 0) {
lv = c;
avalanches.push_back({i});
@@ -56,25 +56,25 @@ void animate::bond_broken(const network& net, const current_info& cur, unsigned
avalanches.back().push_back(i);
}
- boost::add_edge(net.G.dual_edges[i].v[0], net.G.dual_edges[i].v[1], {i}, G);
+ boost::add_edge(n.G.dual_edges[i].v[0], n.G.dual_edges[i].v[1], {i}, G);
glBegin(GL_LINES); // Each set of 3 vertices form a triangle
glColor3f(1.0f, 1.0f, 1.0f); // Blue
- graph::coordinate r1 = net.G.vertices[net.G.edges[i].v[0]].r;
- graph::coordinate r2 = net.G.vertices[net.G.edges[i].v[1]].r;
+ graph::coordinate r1 = n.G.vertices[n.G.edges[i].v[0]].r;
+ graph::coordinate r2 = n.G.vertices[n.G.edges[i].v[1]].r;
- if (fabs(r1.x - r2.x) > Lx / 2) {
- if (r1.x < Lx / 2) {
- r2.x -= Lx;
+ if (fabs(r1.x - r2.x) > n.G.L.x / 2) {
+ if (r1.x < n.G.L.x / 2) {
+ r2.x -= n.G.L.x;
} else {
- r2.x += Lx;
+ r2.x += n.G.L.x;
}
}
- if (fabs(r1.y - r2.y) > Ly / 2) {
- if (r1.y < Ly / 2) {
- r2.y -= Ly;
+ if (fabs(r1.y - r2.y) > n.G.L.y / 2) {
+ if (r1.y < n.G.L.y / 2) {
+ r2.y -= n.G.L.y;
} else {
- r2.y += Ly;
+ r2.y += n.G.L.y;
}
}
@@ -111,18 +111,18 @@ void animate::post_fracture(network &n) {
graph::coordinate r1 = n.G.vertices[n.G.edges[i].v[0]].r;
graph::coordinate r2 = n.G.vertices[n.G.edges[i].v[1]].r;
- if (fabs(r1.x - r2.x) > Lx / 2) {
- if (r1.x < Lx / 2) {
- r1.x += Lx;
+ if (fabs(r1.x - r2.x) > n.G.L.x / 2) {
+ if (r1.x < n.G.L.x / 2) {
+ r1.x += n.G.L.x;
} else {
- r2.x += Lx;
+ r2.x += n.G.L.x;
}
}
- if (fabs(r1.y - r2.y) > Ly / 2) {
- if (r1.y < Ly / 2) {
- r1.y += Ly;
+ if (fabs(r1.y - r2.y) > n.G.L.y / 2) {
+ if (r1.y < n.G.L.y / 2) {
+ r1.y += n.G.L.y;
} else {
- r2.y += Ly;
+ r2.y += n.G.L.y;
}
}