@@ -15,6 +15,7 @@ bool render=true;
1515long double xPos=-3.2 ;
1616long double yPos=-2.0 ;
1717long double zoom=150 ;
18+ int frame=0 ;int oFrame=1486618625 ;
1819long double xJul,yJul;
1920int fractal=1 ;
2021long double startX,startY,start_X,start_Y;
@@ -27,18 +28,22 @@ float period=0,iterations=0,iter=0,log_zn,nu,r1,r2,g1,g2,b1,b2,deltaX,deltaY,t;
2728void reset (){
2829 xPos=-3.2 ;yPos=-2.0 ;zoom=150 ;render=true ;glutPostRedisplay ();
2930}
30- bool inCardioidOrBulb (long double x, long double y) {
31- long double y2 = y * y;
32- long double q = (x - 0.25 ) * (x - 0.25 ) + y2;
33- return (q * (q + (x - 0.25 )) < y2 / 4.0 || (x + 1.0 ) * (x + 1.0 ) + y2 < 0.0625 );
34- }
31+ // bool inCardioidOrBulb(long double x, long double y) {
32+ // long double y2 = y * y;
33+ // long double q = (x - 0.25) * (x - 0.25) + y2;
34+ // return (q * (q + (x - 0.25)) < y2 / 4.0 || (x + 1.0) * (x + 1.0) + y2 < 0.0625);
35+ // }
3536
3637void key (unsigned char key, int x, int y) {
3738 if (key == 27 ) {
3839 exit (0 );
3940 }
4041 if (key == 32 ){
41- std::cout << " ---Position---\n " << " x: " << xPos <<" \n y: " << yPos << " \n Zoom:" << zoom << " \n --------------\n " ;glutPostRedisplay ();
42+ if (julia){
43+ std::cout << " ---Position---\n " << " x: " << xPos <<" \n y: " << yPos << " \n Zoom: " << zoom << " \n Julia x: " << xJul << " \n Julia y: " << yJul << " \n --------------\n " ;glutPostRedisplay ();
44+
45+ }else {
46+ std::cout << " ---Position---\n " << " x: " << xPos <<" \n y: " << yPos << " \n Zoom:" << zoom << " \n --------------\n " ;glutPostRedisplay ();}
4247 }
4348
4449 switch (key){
@@ -62,8 +67,8 @@ void key(unsigned char key, int x, int y) {
6267 case ' 1' : {fractal=1 ;std::cout << " Mandelbrot Set\n " ;glutPostRedisplay ();break ;}
6368 case ' r' : {reset ();break ;}
6469 case ' f' : {fullscreen=!fullscreen;if (fullscreen){oWIDTH=WIDTH;oHEIGHT=HEIGHT;glutFullScreen ();}else {glutReshapeWindow (oWIDTH,oHEIGHT);}break ;}
65- case ' j' : {if (julia){julia=false ;reset ();std::cout << " -Fractal Mode- \n " ;}else {julia=true ;xJul=xPos+mouseX/zoom;
66- yJul=yPos+(HEIGHT-mouseY)/zoom;reset ();std::cout << " --Julia Mode-- \n Real: " << xJul << " \n Imag: " << yJul << " \n -------------- \n " ;} break ;}
70+ case ' j' : {if (julia&&frame>oFrame+ 8 ){julia=false ;reset ();}else {julia=true ;xJul=xPos+mouseX/zoom;
71+ yJul=yPos+(HEIGHT-mouseY)/zoom;}oFrame=frame; glutPostRedisplay ();break ;}
6772 }
6873}
6974long double r0,i0,real,imag,tempreal,io,ro;
@@ -75,7 +80,7 @@ float escapesmooth(long double real, long double imag, int x, int y){
7580 r0=xJul;i0=yJul;
7681 }
7782 iter=0.0 ;
78- if (fractal==1 &&!julia){if (inCardioidOrBulb (real,imag)){return maxIter;}}
83+ // if(fractal==1&&!julia){if(inCardioidOrBulb(real,imag)){return maxIter;}}
7984 while (iter<maxIter&&real*real+imag*imag<=16 ){
8085 if (fractal==4 ){
8186 tempreal=real*imag+r0;
@@ -129,8 +134,8 @@ float escapesmooth(long double real, long double imag, int x, int y){
129134void display (){
130135 glClear (GL_COLOR_BUFFER_BIT);
131136 if (render){
132- glBegin (GL_POINTS);
133137 for (int y=HEIGHT;y>0 ;y--){
138+ glBegin (GL_POINTS);
134139 for (int x=0 ;x<WIDTH+1 ;x++){
135140 iterations=escapesmooth (x/zoom+xPos,y/zoom+yPos,xJul,yJul);
136141 glVertex2i (x,y);
@@ -213,6 +218,9 @@ void onMouseMove(int x, int y) {
213218 mouseX = x;
214219 mouseY = y;
215220}
221+ void idle (){
222+ frame++;
223+ }
216224void specialfunc (int key, int x, int y){
217225 switch (key){
218226 case GLUT_KEY_UP:{
@@ -236,6 +244,7 @@ int main(int argc, char** argv){
236244 gluOrtho2D (0 , WIDTH, 0 , HEIGHT);
237245 glLoadIdentity ();
238246 glClearColor (0.0 ,0.0 ,0.0 ,1.0 );
247+ glutSetKeyRepeat (1 );
239248 std::cout << " Maximum iterations: " << maxIter << " \n " ;
240249
241250 glutSpecialFunc (specialfunc);
@@ -245,6 +254,7 @@ int main(int argc, char** argv){
245254 glutMouseFunc (mouse);
246255 glutMotionFunc (motion);
247256 glutKeyboardFunc (key);
257+ glutIdleFunc (idle);
248258
249259 glutMainLoop ();
250260 return 0 ;
0 commit comments