/* Jin Ding  2/5/98  Period 3 */
/* bifurc.cpp */

#include <iostream.h>
#include <stdio.h>
#include "glaux.h"

float temp=0.03;

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

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

static void key_up() {
  temp+=.00000001;
  if (temp >= 1.0) temp = .0000001;
  cout<<"AUX_UP   Initial X : "<<temp<<endl;
}

static void key_down() {
  temp-=.00000001;
  if (temp <= 0.0) temp = .9999999;
  cout<<"AUX_DOWN Initial X : "<<temp<<endl;
}

static void key_return() {
  cout<<"New X Value : ";
  cin >>temp;
  if ((temp >= 1.0) || (temp <= 0.0)) key_return();
}

static void key_esc() {
  auxQuit();
}

void DrawMyStuff() {
int i;
double k,y;

  glColor3f(0.7,0.0,0.9);
  glPushMatrix();
  glBegin(GL_POINTS);
  for (k=0;k<4;k+=.003) { 
  y=temp;
    for (i=0;i<1000;i++) {
      y=k*y*(1-y);
      glColor3f(0.9/(1.75*y),0.0,0.9/k);
      glVertex3f(k,y,0.0);
    }
  }
  glEnd();
  glPopMatrix();
}
 
static void display() {
  glClear(GL_COLOR_BUFFER_BIT);
  DrawMyStuff();
  glFlush();
  auxSwapBuffers();
}

int main(int argc,char **argv) {
  auxInitDisplayMode(AUX_RGBA);
  auxInitPosition(50,100,800,200);
  if (auxInitWindow("Bifurcation") == GL_FALSE)
    auxQuit();
  Init();

  auxExposeFunc(Reshape);
  auxReshapeFunc(Reshape);
  auxKeyFunc(AUX_UP,key_up);
  auxKeyFunc(AUX_DOWN,key_down);
  auxKeyFunc(AUX_RETURN,key_return);
  auxMainLoop(display);
  return 0;
}
