#include #include #include #include #define RND ((float)rand( )/RAND_MAX) #define True 1 #define False 0 #define WINSIZE 2000 #define ROWSIZE 8000 #define MAX 200 void display(void); void idle(void); void init(void); int main(int argc, char** argv); float j; float distance(float x, float y) { float i = pow(x, 2.0) + pow(y, 2.0); i = sqrt(i); return i; } int mandel(float zx, float zy, float cx, float cy, int count) { float new_zx, new_zy; if(distance(zx, zy) > 10) { return count; } else if(count > MAX) { return 1; } new_zx = pow(zx, 2.0) - pow(zy, 2.0) + cx; new_zy = 2*zx*zy + cy; return mandel(new_zx, new_zy, zx, zy, count + 1); } void display( ) { int i, out; float color; glPointSize(1.0); glBegin(GL_POINTS); for(i = 0; i < ROWSIZE; i++) { out = mandel(0,0, i*1.0/ROWSIZE + 0.3, j*1.0/ROWSIZE + 0.3, 0); if(out == 1) { glColor3f(0.0, 0.0, 0.0); } else { color = (float)out/MAX; glColor3f(0.3, color, color - 0.1); } glVertex3f(i*0.4 - WINSIZE/2, j, 0.0); } glEnd( ); glutSwapBuffers( ); j -= 0.6; } void idle( ) { glutPostRedisplay( ); } void init( ) { glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_FLAT); glLoadIdentity( ); glOrtho(- WINSIZE/2, WINSIZE/2, -WINSIZE, WINSIZE, -20.0, 20.0); glClear(GL_COLOR_BUFFER_BIT); j = WINSIZE; } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(WINSIZE, WINSIZE); glutInitWindowPosition(0,0); glutCreateWindow("MandelBrot"); init( ); glutDisplayFunc(display); glutIdleFunc(idle); glutMainLoop( ); return 0; }