Mandelbrot Set Project
Mandelbrot set Project
The Mandelbrot Set is a fractal object that exists on the complex number
plane. The Mandelbrot set has an inside and an outside. It is the boundary
between the inside and the outside that's the fractal.
A complex number is a number that has two components, a real part and an
imaginary part. Complex number are used for things like giving square roots
of negative numbers. I'm not a math teacher and I'm not sure of the best way
of approaching complex numbers here. Let's try this.
Expression Real Number Complex number
(Real Part,
Imaginary part)
a=1 1 (1,0*i)
a=-1 -1 (-1, 0*i)
a=square root(1) 1 (1, 0*i)
a=square root(-1) na (0, 1*i)
"i" above is defined to be the square root of negative 1.
The numbers that we are used to, integers and real numbers, make a number
line. ie: the set of all reals form a line. The set of all complex numbers
defines a plane, because the complex numbers each have two components. So
you can think of your computer screen as a window onto the complex number
plane, with the coordinates of each pixel representing the components of a
complex number. So, pixel (x,y) would be represent the complex number (x,
y*i).
Arithmatic with complex numbers is a bit complicated (surprise) and I won't
go into it now. Look for a followup posting dealing with that.
The Mandelbrot Set is not drawn so much as it's detected. You look at a
pixel and ask of it - Is this pixel in the Mandelbrot Set? If it is within
the set, you colour it one way, if it's not, you colour it another way.
So you set up a loop that asks that question of every pixel on the screen.
ie:
For x = 1 to ScreenWidth
for y = 1 to ScreenHeight
Check_Pixel_for_Mandness(x,y)
if Pixel is in Mandelbrot Set
Colour it one way
else
Colour it another way
next y
next x
end
Checking whether a pixel is inside or outside the Mandelbrot set is an
interesting process.
First we create a "constant" such that constant=(x,y)= pixel coordinates
The Mandelbrot Set Detector works like this
Maximum=500
z=(1,1)
c=(x,y)
counter=0
while x < (2,2) or counter>Maximum
counter = counter + 1
z = z*z + c
end while
end
Now if the pixel you are looking at is inside the Set, then this loop will
be infinite, and so you have to have the escape clause that gets out of the
loop if the value of counter goes over a maximum. If at the end of the test
your count is => than the maximum, then the pixel is inside the set and you
colour it one way. If the count is < maximum, then the pixel was outside the
set and you should colour it another way that is dependant on what the count
was.
I'm a bit rusty - but I think that the above detects the Mandelbrot Set. If
you put your pixel coordinates into z to start, and just make c a constant,
then I think you detect the Julia Set, which is closely related. Even if you
make a mistake in the way you set your system up, you often get some kind of
interesting fractal, even if it isn't the genuine Mandelbrot set.
Anyway - that's the start. A bit of a Math appendix will follow. I think
Euphoria has a library that will do the complex math, but I haven't worked
with that stuff yet - I've always just written the few functions I've needed
from scratch.
Bye
Martin
Martin Hunt - simulat at intergate.bc.ca
|
Not Categorized, Please Help
|
|