<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>General discussion. (new threads)</title>
		<link>http://pcg.wikidot.com/forum/c-42082/general-discussion</link>
		<description>Threads in the forum category &quot;General discussion.&quot; - General discussion about game development and PCG techniques.</description>
				<copyright></copyright>
		<lastBuildDate></lastBuildDate>
		
					<item>
				<guid>http://pcg.wikidot.com/forum/t-79282</guid>
				<title>multiplicative cascades(ish)</title>
				<link>http://pcg.wikidot.com/forum/t-79282/multiplicative-cascades-ish</link>
				<description>discussion on an algorithm for fractals of arbitrary dimension and (maybe) lacunarity</description>
				<pubDate>Mon, 04 Aug 2008 19:12:02 +0000</pubDate>
				<wikidot:authorName>droid</wikidot:authorName>				<wikidot:authorUserId>171383</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I was looking at <a href="http://en.wikipedia.org/wiki/Multiplicative_Cascade">multiplicative cascades</a> 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.</p> <p>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:</p> <span class="equation-number">(1)</span> <div class="math-equation" id="equation-20572-1"><img src="http://pcg.wikidot.com/local--math/eqs/b960ad52009967a56d56c5805db91ca2.png" alt="n ^ d/n ^ 2" /></div> <p>This is done recursively for each square selected.<br /> 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.</p> <p>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).</p> <p>I would attach an output image (and add it to <a href="http://pcg.wikidot.com/pcg-algorithm:fractal">Fractal</a> to illustrate dimension), but I do not have a flikr account.</p> <p>Python, with <a href="http://www.pythonware.com/library/pil/handbook/image.htm">Python Image Library</a> for image stuff:</p> <div class="code"> <pre> <code>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() &lt; 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] &lt; 1024: image = expand(image, dimension) image.show() image.save('fractal%d_%d.png' % (dimension*100,seed))</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>