# TopDown Island Generation

I am trying to generate an island using Simplex Noise. To actually make a island shape i used Amitp's answers to the following questions:

Using them i have snippet of code for generation:(width/height is 128)

for(int y = 0; y < HEIGHT; y++) {
for(int x = 0; x < WIDTH; x++) {
// amitp's solution
Vector2 vec = new Vector2(2 * x / WIDTH - 1, 2 * y / HEIGHT - 2);
float d = Mathf.Sqrt(vec.x * vec.x + vec.y * vec.y);
//
float noise = Noise.Generate((float)x / WIDTH * 10, (float)y / HEIGHT * 10);

// amitp's solution again
mapData[x, y] = noise > 0.3 + 0.4*d*d ? noise * 10 : 0.0f;
//

colors[x + y * WIDTH] = new Color(mapData[x, y], mapData[x, y], mapData[x, y]);
}
}


This gives me the following unwanted result:

How do i get fix it to generate properly?

Lastly i'm using Unity.

***EDIT:

Fixed/Changed a couple of things and now i am getting this(still not what i want):

with this changed code:

for(int y = 0; y < HEIGHT; y++) {
for(int x = 0; x < WIDTH; x++) {
// amitp's solution
Vector2 vec = new Vector2(((2 * x) / WIDTH) - 1, ((2 * y) / HEIGHT) - 1);
float d = Mathf.Sqrt((vec.x * vec.x) + (vec.y * vec.y));
//
float noise = Noise.Generate((float)x / WIDTH, (float)y / HEIGHT);

// amitp's solution again
mapData[x, y] = noise > 0.3 + 0.4*d*d ? noise * 10 : 0.0f;
//

colors[x + y * WIDTH] = new Color(mapData[x, y], mapData[x, y], mapData[x, y]);
}
}

• "(still not what I want)" - can you describe what it is that you do want? What would you like to change about the results you have now? I presume centering & scaling the island relative to the whole square, not just the top-right quadrant, and getting rid of the cropped edges. Anything else? Commented Jul 3, 2015 at 20:28
• Yeah, sorry. I want it to be centered, which i don't know why it is not doing that. As well as what you said, removed cropping and scale nicely. Commented Jul 3, 2015 at 21:29

I suggest this aproach. Let fs(x,y) be your simplex noise function. Let's introduce a second function : f(x,y) = ((float)Math.Sin(((float)x/(float)WIDTH) * Math.PI) ) * ((float)Math.Sin(((float)y / (float)WIDTH) * Math.PI) ) or any function that rassemble the following and that gives values from 0 to 1:

at this point take your simplex noise fs(x,y) :

and multiply per f(x,y) you get something like this :

finaly apply a colorgradient to obtain something like :

• I am actually struggling to find a simplex noise implementation that returns values in the 0 to 1 range. Can any one lead me to one? Commented Jul 7, 2015 at 11:05
• I saw you use unity : try Mathf.PerlinNoise docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html Commented Jul 7, 2015 at 11:21
• I'm not very keen on Unity's Perlin Noise method. When i use it, it just seems to give repetition of 'rolling hills'. Maybe i am using it wrong, but. Commented Jul 7, 2015 at 16:01
• Ok, found a way to use a perlin noise function that gives good results but returns in the range of -1 to 1. I then found a post that give a small formulae to change the -1 to 1 range into 0 to 255 range. Now just the matter of getting the mask formulae to work. Commented Jul 7, 2015 at 16:24
• Ok, so the formlae : f(x,y) = WIDTH * (1 - (X * X + Y * Y)) : isnt giving me numbers in the range of 0 to 1, its giving me the range of 0 to large negative numbers. Commented Jul 7, 2015 at 16:35