# Creating a set of islands by subtracting gradient values from a Perlin noise

The answers to this question explains fairly well how to create a big island in the center of the screen by setting up a gradient and then subtracting its value from a Perlin Noise.

Anyway they explain how to create only one gradient at the center of the screen to create a big, sort of circular island.

But what if I want to create an island which has more than one gradient to create a less regular shape, or if I want to create multiple separated islands by setting multiple gradients in different positions? What value should I subtract from the Perlin Noise function for each point? The sum of the distance from each gradient to that point? The average?

Edit: Jon's method of multiplying and normalizing worked, got this result with 4 gradient points: • Multiply the gradients, then normalize them. Apr 25 '16 at 14:03
• So, say I have one gradient at 0, 0, and one at 20, 0, for the point 10, 0 i take the distance from the first (10) and multiply for the distance from the second (10), obtaining 100, and then? Apr 25 '16 at 14:31
• No. You would blend both your gradient noises together using some kind of blend operation. I would suggest multiplying their values together in order to retain a nice gradient pattern. Then normalize the resulting blended data to make it easier to work with. Apr 25 '16 at 14:33
• The blend operation. That'exactly what I'm looking for .-. Apr 25 '16 at 14:36
• I added some sample code on how to blend noise data. It is pretty simple stuff, and you could write a nice wrapper to do the operations for you. Let me know if you have any questions about it. Apr 25 '16 at 14:51

You can blend noise together easily, the concept is pretty simple. You essentially loop through each noise value, and perform an operation on the data, and then save the result. It is also a good idea to normalize this data as it makes it easier to use for future operations.

Here is a simple container class to hold resulting noise data:

public class MapData {

public float[,] Data;
public float Min { get; set; }
public float Max { get; set; }

public MapData(int width, int height)
{
Data = new float[width, height];
Min = float.MaxValue;
Max = float.MinValue;
}
}


Using this class, we can generate and store our noise data. You don't have to use this, but it makes it easier to have something to manage your generated noise data. We will use this to blend the gradients together:

blendData = new MapData (Width, Height);


Grab your data and blend it, keeping track of your upper/lower limits:

// first pass - blend gradient values
for (var x = 0; x < Width; x++) {
for (var y = 0; y < Height; y++) {

// Multiply

// keep track of the max and min values found
if (blendValue > blendData.Max) blendData.Max = blendValue;
if (blendValue < blendData.Min) blendData.Min = blendValue;

blendData.Data[x,y] = blendValue;
}
}


Normalize the resulting data, so that you don't have crazy values to deal with in the future:

// secondary pass to normalize the blended values
for (var x = 0; x < Width; x++) {
for (var y = 0; y < Height; y++) {
blendData.Data[x,y] = (blendData.Data[x,y] - blendData.Min) / (blendData.Max - blendData.Min);
}
}

• This already looks clearer. Got to try this visually. Apr 25 '16 at 15:02
• Can you point out a link reference with some mathematical principles would help me to understand the second loop? Apr 28 '16 at 14:16
• Never mind, it is feature scaling. Apr 28 '16 at 14:19