//Second Program in SuperComputer Applications...
//Formula:  x1=k(x0-x0*x0)

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "glaux.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

const double Initialx0=.5;
const xmax=25;
const kmax=4;
const double yinit=.5;

static void Init()
  { glClearColor(0.0,0.0,0.0,1.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,(double)kmax,0.0,1.0,-1.0,1.0);
    glMatrixMode(GL_MODELVIEW);
  }

static void KPUpArrow()
  { cout<<"Up Arrow Pressed\n"; }

static void KPDownArrow()
  { cout<<"Down Arrow Pressed\n"; }

void DrawingRoutine()
  { double x,y,k;
    glColor3f(1.0,0.0,0.0);
    glBegin(GL_POINTS);
      for(k=0;k<kmax;k+=.01)
        { y=yinit;
          for(x=0;x<xmax;x++)
            { y=k*(y-y*y);
              glVertex3f(k,y,0.0);
            }
        }
    glEnd();
  }

static void display()
  { glClear(GL_COLOR_BUFFER_BIT);
    DrawingRoutine();
    glFlush();
    glXSwapBuffers(auxXDisplay(), auxXWindow());
  }

int main(int argc,char **argv)
  { auxInitDisplayMode(AUX_DOUBLE | AUX_RGBA);
    auxInitPosition(0,0,640,400);
    if (auxInitWindow("SC2.cc")==GL_FALSE) auxQuit();
    Init();
    auxExposeFunc(Reshape);
    auxReshapeFunc(Reshape);
    auxKeyFunc(AUX_UP,KPUpArrow);
    auxKeyFunc(AUX_DOWN,KPDownArrow);
    auxMainLoop(display);
    return 0;
 }

