hmmmmmm, That solution is even worse really. Basically, I'm trying to draw a Mandelbrot set. And I need to plot a few hundred thousand points, after testing them to see if they satisfy:

P[^n](0) -/-> infinity as n->infinity, where P(z)=z^2+c, and c is the point (x,y)=x+iy.

I think g.drawLine(x,y,x,y) will be quicker than filling in an oval.

I'm shocked that java wont let you plot a point. Why isn't there a method plotPoint(x,y) or something???

Colin, to help other folks who might be following this discussion, it's best to keep your reply in the original thread. When I first started reading your thread, it starts right in with "That solution is even worse", but I didn't know what "that solution" was.

That said, here we are now, and you're trying to plot points with Java Swing/AWT. I'm about to be trying the same thing. What Ryan suggests is all I can find for the moment, so that's what I'm going to try soon too.

If it works out for you, please post some sample code for us.

I've done a bit of fractal drawing using the BufferedImage method setRGB(), doing and after the iteration is done draw it onscreen with Graphics.drawImage().

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1024

4

posted

0

Originally posted by colin shuker: Basically, I'm trying to draw a Mandelbrot set. And I need to plot a few hundred thousand points, after testing them to see if they satisfy:

P[^n](0) -/-> infinity as n->infinity, where P(z)=z^2+c, and c is the point (x,y)=x+iy.

Would this be a reasonable forum to discuss (language independent) Mandlebrot Set program issues? I could ramble on for hours.

I'm shocked that java wont let you plot a point. Why isn't there a method plotPoint(x,y) or something???

One reason may be that in Java 2D, points are infinitely small. They have no spatial extent. A *range* of points, however, can be rendered, such as a line, or a rectangle.

Just my quick 2 cents. [ June 25, 2005: Message edited by: Rob Ross ]

Rob
SCJP 1.4

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1024

4

posted

0

Originally posted by Rob Ross:

One reason may be that in Java 2D, points are infinitely small. They have no spatial extent. A *range* of points, however, can be rendered, such as a line, or a rectangle.

But lines are infinitely narrow, so you shouldn't be able to see them either. You should need some type of area fill before you can see anything.

(I'm not saying you're wrong, just that Java is goofy.)

Please feel free to ramble. Do you know of any tutorials or other useful information about interesting ways to color the image? Everything I find on the net is apparently either over my head or badly explained. Any suggestions?

Can't pass up tooting my own horn: at http://www.ulfdittmer.com/simplemandel/index.html is an applet (with source code) that draws the Mandelbrot set for various exponents, and lets you zoom in and out. It has 12 built-in colors (the ones from java.awt.Color), but you can change those to any color sequence you like.

I like it. I especially like the optimation you made where you draw the outline of a rectangle first to see if all the border values are to be drawn black and then filling in the iterior if it is. I think I'm going to "steal" that for my version.

Originally posted by Ulf Dittmer: Can't pass up tooting my own horn: at http://www.ulfdittmer.com/simplemandel/index.html is an applet (with source code) that draws the Mandelbrot set for various exponents, and lets you zoom in and out. It has 12 built-in colors (the ones from java.awt.Color), but you can change those to any color sequence you like.

I like it. Especially the optimizations as Ryan pointed out. My previous attempts at drawing the Mandlebrot set were much slower, mostly because I calculated each pixel rather than trying to come up with some scheme to draw a bounding rectangle.

So is it always true that if all the points along the border of a bounding rectangle converge then all the points on the interior also converge? Has this been proved mathematically?

So is it always true that if all the points along the border of a bounding rectangle converge then all the points on the interior also converge? Has this been proved mathematically?

Well, according to this page, the Mandelbrot Set is simply connected. I don't have the math to understand the argument for it, but it should be enough to answer your first question in the affirmative.

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1024

4

posted

0

Originally posted by Timmy Marks:

Well, according to this page, the Mandelbrot Set is simply connected.

Yes but... Now that I think about it, Ulfs code doesn't really check the entire border. It merely checks the border points at the pixel locations. A non-trivial "finger" of non-converging points might squeeze into the rectangle between two border points that get calculated as convergers.

I guess that makes the "rectangle trick" a "heuristic" instead of an "optimization".

Ryan

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1024

4

posted

0

Originally posted by Timmy Marks:

Please feel free to ramble.

Ok, you asked for it.

Since both c and z are complex numbers the function to determine what color to draw each pixel is a four-paramter function: public Color colorForPoint(double zReal, double zImag, double cReal, double cImag) Or you could say that colorForPoint() defines a function in 4D space. It's just that for Mandlebrot set, you're rendering the 2D slice of that 4D space where zReal=0 and zImag=0.

When you hold cReal=0 and cImag=0 and vary z, you end up with what's called a Julia set.

What if you included a way to render ANY 2D slice through that 4D space? You could get some seriously funky pictures. My first shot at this (written in C back in the '80s some time) allowed you pick two of the paramters to hold constant, the constant values for those two and the limits for the other two (varying) variables. So the setup for a Mandlebrot set would be something like (zReal, 0, zImag, 0, cReal, -2, 2, cImag, -2, 2)

BUT... A way that would be even more flexible to define your favorite slice through 4 space would be to use a matrix to define a couple parametric equations to tell what 4-space point corresponds to each 2-space pixel. Since all the relationships are linear, coming up with the matrix coefficients shouldn't be too hard.

Example (mandlebrot): Your image coordinates are 0<=X<=100 and 0<=Y<=100. You want (0,0) to show colorForPoint(0, 0, -1, 1). (100, 0) ==> (0, 0, 1, 1). (0, 100) ==> (0, 0, -1, -1). Apply a little linear algebra and we find that zReal = 0X + 0Y + 0; zImag = 0X + 0Y + 0; cReal = .02X + 0Y - 1; cImag = 0X - .02Y + 1.

In matrix form, that's

The only piece I'm missing is an intuitively obvious user interface that allows the user to specify the parameters using simple mouse/keyboard gestures. Dragging on one image to zoom in on a specific section is obvious, but what gestures could be used to rotate the image plane into/out of the current plane? ...especially when there are TWO other dimensions to rotate through? I'm working on some custom Swing widgets for it.

If anyone sees any problem with my math, please let me know.

Ryan [ July 11, 2005: Message edited by: Ryan McGuire ]