I have had no previous experience with procedural generation so this was quite a learning curve for me and I feel I have done fairly well. I finally managed to make a Perlin noise demo with help from this article here and I'm fairly happy of the result (that demo uses a persistence of 1 and 8 octaves).
Here is the code for my Perlin noise. It's very fast to generate compared to some of the other algorithms I've tried. Im using a linear interpolate method because I don't notice the difference between a cos one except for the fact that linear is MUCH quicker...
double[][] genWhiteNoise(){
Random random = new Random(seed);
double[][] noise = new double[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
noise[x][y] = random.nextDouble() % 1;
}
}
return noise;
}
double[][] generateSmoothNoise(double[][] baseNoise, int octave){
double[][] smoothNoise = new double[width][height];
int samplePeriod = 1 << octave;
double sampleFrequency = 1.0f / samplePeriod;
for(int x = 0; x < width; x++){
int sample_x0 = (x / samplePeriod) * samplePeriod;
int sample_x1 = (sample_x0 + samplePeriod) % width;
double horizontal_blend = (x - sample_x0) * sampleFrequency;
for(int y = 0; y < height; y++){
int sample_y0 = (y / samplePeriod) * samplePeriod;
int sample_y1 = (sample_y0 + samplePeriod) % height;
double vertical_blend = (y - sample_y0) * sampleFrequency;
double top = interpolate(baseNoise[sample_x0][sample_y0], baseNoise[sample_x1][sample_y0], horizontal_blend);
double bottom = interpolate(baseNoise[sample_x0][sample_y1], baseNoise[sample_x1][sample_y1], horizontal_blend);
smoothNoise[x][y] = interpolate(top, bottom, vertical_blend);
}
}
return smoothNoise;
}
double[][] perlinNoise(double[][] baseNoise, int octaveCount){
double[][][] smoothNoise = new double[octaveCount][][];
for(int i = 0; i < octaveCount; i++){
smoothNoise = generateSmoothNoise(baseNoise, i);
}
double[][] perlinNoise = new double[width][height];
double amplitude = 1.0;
double totalAmplitude = 0.0d;
for(int octave = octaveCount - 1; octave >= 0; octave--){
amplitude *= persistance;
totalAmplitude += amplitude;
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
perlinNoise[x][y] += smoothNoise[octave][x][y] * amplitude;
}
}
}
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
perlinNoise[x][y] /= totalAmplitude;
}
}
return perlinNoise;
}
First off, can someone please tell me if the noise I have generated if suitable for random world generation or if it's not, can they give me some tips and/or links to good examples.
and second, can someone please tell me a good place to start for turning that Perlin noise into a game world. I am using a tile based system and i plan on having mountains, sand dunes, forests and cities (they wont be randomly generated but they will have a random location in the world based on some placement parameters).
Any help would be very much appreciated.