<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>simplex noise &#8211; WLGfx</title>
	<atom:link href="https://csnorwood.com/category/simplex-noise/feed/" rel="self" type="application/rss+xml" />
	<link>https://csnorwood.com</link>
	<description>Programmers Website and Blog</description>
	<lastBuildDate>Tue, 30 Jan 2024 16:32:29 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://csnorwood.com/wp-content/uploads/2024/01/cropped-wlgfx-favicon-white-32x32.png</url>
	<title>simplex noise &#8211; WLGfx</title>
	<link>https://csnorwood.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Simplex Noise in Java</title>
		<link>https://csnorwood.com/2017/09/17/simplex-noise-in-java/</link>
		
		<dc:creator><![CDATA[csnorwood]]></dc:creator>
		<pubDate>Sun, 17 Sep 2017 18:11:16 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[simplex noise]]></category>
		<guid isPermaLink="false">http://wlgfx.com/?p=276</guid>

					<description><![CDATA[Well, I finally got round to testing out the noise algorithms again. And this time in Java. I grabbed OpenSimplexNoise class and had to add my own functions to it so that I could use &#8216;octaves&#8217; and &#8216;persistence&#8217; values to add roughness to it. The extra functions which handle 2D and 3D noise are: public [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Well, I finally got round to testing out the noise algorithms again. And this time in Java.</p>
<p>I grabbed <a href="https://gist.github.com/KdotJPG/b1270127455a94ac5d19">OpenSimplexNoise</a> class and had to add my own functions to it so that I could use &#8216;octaves&#8217; and &#8216;persistence&#8217; values to add roughness to it. The extra functions which handle 2D and 3D noise are:</p>
<pre style="background-color: #000; color: #cc0; font-size: 12px;">    public double OctavePerlin2(double x, double y, int octaves, double persistence) {
        double total = 0;
        double frequency = 1;
        double amplitude = 1;
        double maxValue = 0;  // Used for normalizing result to 0.0 - 1.0
        for(int i=0;i&lt;octaves;i++) {
            total += eval(x * frequency, y * frequency) * amplitude;

            maxValue += amplitude;

            amplitude *= persistence;
            frequency *= 2;
        }

        return total/maxValue;
    }
    
    public double OctavePerlin3(double x, double y, double z, int octaves, double persistence) {
        double total = 0;
        double frequency = 1;
        double amplitude = 1;
        double maxValue = 0;  // Used for normalizing result to 0.0 - 1.0
        for(int i=0;i&lt;octaves;i++) {
            total += eval(x * frequency, y * frequency, z * frequency) * amplitude;

            maxValue += amplitude;

            amplitude *= persistence;
            frequency *= 2;
        }

        return total/maxValue;
    }</pre>
<p>Then I added a UI using Swing and got it all working including adding a water level.</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-280" src="http://csnorwood.com/wp-content/uploads/2017/09/perlinnoisejava.png" alt="" width="776" height="562" srcset="https://csnorwood.com/wp-content/uploads/2017/09/perlinnoisejava.png 776w, https://csnorwood.com/wp-content/uploads/2017/09/perlinnoisejava-300x217.png 300w, https://csnorwood.com/wp-content/uploads/2017/09/perlinnoisejava-768x556.png 768w" sizes="(max-width: 776px) 100vw, 776px" /></p>
<p>[ADDED] And a better image:</p>
<p><img decoding="async" class="alignnone size-full wp-image-283" src="http://csnorwood.com/wp-content/uploads/2017/09/perlinnoisejava2.png" alt="" width="778" height="561" srcset="https://csnorwood.com/wp-content/uploads/2017/09/perlinnoisejava2.png 778w, https://csnorwood.com/wp-content/uploads/2017/09/perlinnoisejava2-300x216.png 300w, https://csnorwood.com/wp-content/uploads/2017/09/perlinnoisejava2-768x554.png 768w" sizes="(max-width: 778px) 100vw, 778px" /></p>
<p>All I need now is to break up the calculations into blocks and run each block on its own thread when I come to using this again.</p>
<p>The class which creates the bitmap:</p>
<pre style="background-color: #000; color: #cc0; font-size: 12px;">public class BufferedImageNoise {
    
    int w, h;
    long seed;
    double scale;
    
    int off_x, off_y;
    
    int octaves;
    double persistence;
    
    double water;
    
    OpenSimplexNoise noise;
    
    public BufferedImageNoise(int width, int height, long seed, double scale, int octaves, double persistence, double water) {
        w = width; h = height;
        this.seed = seed;
        this.scale = scale;
        this.octaves = octaves;
        this.persistence = persistence;
        this.water = water;
        
        off_x = off_y = 0;
        
        noise = new OpenSimplexNoise(seed);
    }
    
    public BufferedImage getImage() {
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        for (int y = 0; y &amp;lt h; y++)
        {
            for (int x = 0; x &amp;lt w; x++)
            {
                double value = noise.OctavePerlin2(x / scale, y / scale, octaves, persistence) + 1.3;
                
                int rgb = value &amp;gt water ? 0x010101 * (int)((value) * 127.5) : 0x000088;
                image.setRGB(x, y, rgb);
            }
        }
        return image;
    }
}</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
