C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 300,495 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,843 people online right now. Registration is fast and FREE... Join Now!




MandelBrot

 

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

pinktofu

18 Sep, 2007 - 02:46 AM
Post #1

New D.I.C Head
*

Joined: 18 Sep, 2007
Posts: 2


My Contributions
IPB 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.com/~dmn/diana/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.

User is offlineProfile CardPM
+Quote Post


orcasquall

RE: MandelBrot

18 Sep, 2007 - 08:10 AM
Post #2

D.I.C Head
Group Icon

Joined: 14 Sep, 2007
Posts: 158



Thanked: 10 times
Dream Kudos: 50
My Contributions
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.
CODE

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.
User is offlineProfile CardPM
+Quote Post

pinktofu

RE: MandelBrot

18 Sep, 2007 - 10:11 AM
Post #3

New D.I.C Head
*

Joined: 18 Sep, 2007
Posts: 2


My Contributions
CODE

            // 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.
User is offlineProfile CardPM
+Quote Post

orcasquall

RE: MandelBrot

19 Sep, 2007 - 08:34 AM
Post #4

D.I.C Head
Group Icon

Joined: 14 Sep, 2007
Posts: 158



Thanked: 10 times
Dream Kudos: 50
My Contributions
Basically, the escape condition is the part where
CODE

((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.
User is offlineProfile CardPM
+Quote Post

keems21

RE: MandelBrot

26 Sep, 2007 - 11:43 PM
Post #5

D.I.C Head
Group Icon

Joined: 3 Feb, 2007
Posts: 184



Thanked: 3 times
Dream Kudos: 25
My Contributions
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:
CODE

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: 26 Sep, 2007 - 11:43 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:49AM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month