title: my mandelbrot set outputs wired image
body: <p>I am trying to create a mandelbrot image using c++/opengl.  Below is the simple code that i have came up with so far and the image that comes out:</p>
  
  <p><img src="https://i.stack.imgur.com/GKt3Z.png" alt="enter image description here"></p>
  
  <pre><code> #include&lt;GL/gl.h&gt;
   #include &lt;GL/glu.h&gt;
   #include &lt;GL/glut.h&gt;
   #include &lt;math.h&gt;
   #include &lt;stdio.h&gt;
   #include &lt;stdlib.h&gt;
  
   double dividecubesby  = 300;
   const double left = -2.0;
   const double right = 2.0;
   const double bottom = -2.0;
   const double top = 2.0;
   int maxiteration = 90;
  
   int mandtest(double Cr, double Ci){
  
     double Zr = 0.0;
     double Zi = 0.0;
     int times = 0;
  
     Zr = Zr+Cr;
     Zi = Zi+Ci;
  
        while ((((Zr*Zr)+(Zi*Zi))&lt;4) &amp;&amp; (times &lt; maxiteration)){
  
  
          Zr = (Zr*Zr)-(Zi*Zi);
          Zi = 2*Zr*Zi;
          Zr = Zr+Cr;
          Zi = Zi+Ci;                
          times = times+1;  
  
        }
   return times;
  
  
  
  void display(void)
  {
          glClear(GL_COLOR_BUFFER_BIT);
          glColor3f(1.0f,1.0f,1.0f);
          double real = left;//this is the real part of  the order-pair in the cube
          double image = top;// this is the image part of the order-pair in the cube
          double deltax = ((right - left)/(dividecubesby));//this means 4/300
          double deltay = ((top- bottom)/(dividecubesby));// this means 4/300
  
  glBegin(GL_POINTS);
  
      for(double x= left;x&lt;=right;x += deltax ){
  
  
          for(double y= bottom; y&lt;=top;y +=  deltay ){
  
              if((mandtest(x,y))==maxiteration){
  
                  glColor3f(1.0f,1.0f,1.0f); 
                              glVertex2f(x,y);
  
              }
  
              else {
                  glColor3f(0.0f,0.0f,(float)mandtest(x,y)/maxiteration);
                                      glVertex2f(x,y);
              }
  
          }
      }
      glEnd();
  
  glFlush();
  
  }
  
  void init(void)
  {
  //select clearing (background) color
      glClearColor(0.0, 0.0, 0.0, 0.0);
  
          //initialize viewing values 
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
  //glortho(left,right,bottom,top,near,far)
      gluOrtho2D(-2.0, 2.0, -2.0, 2.0);
  }
  
  
  int main(int argc, char ** argv)
  {   
  glutInit(&amp;argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(dividecubesby,dividecubesby);
  glutCreateWindow("A Simple OpenGL Windows Application with GLUT");
  init();
  glutDisplayFunc(display);
  glutMainLoop();
  
  
      return 0;
  }
  </code></pre>