Plasma Fractal Notes

One of the simplest fractals out there is the plasma fractal, an easy-to-generate random "noisy image" that looks something like this:

This effect is rendered by the "Clouds" and "Difference Clouds" filters in Photoshop or the GIMP. It's a fractal with a simple recursive definition, where to draw a plasma fractal in a box you perturb the box's edges and center slightly; then recursively draw plasma fractals in each 4 smaller boxes.

void plasma(int l,int r,int b,int t,//Coordinates of left, right, top, bottom
        Pixel bl,Pixel br,Pixel tl,Pixel tr,//Image values at corners
        Random *R)
        if ((l+1>=r)||(b+1>=t)) return;//We're now a single pixel

        int h=(l+r)/2,v=(t+b)/2;//Coordinates of center
        int hlen=r-h,vlen=t-v;
        //Compute perturbed Colors of Rectangle edge midpoints
        Pixel vl=R->perturb        ((tl+bl)/2,l,v,vlen);
        Pixel vr=R->perturb_nowrite((tr+br)/2,r,v,vlen);
        Pixel bh=R->perturb        ((bl+br)/2,h,b,hlen);
        Pixel th=R->perturb_nowrite((tl+tr)/2,h,t,hlen);
        //Compute Color of dead center via averaging
        Pixel vh=R->perturb((vl+vr)/2,h,v,int((vlen+hlen)*0.707));
        //Recurse on sub-rectangles (top left, top right, bottom left, bottom right)
        plasma(l,h,  v,t, vl,vh,   tl,th,    R);
        plasma(  h,r,v,t,    vh,vr,   th,tr, R);
        plasma(l,h,  b,v, bl,bh,   vl,vh,    R);
        plasma(  h,r,b,v,    bh,br,   vh,vr, R);

As the boxes get smaller and smaller, your perturbation normally shrinks as well--this makes the image look rough from far away, but fairly smooth up close. The GIMP even lets you control the perturbation falloff as a function of scale, but it's only got one slider so it uses a power law to relate the perturbation to the size.

In general, you can set the perturbation to be any function of the scale you like.

A perfectly flat image-- no randomness.

More perturbation at large scales than at small leads to a "natural looking" image. This is just the power law with power=1.0.

A large fixed amount of perturbation leads to tons of noise at all scales.

Perturbation only at small scales removes the undulation completely.

Perturbation only at large scales shows only undulation. Since below a certain size there's no perturbation, this is exactly like doing a bilinear interpolation of a smaller plasma fractal.

perturb=((len>=10) && (len<20))?100:0
Perturbation only at medium scales--no undulation, but no fine noise.

The most popular perturbation function is a simple power law: "perturb=pow(len,k)", where k is a constant typically between 0 and 10. I've created an animation (MPEG, 90KB) where k slowly increases from 0 to 2.5; in this movie, noise starts out at the low frequencies and slowly moves to higher and higher frequencies.

Finally, note that the above images show exactly the same random noise, no matter what perturbation function is used. It's normally quite easy to generate the exact same pseudorandom number stream from the same seed, and doing so allows you to clearly separate out the effects of the (deterministic) scale factor from the random choices. Sadly, the otherwise excellent "Render Clouds" plasma filter on the GIMP somehow manages to generate different random numbers for different scale factors, confusing the two issues.

Back to Orion's Oeuvre.
Back to Orion's Home Page.