Arrow keys to rotate/tilt, +/- zoom, w wireframe
The map is 100x100 units.
Java source code;
static float lacunarity=1;
static float gain=1;
static float offset=1;
static int numberOfOctaves=3;
static float hScale=0.5f;
static float vScale=0.5f;
public static float ridgedMF(double x, double z)
{
double sum = 0;
float amplitude = 0.5f;
float frequency = 1.0f;
double prev = 1.0f;
int octaves=numberOfOctaves;
x*=hScale;
z*=hScale;
for (int i = 0; i < octaves; i++)
{
double n = ridge(interpolatedNoise((float)(x*frequency),(float)(z*frequency)), offset);
sum += n * amplitude * prev;
prev = n;
frequency *= lacunarity;
amplitude *= gain;
}
return (float)-sum*vScale;
}
public static double ridge(double h, float offset)
{
h = Math.abs(h);
h = offset - h;
h = h * h;
return h;
}
public static float noise(int x, int y)
{
int n=x+y*57;
n=(n<<13)^n;
return (1.0f-((n*(n*n*15731+789221)+1376312589)&0x7fffffff)/1073741824f);
}
private static float interpolatedNoise(float x, float y)
{
int integer_X=(int)x;
float fractional_X = x-integer_X;
int integer_Y=(int)y;
float fractional_Y=y-integer_Y;
float v1 = noise(integer_X,integer_Y);
float v2 = noise(integer_X+1,integer_Y);
float v3 = noise(integer_X,integer_Y+1);
float v4 = noise(integer_X+1,integer_Y+1);
float i1=interpolate(v1,v2,fractional_X);
float i2=interpolate(v3,v4,fractional_X);
return interpolate(i1,i2,fractional_Y);
}
private static float interpolate(float a, float b, float x)
{
// linear
// return a*(1-x) + b*x;
// cosine
float ft=x*3.1415927f;
float f=(float)((1-Math.cos(ft))*0.5f);
return a*(1-f)+b*f;
}