Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "OpenGLFramework.h"
- #ifndef __LORENZ_ATTRACTOR__
- #define __LORENZ_ATTRACTOR__
- using namespace openGLFramework;
- //All constants go here
- #define MAX_PARTICLES 10000
- class LorenzAttractor {
- private:
- unsigned int numPointsDrawn;
- float sx, sy, sz, x0, y0, z0, x1, y1, z1;
- float red, green, blue;
- float h, a, b, c;
- public:
- LorenzAttractor() : h(0.01), a(10.0), b(28.0), c(8.0/3.0) {
- numPointsDrawn = 0;
- x0 = y0 = z0 = x1 = y1 = z1 = 0;
- red = green = blue = 0.5f;
- }
- LorenzAttractor(float xStart, float yStart, float zStart, float colorRed, float colorGreen, float colorBlue): h(0.01), a(10.0), b(28.0), c(8.0/3.0) {
- numPointsDrawn = 0;
- x1 = y1 = z1 = 0;
- sx = x0 = xStart;
- sy = y0 = yStart;
- sz = z0 = zStart;
- red = colorRed;
- green = colorGreen;
- blue = colorBlue;
- }
- void setParams(float h, float a, float b, float c) {
- this->h = h;
- this->a = a;
- this->b = b;
- this->c = c;
- }
- void setAttributes(float xStart, float yStart, float zStart, float colorRed, float colorGreen, float colorBlue) {
- sx = x0 = xStart;
- sy = y0 = yStart;
- sz = z0 = zStart;
- red = colorRed;
- green = colorGreen;
- blue = colorBlue;
- }
- void simulate() {
- unsigned int i = 0;
- x0 = sx;
- y0 = sy;
- z0 = sz;
- x1 = y1 = z1 = 0.0f;
- glPushMatrix();
- glPointSize(1.0f);
- glColor3f(red, green, blue);
- glBegin(GL_LINE_STRIP);
- for (i = 0; i < numPointsDrawn; i++) {
- x1 = x0 + h * a * (y0 - x0);
- y1 = y0 + h * (x0 * (b - z0) - y0);
- z1 = z0 + h * (x0 * y0 - c * z0);
- x0 = x1;
- y0 = y1;
- z0 = z1;
- glVertex3f(x0, y0, z0);
- }
- glEnd();
- glPopMatrix();
- numPointsDrawn = (numPointsDrawn >= MAX_PARTICLES) ? 0 : numPointsDrawn + 1;
- }
- };
- #endif //__LORENZ_ATTRACTOR__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement