{"author_name":"BlueShaman","cat":"LD #24","comments":[{"author_name":"","time":"August 19, 2012 11:24 am","epoch":1345393440,"text":"What exactly does it do?","spam":"N"},{"author_name":"","time":"August 28, 2012 10:00 pm","epoch":1346209200,"text":"Really nice for land generation as my test app shows. <img src=\"http:\/\/ludumdare.com\/compo\/wp-includes\/images\/smilies\/simple-smile.png\" alt=\":)\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> It&#8221;s much better then the perlin noise function (noise) built into Processing. Good job!","spam":"N"}],"epoch":1345388340,"likes":3,"metadata":{"p_key":"55274","p_author":"BlueShaman","p_authorkey":"4891","p_urlkey":"90992","p_title":"Smooth Noise Function [java]","p_cat":"LD #24","p_event":"LD24","p_time":"1345388340","p_likes":"3","p_comments":"2","p_status":"UPD5","us_key":"4891","us_name":"BlueShaman","us_username":"blueshaman","event_start":"1345766400","event_key":"12","event_name":"LD24"},"text":"<p>It&#8217;s a fairly slow function, but it&#8217;s better than the one built into Processing.org. The functions which I don&#8217;t define are mostly in the Math library (they&#8217;re redefined like that by Processing). &#8216;dist&#8217; is Euclidean distance.<\/p>\n <pre>int seed; \/\/Seed for the noise. It seems that very similar seeds have very similar results.<\/pre>\n <pre>float rr(int x,int y,int b) {<\/pre>\n <pre>Random k = new Random(x + y*13337 + seed);<\/pre>\n <pre>int a = 0;<\/pre>\n <pre>while (a &lt; b+2){<\/pre>\n <pre>k.nextFloat(); a++;<\/pre>\n <pre>}<\/pre>\n <pre>return k.nextFloat();<\/pre>\n <pre>}<\/pre>\n <pre>int noiq = 4;\/\/Quality of noise. Higher is slower and shouldn't have rips.<\/pre>\n <pre>float noi(float a,float b) { \/\/x,y positions of noise. Returns a number between 0 and 1,symmetric about 0.5.<\/pre>\n <pre>int u = (int)floor(a-noiq);<\/pre>\n <pre>int ut = u + noiq*2;<\/pre>\n <pre>float s = 0;<\/pre>\n <pre>float w = 0;<\/pre>\n <pre>while (u &lt; ut) {<\/pre>\n <pre>int v = (int)floor(b-noiq);<\/pre>\n <pre>int vt = v + noiq*2;<\/pre>\n <pre>while (v &lt; vt) {<\/pre>\n <pre>float m = dist(a,b,(float)u + rr(u,v,1),(float)v + rr(u,v,2));<\/pre>\n <pre>float j = pow(0.2,m*2);<\/pre>\n <pre>w = w + j;<\/pre>\n <pre>s = s + j * rr(u,v,0);<\/pre>\n <pre>v++;<\/pre>\n <pre>}<\/pre>\n <pre>u++;<\/pre>\n <pre>}<\/pre>\n <pre>return s\/w;<\/pre>\n <pre>}<\/pre>","time":"August 19th, 2012 9:59 am","title":"Smooth Noise Function [java]"}