Advertisement
wtmhahagd

mandelbrot

Nov 30th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. void displayfunc() {
  2. glClear(GL_COLOR_BUFFER_BIT);
  3. glColor3f(0.0, 1.0, 0.0);
  4.  
  5. for (int x = 0; x < N; x++) {
  6. for (int y = 0; y < N; y++) {
  7. glBegin(GL_POINTS);
  8.  
  9. double scaledX = (x - N / 2) * 4 / (N * 1.0);
  10. double scaledY = (y - N / 2) * 4 / (N * 1.0); //dark voodoo magic
  11.  
  12. int count = 0;
  13. int max = 256;
  14.  
  15. double a, b = 0.0;
  16.  
  17. while (count < max && ((a * a) + (b * b)) <= 4) {
  18. int temp_a = (a * a) - (b * b) + scaledX;
  19. b = 2 * a * b + scaledY;
  20. a = temp_a;
  21. count++;
  22. }
  23.  
  24. if (count < max) {
  25. glColor3f(1.0, 1.0, 0.0); //outside color
  26. } else {
  27. glColor3f(0.0, 0.0, 0.0); //inside color
  28. }
  29.  
  30. glVertex2f(x, y); //draw a pixel of the color specified in glColor3f
  31. glEnd();
  32. }
  33. }
  34.  
  35. glutSwapBuffers(); //always at the end of displayfunc()
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement