multiplicative cascades(ish)
Forum » Game Design / General discussion. » multiplicative cascades(ish)
Started by: droiddroid
On: 1217877122|%e %b %Y, %H:%M %Z|agohover
Number of posts: 3
rss icon RSS: New posts
Summary:
discussion on an algorithm for fractals of arbitrary dimension and (maybe) lacunarity
multiplicative cascades(ish)
droiddroid 1217877122|%e %b %Y, %H:%M %Z|agohover

I was looking at multiplicative cascades and thinking of a method from "the fractal geometry of nature" by BB Mandelbrot. I would like a way of generating a set of points that have a certain dimension and lacunarity, and remember something similar to this in the book. This is the closest I can come up with.

The basic idea is to divide the unit square into a grid and randomly choose squares from it, the probability for each square being determined by dimension d:

(1)
n ^ d/n ^ 2

This is done recursively for each square selected.
The only way of varying the lacunarity that I can remember is to use finer grids per step (n). If anyone has a better way of doing this, let me know.

Also, is there a good definition of lacunarity? I think it was described as proportional to the maximum circle that could fit in the gaps and that doesn't contain any points of the set (averaged across all possible seeds for generating the set).

I would attach an output image (and add it to Fractal to illustrate dimension), but I do not have a flikr account.

Python, with Python Image Library for image stuff:

import random
import math

import PIL.Image
import PIL.ImageFilter

#seed the random generator for repeatable output
seed = 42
rng = random.Random(seed)

def expand(image,
    dimension,
    n_per_level=2):
    '''expand the image by n_per_level, adding detail
    '''

    p_per_pixel = (n_per_level ** dimension)/(n_per_level ** 2)

    #note: using a filter when scaling (such as BILINEAR or BICUBIC) removes
    #       artifacts along division edges, if care is taken the output is seamless and tileable.
    #       for the sake of brevity, these are removed.

    #scale the image
    output = image.resize(
        (image.size[0]*n_per_level,
        image.size[1]*n_per_level))

    #add detail
    pixels = output.load()
    for i in range(output.size[0]):
        for j in range(output.size[1]):
            #black are the points of the set
            value = 1 - pixels[i,j] / 255.
            p = p_per_pixel * value
            if rng.random() < p:
                pixels[i,j] = 0
            else:
                pixels[i,j] = 255.
    return output

#start with one black pixel, greyscale image
image = PIL.Image.new('L',(1,1))

dimension = 1.5

#expand the image 'till it's big enough
while image.size[0] < 1024:
    image = expand(image, dimension)

image.show()
image.save('fractal%d_%d.png' % (dimension*100,seed))
last edited on 1217877197|%e %b %Y, %H:%M %Z|agohover by droid + show more
unfold multiplicative cascades(ish) by droiddroid, 1217877122|%e %b %Y, %H:%M %Z|agohover
Re: multiplicative cascades(ish)
andrewdoullandrewdoull 1220258623|%e %b %Y, %H:%M %Z|agohover

I see you figured out that wikidot does image hosting (to an extent)… thanks for the code.

unfold Re: multiplicative cascades(ish) by andrewdoullandrewdoull, 1220258623|%e %b %Y, %H:%M %Z|agohover
Re: multiplicative cascades(ish)
droiddroid 1243018306|%e %b %Y, %H:%M %Z|agohover

Another image, actually I found it almost a year ago, just havent posted it yet. I was searching for something else, and a typo gave this. Looks kinda cool.
marrowlike

Starting with a black pixel, the following function is applied to each pixel:

#value is the value of the current pixel, 0 to 255
#n_per_level is how many subdivisions per step
#x is a random value between 0 and 1, straight out of the random number generator
def foo(value,n_per_level,x):
    v = value/255.
    if v > 1./n_per_level**2:
        v = 1+math.log(v,4)
        return int(255 * v + .5)
    else:
        return int(255 * x + .5)

The resulting image is then doubled in size (or scaled by n_per_value, that is usually 2) by linear interpolation.

These two steps are repeated until the image is large enough. I cropped the output image to yield my desktop resolution.

unfold Re: multiplicative cascades(ish) by droiddroid, 1243018306|%e %b %Y, %H:%M %Z|agohover
New post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License