Skip to content

Commit a07ecd6

Browse files
committed
Implement 4D noise
1 parent c865a84 commit a07ecd6

File tree

5 files changed

+77
-9
lines changed

5 files changed

+77
-9
lines changed

src/main/java/monkstone/noise/Noise.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ default float noise(float x, float y) {
4242

4343
/**
4444
* <p>
45+
* Returns the Perlin noise value at specified coordinates.Perlin noise is
46+
a random sequence generator producing a more natural ordered, harmonic
47+
succession of numbers compared to the standard <b>random()</b> function. It was invented by Ken Perlin in the 1980s and been used since in
48+
graphical applications to produce procedural textures, natural motion,
49+
shapes, terrains etc. The main difference to the
50+
<b>random()</b> function is that Perlin noise is defined in an infinite
51+
* n-dimensional space where each pair of coordinates corresponds to a fixed
52+
* semi-random value (fixed only for the lifespan of the program). The
53+
* resulting value will always be between 0.0 and 1.0. Processing can
54+
* compute 1D, 2D and 3D noise, depending on the number of coordinates
55+
* given. The noise value can be animated by moving through the noise space
56+
* as demonstrated in the example above. The 2nd and 3rd dimension can also
57+
* be interpreted as time.The actual noise is structured similar to an audio
58+
* signal, in respect to the function's use of frequencies. Similar to the
59+
* concept of harmonics in physics, perlin noise is computed over several
60+
* octaves which are added together for the final result. Another way to
61+
* adjust the character of the resulting sequence is the scale of the input
62+
* coordinates. As the function works within an infinite space the value of
63+
* the coordinates doesn't matter as such, only the distance between
64+
* successive coordinates does (eg. when using <b>noise()</b> within a
65+
* loop). As a general rule the smaller the difference between coordinates,
66+
* the smoother the resulting noise sequence will be. Steps of 0.005-0.03
67+
* work best for most applications, but this will differ depending on use.
68+
* <p>
69+
* @param x x-coordinate in noise space
70+
* @param y y-coordinate in noise space
71+
* @param z z-coordinate in noise space
72+
* @param w w-coordinate typically time
73+
* @return
74+
*/
75+
float noise(float x, float y, float z);
76+
77+
/**
78+
* <p>
4579
* Returns the Perlin noise value at specified coordinates. Perlin noise is
4680
* a random sequence generator producing a more natural ordered, harmonic
4781
* succession of numbers compared to the standard <b>random()</b> function.
@@ -72,7 +106,7 @@ default float noise(float x, float y) {
72106
* @param z z-coordinate in noise space
73107
* @return
74108
*/
75-
float noise(float x, float y, float z);
109+
float noise(float x, float y, float z, float w);
76110

77111
/**
78112
* Adjusts the character and level of detail produced by the Perlin noise

src/main/java/monkstone/noise/NoiseGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public NoiseGenerator(Noise implementation){
2626
public float noise(float x, float y, float z) {
2727
return implementation.noise(x, y, z);
2828
}
29+
30+
@Override
31+
public float noise(float x, float y, float z, float w) {
32+
return implementation.noise(x, y, z, w);
33+
}
2934

3035
@Override
3136
public void noiseDetail(int lod) {

src/main/java/monkstone/noise/SimplexNoise.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,17 @@ else if (x0 < z0) {
274274
}
275275

276276
// 4D simplex noise, better simplex rank ordering method 2012-03-09
277-
public static float noise(float x, float y, float z, float w) {
277+
278+
/**
279+
*
280+
* @param x
281+
* @param y
282+
* @param z
283+
* @param w
284+
* @return
285+
*/
286+
@Override
287+
public float noise(float x, float y, float z, float w) {
278288

279289
float n0, n1, n2, n3, n4; // Noise contributions from the five corners
280290
// Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in

src/main/java/monkstone/noise/ValueNoise.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public float noise(float x, float y, float z) {
131131
}
132132
return r;
133133
}
134+
135+
134136

135137
@Override
136138
public void noiseDetail(int lod) {
@@ -157,4 +159,10 @@ public void noiseSeed(long seed) {
157159
perlinRandom.setSeed(seed);
158160
perlin = null;
159161
}
162+
163+
@Override
164+
public float noise(float x, float y, float z, float w) {
165+
String message = "Use Simplex Noise for 4D noise";
166+
throw new UnsupportedOperationException(message);
167+
}
160168
}

src/main/java/processing/core/PApplet.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4932,13 +4932,12 @@ public float noise(float x, float y) {
49324932
/**
49334933
* ( begin auto-generated from noise.xml )
49344934
*
4935-
* Returns the Perlin noise value at specified coordinates. Perlin noise is
4936-
* a random sequence generator producing a more natural ordered, harmonic
4937-
* succession of numbers compared to the standard <b>random()</b> function.
4938-
* It was invented by Ken Perlin in the 1980s and been used since in
4939-
* graphical applications to produce procedural textures, natural motion,
4940-
* shapes, terrains etc. The main difference to the
4941-
* <b>random()</b> function is that Perlin noise is defined in an infinite
4935+
* Returns the Perlin noise value at specified coordinates.Perlin noise is
4936+
a random sequence generator producing a more natural ordered, harmonic
4937+
succession of numbers compared to the standard <b>random()</b> function. It was invented by Ken Perlin in the 1980s and been used since in
4938+
graphical applications to produce procedural textures, natural motion,
4939+
shapes, terrains etc. The main difference to the
4940+
<b>random()</b> function is that Perlin noise is defined in an infinite
49424941
* n-dimensional space where each pair of coordinates corresponds to a fixed
49434942
* semi-random value (fixed only for the lifespan of the program). The
49444943
* resulting value will always be between 0.0 and 1.0. Processing can
@@ -4959,6 +4958,7 @@ public float noise(float x, float y) {
49594958
*
49604959
* ( end auto-generated )
49614960
*
4961+
* @return
49624962
* @webref math:random
49634963
* @param x x-coordinate in noise space
49644964
* @param y y-coordinate in noise space
@@ -4971,6 +4971,17 @@ public float noise(float x, float y, float z) {
49714971
return noiseGenerator.noise(x, y, z);
49724972
}
49734973

4974+
/**
4975+
*
4976+
* @param x
4977+
* @param y
4978+
* @param z
4979+
* @param w
4980+
* @return
4981+
*/
4982+
public float noise(float x, float y, float z, float w) {
4983+
return noiseGenerator.noise(x, y, z, w);
4984+
}
49744985

49754986

49764987
// [toxi 040903]

0 commit comments

Comments
 (0)