Sign in to follow this  

Help with Mandelbrot Ser

This topic is 3746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to plot the Mandelbrot set, I use white pixels to draw if the pixel is not in the set and blue if it is. However what this code draws does not look like the Mandelbrot set. for ( x = 1; x <= 640; x++) { for ( y = 1; y <= 480; y++) { for(n = 1; n < 90; n++) { glBegin(GL_POINTS); glColor3f( 1, 1, 1); // glVertex2f( x, y); p = x - 300; q = y - 300; u = x * x - y * y + p; v = 2 * x * y + q; if( u * u + v * v > 4) { glVertex2f( x, y); }//end if else { glColor3f( 0, 0, 1); glVertex2f( x, y); }//end else glEnd(); glFlush(); }//end for }//end for }//end for

Share this post


Link to post
Share on other sites
Here's a question: why do you draw a pixel for every single iteration? You should wait until all the iterations have been made, and then you should draw the pixel.

Also, you're calculating it wrong. First, you need the convert the screen coordinates to graph coordinates. Having each pixel equal a unit of 1 on a graph means that your mandelbrot set will be about 3 pixels big. Also, the equation is zi = zi-12 + c, where z0 = c, and c is the point on the graph you are calculating. Basically what that means is that you need to recursively edit u and v but multiplying them by each other and not x or y.

This looks like a good tutorial that you should go through, it will probably make a lot more sense after reading this.

I've rewritten part of your code, but I haven't tested it, so I'm not going to guarantee that it will work. (this chunk of code goes in the middle of the first two for loops)
p = (x - 400) / 200.0;
q = (y - 300) / 300.0;

glBegin(GL_POINTS);
for(n = 1; n < 90; n++)
{
float temp = u * u - v * v + p;
v = 2 * u * v + q;
u = temp;

if( u * u + v * v > 4)
break;
}//end for

if (u * u + v * v > 4)
glColor3f(1, 1, 1);
else
glColor3f(0, 0, 1);

glVertex2f(x, y);

glEnd();
glFlush();

Goo luck, and come back if you've got any questions!

Share this post


Link to post
Share on other sites

This topic is 3746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this