# How can I generate terrain as integers using perlin noise?

Hi everyone. I’ve been working on a game using text to instantiate sprites in the game world. so far, I’ve been manually typing out each number myself, but now I’d like to learn how to procedurally generate terrain and from what I gather perlin noise is the way to go.

The way I’ve done it so far, I would have a list of arrays with values like this;

``````00001010000000000000000000000000000000000000000000
00000000000000010000000000000000000000000000000000
00000000001000000000010100000000000000000000000000
00000000000010000101111111100000011100110100000000
00000000000011101111111111111110111111111111111000
0000000011100111111111111111001111111111111111100
00000000000010001111111111000001111111111111111100
00001100110001111111111111100011111111111111110110
00011111100000111111111010011111111111111110000000
00000011110111111111110111111111111111111000000000
00000001111111111100000011111111111011010000000000
00000000011111111000001111111111101001000000000000
00000000000100100000000110111110011000000000000000
00000000000000000000000110010000000000000000000000
00000000000000000000000000000000011000000000000000
``````

where the 0s would be sea and the 1s would be land. each row is an array, and it can be referenced in a loop, so each block is created one after another based on it’s number.

From what I’ve seen so far, it seems like Mathf.PerlinNoise only returns a float, how could I full my arrays with the values?

int mapheight = 15:
int mapwidth = 30;

``````Vector2 shift = new Vector2(0,0); // play with this to shift map around
float zoom = 0.1; // play with this to zoom into the noise field

for(int x = 0; x < mapwidth; x++)
for(int y = 0; y < mapheight; y++)
{
Vector2 pos = zoom * (new Vector2(x,y)) + shift;
float noise = Mathf.PerlinNoise(pos.x, pos.y);
if (noise<0.5f) map[x,y] = 0; // water
else if (noise<0.6f) map[x,y] = 2; // sand
else if (noise<0.9f) map[x,y] = 1; // land
else map[x,y] = 3; // mountain

}
``````