0

I got a perlin noise algorithm and an opensimplex noise algorithm that returns a double based on the X and Y values given. I'm designing software and I would like to know how to:

  • Scale the perlin noise with a 0-1 double value
  • Allow building the perlin at different resolutions (i.e. 1024, 2048) but still maintain scale, but add additional detail.
  • Allow user to change world size, which also affects the scale

My current code for this:

double scale = ((((Double) parameters.get(SCALE).getValue() * 10) + 0.25) * ProjectSettings.WORLD_SIZE) /  ((double) resolution / 1000);
double x = 0;
double y = 0;
OpenSimplexNoise noise = new OpenSimplexNoise((Long) parameters.get(SEED).getValue());
for(int n = 0; n < resolution; n++) {
    x += scale;
    for(int m = 0; m < resolution; m++) {
        y += scale;
        values[n][m] = noise.generateOpenSimplexNoise(x, y, (Double) parameters.get(PERSISTENCE).getValue(), (Integer) parameters.get(OCTAVES).getValue());
    }
}
DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
frogocomics
  • 41
  • 1
  • 5

1 Answers1

-2

If you want to change resolution of the Perlin noise image, change height and with values in your for loops. In order to scale, you have to multiply first and/or second arguments of Perlin noise method by some variable that changes when you need to scale. Time value may be well suited for this. See code example below.

time += 0.01;
// Change height and width values to change resolution
for(int y = 0; y < height; y++){
    for(int x = 0; x < width; x++){
        double dx = (double) x / MainWindow.height;
        double dy = (double) y / MainWindow.height;

        // Perlin noise method call
        // In order to scale, you have to multiply current values 
        // by time or other variable, which change would cause the zoom.
        double noise = noise(dx * time, dy * time);
    }
}
Fataho
  • 99
  • 3
  • 15