/*  trycanvas.cpp
 *  This program demonstrates the use of Canvas for a simulation:
 *  Fibonacci numbers
 *  Click the right button to exit.
 */
#include << X11/Xlib.h>
#include << fstream.h>
#include << math.h>
#include << GL/glut.h>
#include << GL/gl.h>
#include << stdlib.h>
#include << stdio.h>
#include "Canvas.h"

const float worldWidth = 15.0;
const float worldHeight = 1000.0;        
const int screenWidth = 640;
const int screenHeight = 480;
Canvas cvs(screenWidth, screenHeight, "Try out Canvas");

void myInit(void) 
{
   cvs.setBackgroundColor (1.0, 1.0, 1.0);   // set black background color
   cvs.setColor (0.0, 0.0, 0.0);       // set the drawing color
   glPointSize (4.0);                  // set dot size 2 x 2
   cvs.setWindow(0.0, worldWidth, 0.0, worldHeight);
}

void myDisplay(void)
{
int a = 1, b = 1, c = 1;

    cvs.clearScreen();     // clear the screen
    cvs.setViewport(0, 640, 0, 480);
    cvs.moveTo(0, 1);
    cvs.lineTo(1, 1);
    for (int i = 2; i <= worldWidth; i++) {
        c = a + b;
        a = b;
        b = c;
        cvs.lineTo(i, c);
    }
}

void myMouse(int button, int state, int x, int y)
{
  switch (button) {
     case GLUT_RIGHT_BUTTON:
        if (state == GLUT_DOWN)
           exit (-1);
        break;
     default:
        break;
  }
}

int main(int argc, char** argv)
{

   myInit ();
   glutDisplayFunc(myDisplay);              // register redraw function
   glutMouseFunc(myMouse);                  // register myMouse function
   glutMainLoop();                          // go into a perpetual loop
   return 0;
}