Jump to content
• Advertisement

Public Group

# Help with Mandelbrot Ser

This topic is 4111 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

##### Share on other sites
Advertisement
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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5
• Advertisement

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633758
• Total Posts
3013712
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!