Bifurcation Code

WB01343_.gif (599 bytes)

// Bifurcation Diagram
// Tom Dixon - Period 3

#include "glaux.h"

static void Init() {
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glShadeModel(GL_FLAT);
}

static void Reshape(int w, int h) {
  glViewport(0, 0, GLint(w), GLint(h));
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, 4.0, 0.0, 1.0, -1.0, 1.0);
  glMatrixMode(GL_MODELVIEW);
}

static void key_esc() { auxQuit(); }

void showdiagram() {              // Draws bifurcation diagram
  double k, x;
  glColor3f(1.0, 1.0, 0.0);
  glBegin(GL_POINTS);
  for(k=0; k<4; k+=0.001) {       // Step through k
    x=0.33;
    for(int i=0; i<15; i++) {     // Iterate function, plotting each value
      x=k*x*(1-x);
      glVertex3f(k, x, 0.0);
    }
  }
  glEnd();
}   

static void display() {
  glClear(GL_COLOR_BUFFER_BIT);
  showdiagram();
  glFlush();
  auxSwapBuffers();
}

void main() {
  auxInitDisplayMode(AUX_RGBA);
  auxInitPosition(50, 50, 800, 400);
  if (auxInitWindow("Logistic Growth Function")==GL_FALSE) auxQuit();
  Init();
  auxExposeFunc(Reshape);
  auxReshapeFunc(Reshape);
  auxMainLoop(display);
}

WB01343_.gif (599 bytes)