January 15, 2014

Rainbow - part 2

float colors[] =
{1.0, 0.0, 0.0,
1.0, 0.5, 0.0,
1.0, 1.0, 0.0,
 0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
1.0, 0.0, 1.0};

int startX = -1.0, middleX = 0.0, endX = 1.0;
int RED = 0, ORANGE = 3, YELLOW = 6, GREEN = 9, BLUE = 12, PURPLE = 15;

void drawLine(float rainbowBottom, int color)
{
glBegin(GL_LINES);
glColor3f(colors[color], colors[color + 1], colors[color + 2]);
glVertex3f(startX, rainbowBottom, 0.0);
glVertex3f(middleX, rainbowBottom + .08, 0.0);
glVertex3f(middleX, rainbowBottom + .08, 0.0);
glVertex3f(endX, rainbowBottom, 0.0);
glEnd();
}

void display()
{
  glClearColor(1,1,1,1);
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_LINES);

  drawLine(.5, RED);
  drawLine(.45, ORANGE);
  drawLine(.4, YELLOW);
  drawLine(.35, GREEN);
  drawLine(.3, BLUE);
  drawLine(.25, PURPLE);

  glEnd();
  glutSwapBuffers();
}

int main(int argc, char** argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
  glutInitWindowSize(600,600);

  glutCreateWindow("not a rainbow but i can still pretend");
  glutDisplayFunc(display);

  glutMainLoop();
}

Still does the same thing, but in a clearer way to understand.

I do realize I could be using github.