<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Generating 2D random fractal terrains with F#</title>
	<atom:link href="http://www.bugfree.dk/blog/2009/03/06/generating-2d-random-fractal-terrains-with-f/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bugfree.dk/blog/2009/03/06/generating-2d-random-fractal-terrains-with-f/</link>
	<description>Not anti-anything, just pro-quality</description>
	<lastBuildDate>Thu, 16 Dec 2010 07:18:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Bugfree.dk &#187; Blog Archive &#187; 2009 in retrospect</title>
		<link>http://www.bugfree.dk/blog/2009/03/06/generating-2d-random-fractal-terrains-with-f/comment-page-1/#comment-22121</link>
		<dc:creator>Bugfree.dk &#187; Blog Archive &#187; 2009 in retrospect</dc:creator>
		<pubDate>Mon, 28 Dec 2009 11:33:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.bugfree.dk/blog/2009/03/06/generating-2d-random-fractal-terrains-with-f/#comment-22121</guid>
		<description>[...] started to permeate C#, my language of choice. I learned a great deal about LINQ, about F# when I generated fractal terrains, about XSL when I had to jump through functional loops, and generally reading about functional [...]</description>
		<content:encoded><![CDATA[<p>[...] started to permeate C#, my language of choice. I learned a great deal about LINQ, about F# when I generated fractal terrains, about XSL when I had to jump through functional loops, and generally reading about functional [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bob</title>
		<link>http://www.bugfree.dk/blog/2009/03/06/generating-2d-random-fractal-terrains-with-f/comment-page-1/#comment-16398</link>
		<dc:creator>bob</dc:creator>
		<pubDate>Thu, 16 Jul 2009 13:26:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.bugfree.dk/blog/2009/03/06/generating-2d-random-fractal-terrains-with-f/#comment-16398</guid>
		<description>Here&#039;s one that doesn&#039;t build a list in memory:

    private const float MinDisplacement = 0.01f;

    public void Generate(float y1, float y2, float displace, Action callback)
    {
        if (displace == 1.0f) callback(y1);

        // subdivide
        if (displace &gt;= MinDisplacement)
        {
            // pick a random midpoint
            float midpoint = Average(y1, y2) + Random(displace);

            Generate(y1, midpoint, displace / 2.0f, callback);
            callback(midpoint);
            Generate(midpoint, y2, displace / 2.0f, callback);
        }

        if (displace == 1.0f) callback(y2);
    }

    float Average(float a, float b) { return (a + b) / 2.0f; }

    // get a random value between -scale and scale
    private Random _rand = new Random();
    float Random(float scale)
    {
        return (float)(_rand.NextDouble() - 0.5f) * scale;
    }</description>
		<content:encoded><![CDATA[<p>Here&#8217;s one that doesn&#8217;t build a list in memory:</p>
<p>    private const float MinDisplacement = 0.01f;</p>
<p>    public void Generate(float y1, float y2, float displace, Action callback)<br />
    {<br />
        if (displace == 1.0f) callback(y1);</p>
<p>        // subdivide<br />
        if (displace &gt;= MinDisplacement)<br />
        {<br />
            // pick a random midpoint<br />
            float midpoint = Average(y1, y2) + Random(displace);</p>
<p>            Generate(y1, midpoint, displace / 2.0f, callback);<br />
            callback(midpoint);<br />
            Generate(midpoint, y2, displace / 2.0f, callback);<br />
        }</p>
<p>        if (displace == 1.0f) callback(y2);<br />
    }</p>
<p>    float Average(float a, float b) { return (a + b) / 2.0f; }</p>
<p>    // get a random value between -scale and scale<br />
    private Random _rand = new Random();<br />
    float Random(float scale)<br />
    {<br />
        return (float)(_rand.NextDouble() &#8211; 0.5f) * scale;<br />
    }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

