I'm using 1D Perlin noise to generate a tile-based world. But the hills that generate are too small. I tried changing the values of the parameters of the PerlinNoise1D method (see below), but that not only changed the maximum height, it also changed the gradient, which I was trying to avoid.

(Sorry for the attached images "Insert Image" didn't work)

This is how it generates now:

<Attached as TerrainNow.jpg>

This is how I want it (of course it's not possible to get it that smooth with tiles this is just a sketch):

<Attached as HowIWantIt.jpg>

This is how it looks like when I try to do it myself:

<Attached as Terrain.jpg>

And here's the code I'm using.

Generation Code:

Code :

Tile[][] tiles = new Tile[][]; int offset = 2048; for(int i = 0;i<tiles[0].length;i++) { int y = (int)ClassNoise.PerlinNoise1D(i, 0.5f, 8)*4; for(int j = offset+y;j<tiles.length;j++) { tiles[i,j] = new Tile(i,j); } }

ClassNoise class:

Code :

public class ClassNoise { public static List<Integer[]> primes = new ArrayList<Integer[]>(); static { int prime1 = 0; int prime2 = 0; int prime3 = 0; for (int i = 1; i < 10000000; i+=2) { if (isPrime(i)) { //primes.add(i); prime1 = i; for (; i < 10000000; i+=2) { if (isPrime(i)) { //primes.add(i); prime2 = i; for (; i < 10000000; i+=2) { if (isPrime(i)) { prime3 = i; primes.add(new Integer[]{prime1,prime2,prime3}); } } } } } } } public static float Noise(int x, int octave) { x = (x << 13) ^ x; return (float) (1.0 - ((x * (x * x * primes.get(octave)[0] + primes.get(octave)[1]) + primes.get(octave)[2]) & Integer.MAX_VALUE) / 1073741824f); } public static float PerlinNoise1D(float x, float persistence, int octaves) { float total = 0; float p = persistence; int n = octaves - 1; float[] octavePostMutliply = { 1, 1, 1, 1, 1, 1, 1, 1 }; for (int i = 0; i <= n; i++) { float frequency = (float) Math.pow(2, i); double amplitude = Math.pow(p, octaves - i); total += InterpolatedNoise(x * frequency, i) * amplitude * octavePostMutliply[i]; } return total; } private static float InterpolatedNoise(float x, int octave) { int integer_X = (int) x; float fractional_X = x - integer_X; float v1 = SmoothNoise1D(integer_X, octave); float v2 = SmoothNoise1D(integer_X + 1, octave); return CosineInterpolate(v1, v2, fractional_X); } public static float CosineInterpolate(float a, float b, float x) { float ft = (float) (x * Math.PI); float f = (float) ((1 - Math.cos(ft)) * 0.5); return a * (1 - f) + b * f; } public static float SmoothNoise1D(int x, int octave) { return Noise(x, octave) / 2 + Noise(x - 1, octave) / 4 + Noise(x + 1, octave) / 4; } private static boolean isPrime(int n) { if (n % 2 == 0) return false; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } }