MandelBrot

Something math wise~PL C#, Math forums.. nope

Page 1 of 1

4 Replies - 22354 Views - Last Post: 27 September 2007 - 12:43 AM Rate Topic: -----

#1 pinktofu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 18-September 07

MandelBrot

Post icon  Posted 18 September 2007 - 03:46 AM

Posted Image
I am working on the mandelbrot set fractal..
So far I can zoom, render (very fast using bytes), change color scheme...
I am wanting to make the mandelbrot look more.. pretty though, eye candy wise, seeing I have been obsessing with it, over the past few days. (made a viewer in php for god knows why, got tired of waiting 30 seconds to see the image).

Basically, I seen some stuff floating on google image... of the mandelbrot, some of them, seem to be more comlpex looking, I'm unsure if it is the color schemes they use, or not, though I seen some which appear to have alot more fractals then mine seems to have... mines solid colors~ some I seen, appear to have no solid colors..

Like this one for instance : http://www.engarde.c.../mandelbrot.gif

I'm 16, so I'm not incredibly good with math, or spelling for that matter, though, I seem to have a fascination with this mandelbrot, I got the basic formula down... really wanna see what I can get out of it, anyone mind helping me with, example implementation code, of pattern formulas for colors, or.. perhaps links to sites, explain the formula to do such things? Thanks.

-sincerely, PinkTofu.

Is This A Good Question/Topic? 1
  • +

Replies To: MandelBrot

#2 orcasquall   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 158
  • Joined: 14-September 07

Re: MandelBrot

Posted 18 September 2007 - 09:10 AM

Check out the Wikipedia page on Mandelbrot first. Look for the section "Escape time algorithm".

For colouring, you can consider using a colour lookup table. Generate an array of RGB (red, green, blue) values as the lookup table. Using the "escape value" and/or iteration number, map to an index on the lookup table. Then use the colour from the lookup table thus obtained to colour your pixel.

For example, this should come up with something similar to the ice theme you provided.
System.Drawing.Color[] lookup = new System.Drawing.Color[256];
for (int i = 0; i < 256; ++i)
{
	lookup[i] = System.Drawing.Color.FromArgb(0, 255 - i, 255 - i, 255);
}


The lower the index, the whiter the colour. The higher the index, the bluer the colour.

For more complex colouring, you can try interpolating between two colours, such dark blue and red in the other example picture. Actually, the code above is interpolating between pure white and pure blue.

I'm afraid you'll have to get your hands into some math formula. You'll also have to come up with imaginative ideas on populating that lookup table, because there are many ways to do so. Only by testing your lookup table can you see if your generated Mandelbrot looks "nice". Visual beauty is better interpreted by humans than by computers.

As for the different Mandelbrot sets you've seen, you can try using a different seed value, or add an offset to your x and/or y coordinates.

I can help more if I can see the code with which you generated the set.
Was This Post Helpful? 0
  • +
  • -

#3 pinktofu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 18-September 07

Re: MandelBrot

Posted 18 September 2007 - 11:11 AM

			// Begin Drawing the mandelbrot fractal
			x = minx;
			for (s = 0; s < Width; s++)
			{
				y = miny;
				for (z = 0; z < Height; z++)
				{
					int index = (z * this.panel1.Width + s) * 4;
					while (looper < iteration && ((x1 * x1) + (y1 * y1)) < 4)
					{
						looper++;
						xx = (x1 * x1) - (y1 * y1) + x;
						y1 = 2 * (x1 * y1) + y;
						x1 = xx;
					}
					val = (int)((looper / (double)iteration) * 255.0);
					argb[index] = Spectrum[val].B;
					argb[index + 1] = Spectrum[val].G;
					argb[index + 2] = Spectrum[val].R;
					argb[index + 3] = Spectrum[val].A;
					y += intigralY;
				}
				x += intigralX;
			}


is my code so far for generating the fractal, as you can see, the coloring is very simply.
I'll head of the escape time algo, though I'm have trouble understanding it.
Was This Post Helpful? 0
  • +
  • -

#4 orcasquall   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 158
  • Joined: 14-September 07

Re: MandelBrot

Posted 19 September 2007 - 09:34 AM

Basically, the escape condition is the part where
((x1 * x1) + (y1 * y1)) < 4



Once the sum of products is greater than or equal to 4, you "escape", meaning you draw the pixel.

As for colouring, I'm afraid you'll have to study more formulas... The usual method (for more colourful representations) is to get values in HSV (hue, saturation, value [or level]), then transform them into RGB values.

Here's an HSV formula:
H="i/255" where i between 0 and 255 (your Spectrum array indexing)
S=1
V=1
Which should run through the entire gamut of colours, red through yellow through blue.
(assuming the hue representation you're using has a max value of 1)

You can refer to these colour conversions for more info.

Try Googling for colour space too.
Was This Post Helpful? 0
  • +
  • -

#5 keems21   User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 185
  • Joined: 03-February 07

Re: MandelBrot

Posted 27 September 2007 - 12:43 AM

I did a project very similar to this in Java some time ago. This is something along the lines of the color algorithm that I used:
red = (escapeVal % 32) * 7
green = (escapeVal % 16) * 14 
blue = (escapeVal % 128) * 2


I'm pretty sure that this creates a pretty standard madelbrot image. However, you can play around with the mod values and the constants to get whatever color scheme you're looking for.

This post has been edited by keems21: 27 September 2007 - 12:43 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1