Page 1 of 1

Mandelbrot / Fractals in 6502?

Posted: Fri Aug 10, 2007 9:54 am
by ccovell
Hi, folks. I'm a bit interested in making a program that'll calculate the Mandelbrot set, but I don't want to reinvent the wheel. Does anybody have any links to 6502/6510 ASM code for generating this fractal?

I've already done quite the search through Google and 6502.org and while there is plenty of theory and floating-point C code to be found, there are very few usable code examples for an 8-bit 6502.

Help!?

Re: Mandelbrot / Fractals in 6502?

Posted: Wed Aug 15, 2007 4:55 pm
by Josh
ccovell wrote:Hi, folks. I'm a bit interested in making a program that'll calculate the Mandelbrot set, but I don't want to reinvent the wheel. Does anybody have any links to 6502/6510 ASM code for generating this fractal?

I've already done quite the search through Google and 6502.org and while there is plenty of theory and floating-point C code to be found, there are very few usable code examples for an 8-bit 6502.

Help!?
Your best bet is to do a search for Commodore 64 programs that do this. Virtually everything that could be done with a 6502 processor was done on a C64 at some time or another by someone. The June 1988 issue of COMPUTE!'s Gazette had a type-in program called "Eight Thousand Dragons," which did Mandelbrot graphics. Sadly, source code was not included.

The Sep. 1985 issue of COMPUTE! Magazine has an article on "Apple Fractals," which would have been done on a 6502-based system. Again, there probably isn't source code, though the article may contain some useful information.

Posted: Thu Aug 16, 2007 12:41 am
by ccovell
Thanks for the reply. Since nobody answered in good time, I bit the bullet and did some research, checking out examples in BASIC and C. After a bit of thinking and coding, I made up a nice working Mandelbrot generator in 6502 ASM. But sorry NES fans, my program is for the 7.16 Mhz PC-Engine, because the NES' CPU just isn't fast enough to render some nice fractals without my falling asleep... :-)

I'll update this post when I've finished up the PCE program, since somebody might be interested.

Posted: Sat Aug 25, 2007 10:14 am
by ccovell
OK, an updated post. Double-post, yay!

I finished up my mandelbrot program on the PC-E, and called it Fractal Engine. You can check it out here:
http://www.disgruntleddesigner.com/chri ... ngine.html

Image

Image

Posted: Sat Aug 25, 2007 5:44 pm
by doppelganger
Wow, that looks like a pretty good program considering what it does. Just a couple of questions:

In the second screenshot of the entire Mandelbrot set, how were the axes oriented? In FRACTINT I believe the X-axis (for real values) points to the right, thus causing the Mandelbrot to "point" to the left towards negative values.

And, do you think you'll ever try implementing Julia sets?

Posted: Sat Aug 25, 2007 6:05 pm
by tokumaru
It would be nice to see that on the NES, even if you had to wait a whole night to see anything interesting! =)

Posted: Sat Aug 25, 2007 6:10 pm
by Dwedit
I've used an Applesoft Basic fractal generator, and it took about an hour to run on an Apple ][ C+. I have no doubt an ASM based generator would be much faster on a NES.

Posted: Mon Aug 27, 2007 1:11 am
by ccovell
doppelganger wrote:Wow, that looks like a pretty good program considering what it does. Just a couple of questions:

In the second screenshot of the entire Mandelbrot set, how were the axes oriented? In FRACTINT I believe the X-axis (for real values) points to the right, thus causing the Mandelbrot to "point" to the left towards negative values.

And, do you think you'll ever try implementing Julia sets?
Yes, read the readme; it admits that the Mandelbrot is flipped horizontally just to make the inside iterations as simple and speedy as possible.

I was thinking about putting in Julias, but I never found an easy-to-understand explanation anywhere that said just HOW rendering a Julia set is different from a Mandelbrot set.

Posted: Mon Aug 27, 2007 4:47 am
by tepples
Wikipedia states that Julia sets are rendered with repeated applications of square roots.

Posted: Mon Aug 27, 2007 7:15 pm
by kingshriek
Julia sets and Mandelbrot sets are calculated with the same recurrence relation

z[n+1] = z[n]^2 + c

For the Mandlebrot set, z[0] = 0 and c varies over the entire complex plane.

For Julia sets, a specific complex value c is selected, and z[0] varies over the entire complex plane.

Posted: Mon Aug 27, 2007 7:20 pm
by doppelganger
The Mandelbrot and Julia sets use the same formula, but they use C differently.

The Mandelbrot set use the current complex number (where the pixel coordinates are) for the value of C on every iteration, thus it changes on every pixel.

Julia sets use one fixed complex number for the value of C on every iteration, thus it remains fixed. The fixed complex number is supposed to be assigned before rendering the Julia set.

Since Julia sets use a fixed point and the Mandelbrot set uses every point, it can be said that the Mandelbrot set is an index to every possible Julia set. I will even go so far as to say the Mandelbrot set *is* every Julia set mashed up together in one fractal universe.

Posted: Mon Aug 27, 2007 8:19 pm
by tepples
doppelganger wrote:Since Julia sets use a fixed point and the Mandelbrot set uses every point, it can be said that the Mandelbrot set is an index to every possible Julia set. I will even go so far as to say the Mandelbrot set *is* every Julia set mashed up together in one fractal universe.
You'd be correct. The Mandelbrot set was invented as a way to test conjectures about the set of Julia sets. Wikipedia states that "it is the subset of the complex plane consisting of those parameters c for which the Julia set of fc is connected."