Note that there are some explanatory texts on larger screens.

plurals
  1. POSoftware Perlin noise implementation
    primarykey
    data
    text
    <p>I have written a 2D Perlin noise implementation based on information from <a href="http://www.dreamincode.net/forums/topic/66480-perlin-noise/" rel="nofollow">here</a>, <a href="http://freespace.virgin.net/hugo.elias/models/m_perlin.htm" rel="nofollow">here</a>, <a href="http://www.codeproject.com/KB/recipes/SimpleRNG.aspx" rel="nofollow">here</a>, and <a href="http://mrl.nyu.edu/~perlin/doc/oscar.html#noise" rel="nofollow">here</a>. However, the output looks like <a href="http://dl.dropbox.com/u/14021598/Output.png" rel="nofollow">this</a>.</p> <pre><code>public static double Perlin(double X, double XScale, double Y, double YScale, double Persistance, double Octaves) { double total=0.0; for(int i=0;i&lt;Octaves;i++){ int frq = (int) Math.Pow(2,i); int amp = (int) Math.Pow(Persistance,i); total += InterpolatedSmoothNoise((X / XScale) * frq, (Y / YScale) * frq) * amp; } return total; } private static double InterpolatedSmoothNoise (double X, double Y) { int ix = (int) Math.Floor(X); double fx = X-ix; int iy = (int) Math.Floor(Y); double fy = Y-iy; double v1 = SmoothPerlin(ix,iy); // -- double v2 = SmoothPerlin(ix+1,iy); // +- double v3 = SmoothPerlin(ix,iy+1);// -+ double v4 = SmoothPerlin(ix+1,iy+1);// ++ double i1 = Interpolate(v1,v2,fx); double i2 = Interpolate(v3,v4,fx); return Interpolate(i1,i2,fy); } private static double SmoothPerlin (int X, int Y) { double sides=(Noise(X-1,Y,Z)+Noise(X+1,Y,Z)+Noise(X,Y-1,Z)+Noise(X,Y+1,Z)+Noise(X,Y,Z-1)+Noise(X,Y,Z+1))/12.0; double center=Noise(X,Y,Z)/2.0; return sides + center; } private static double Noise (int X, int Y) { uint m_z = (uint) (36969 * (X &amp; 65535) + (X &gt;&gt; 16)); uint m_w = (uint) (18000 * (Y &amp; 65535) + (Y &gt;&gt; 16)); uint ou = (m_z &lt;&lt; 16) + m_w; return ((ou + 1.0) * 2.328306435454494e-10); } </code></pre> <p>Any input on what is wrong is appreciated.</p> <p>EDIT: I found a way to solve this: I used an array of doubles generated at load to fix this. Any way to implement a good random number generator is appreciated though.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload