mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-26 22:14:08 +08:00
Format code with prettier (#3375)
This commit is contained in:
@ -18,7 +18,12 @@ public class PerlinNoise {
|
||||
* @return float array containing calculated "Perlin-Noise" values
|
||||
*/
|
||||
static float[][] generatePerlinNoise(
|
||||
int width, int height, int octaveCount, float persistence, long seed) {
|
||||
int width,
|
||||
int height,
|
||||
int octaveCount,
|
||||
float persistence,
|
||||
long seed
|
||||
) {
|
||||
final float[][] base = new float[width][height];
|
||||
final float[][] perlinNoise = new float[width][height];
|
||||
final float[][][] noiseLayers = new float[octaveCount][][];
|
||||
@ -33,7 +38,8 @@ public class PerlinNoise {
|
||||
|
||||
// calculate octaves with different roughness
|
||||
for (int octave = 0; octave < octaveCount; octave++) {
|
||||
noiseLayers[octave] = generatePerlinNoiseLayer(base, width, height, octave);
|
||||
noiseLayers[octave] =
|
||||
generatePerlinNoiseLayer(base, width, height, octave);
|
||||
}
|
||||
|
||||
float amplitude = 1f;
|
||||
@ -70,7 +76,12 @@ public class PerlinNoise {
|
||||
* @param octave current layer
|
||||
* @return float array containing calculated "Perlin-Noise-Layer" values
|
||||
*/
|
||||
static float[][] generatePerlinNoiseLayer(float[][] base, int width, int height, int octave) {
|
||||
static float[][] generatePerlinNoiseLayer(
|
||||
float[][] base,
|
||||
int width,
|
||||
int height,
|
||||
int octave
|
||||
) {
|
||||
float[][] perlinNoiseLayer = new float[width][height];
|
||||
|
||||
// calculate period (wavelength) for different shapes
|
||||
@ -90,13 +101,22 @@ public class PerlinNoise {
|
||||
float verticalBlend = (y - y0) * frequency;
|
||||
|
||||
// blend top corners
|
||||
float top = interpolate(base[x0][y0], base[x1][y0], horizintalBlend);
|
||||
float top = interpolate(
|
||||
base[x0][y0],
|
||||
base[x1][y0],
|
||||
horizintalBlend
|
||||
);
|
||||
|
||||
// blend bottom corners
|
||||
float bottom = interpolate(base[x0][y1], base[x1][y1], horizintalBlend);
|
||||
float bottom = interpolate(
|
||||
base[x0][y1],
|
||||
base[x1][y1],
|
||||
horizintalBlend
|
||||
);
|
||||
|
||||
// blend top and bottom interpolation to get the final blend value for this cell
|
||||
perlinNoiseLayer[x][y] = interpolate(top, bottom, verticalBlend);
|
||||
perlinNoiseLayer[x][y] =
|
||||
interpolate(top, bottom, verticalBlend);
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +163,8 @@ public class PerlinNoise {
|
||||
System.out.println("Charset (String): ");
|
||||
charset = in.next();
|
||||
|
||||
perlinNoise = generatePerlinNoise(width, height, octaveCount, persistence, seed);
|
||||
perlinNoise =
|
||||
generatePerlinNoise(width, height, octaveCount, persistence, seed);
|
||||
final char[] chars = charset.toCharArray();
|
||||
final int length = chars.length;
|
||||
final float step = 1f / length;
|
||||
|
Reference in New Issue
Block a user