Smooth Noise Function [java]

It’s a fairly slow function, but it’s better than the one built into Processing.org. The functions which I don’t define are mostly in the Math library (they’re redefined like that by Processing). ‘dist’ is Euclidean distance.

int seed; //Seed for the noise. It seems that very similar seeds have very similar results.
float rr(int x,int y,int b) {
Random k = new Random(x + y*13337 + seed);
int a = 0;
while (a < b+2){
k.nextFloat(); a++;
}
return k.nextFloat();
}
int noiq = 4;//Quality of noise. Higher is slower and shouldn't have rips.
float noi(float a,float b) { //x,y positions of noise. Returns a number between 0 and 1,symmetric about 0.5.
int u = (int)floor(a-noiq);
int ut = u + noiq*2;
float s = 0;
float w = 0;
while (u < ut) {
int v = (int)floor(b-noiq);
int vt = v + noiq*2;
while (v < vt) {
float m = dist(a,b,(float)u + rr(u,v,1),(float)v + rr(u,v,2));
float j = pow(0.2,m*2);
w = w + j;
s = s + j * rr(u,v,0);
v++;
}
u++;
}
return s/w;
}

Comments

19. Aug 2012 · 16:24 UTC
What exactly does it do?
29. Aug 2012 · 03:00 UTC
Really nice for land generation as my test app shows. :) It”s much better then the perlin noise function (noise) built into Processing. Good job!