Skip to content

Commit d3b7d8d

Browse files
authored
Updated Julia sets
No longer prints the point of the julia set you chose - you can instead press space to view both the coordinates and the julia set parameters. Now you can hold "J" and move your mouse around for a real time Julia map thing.
1 parent 453d705 commit d3b7d8d

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

mandel.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bool render=true;
1515
long double xPos=-3.2;
1616
long double yPos=-2.0;
1717
long double zoom=150;
18+
int frame=0;int oFrame=1486618625;
1819
long double xJul,yJul;
1920
int fractal=1;
2021
long 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;
2728
void 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

3637
void 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 <<"\ny: " << yPos << "\nZoom:" << zoom << "\n--------------\n";glutPostRedisplay();
42+
if(julia){
43+
std::cout << "---Position---\n"<< "x: " << xPos <<"\ny: " << yPos << "\nZoom: " << zoom << "\nJulia x: " << xJul << "\nJulia y: " << yJul << "\n--------------\n";glutPostRedisplay();
44+
45+
}else{
46+
std::cout << "---Position---\n"<< "x: " << xPos <<"\ny: " << yPos << "\nZoom:" << 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--\nReal:" << xJul << "\nImag:" << 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
}
6974
long 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){
129134
void 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+
}
216224
void 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

Comments
 (0)