|
| 1 | +package monkstone.noise; |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright (c) 2021 Martin Prout |
| 5 | + * |
| 6 | + * This library is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU General Public |
| 8 | + * License as published by the Free Software Foundation; either |
| 9 | + * version 3.0 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * http://creativecommons.org/licenses/LGPL/2.1/ |
| 12 | + * |
| 13 | + * This library is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + * Lesser General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public |
| 19 | + * License along with this library; if not, write to the Free Software |
| 20 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | + */ |
| 22 | +public interface Noise { |
| 23 | + |
| 24 | + /** |
| 25 | + * |
| 26 | + * @param x |
| 27 | + * @return |
| 28 | + */ |
| 29 | + default float noise(float x) { |
| 30 | + return noise(x, 0); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * |
| 35 | + * @param x |
| 36 | + * @param y |
| 37 | + * @return |
| 38 | + */ |
| 39 | + default float noise(float x, float y) { |
| 40 | + return noise(x, y, 0); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * <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. |
| 48 | + * It was invented by Ken Perlin in the 1980s and been used since in |
| 49 | + * graphical applications to produce procedural textures, natural motion, |
| 50 | + * shapes, terrains etc. The main difference to the |
| 51 | + * <b>random()</b> function is that Perlin noise is defined in an infinite |
| 52 | + * n-dimensional space where each pair of coordinates corresponds to a fixed |
| 53 | + * semi-random value (fixed only for the lifespan of the program). The |
| 54 | + * resulting value will always be between 0.0 and 1.0. Processing can |
| 55 | + * compute 1D, 2D and 3D noise, depending on the number of coordinates |
| 56 | + * given. The noise value can be animated by moving through the noise space |
| 57 | + * as demonstrated in the example above. The 2nd and 3rd dimension can also |
| 58 | + * be interpreted as time.The actual noise is structured similar to an audio |
| 59 | + * signal, in respect to the function's use of frequencies. Similar to the |
| 60 | + * concept of harmonics in physics, perlin noise is computed over several |
| 61 | + * octaves which are added together for the final result. Another way to |
| 62 | + * adjust the character of the resulting sequence is the scale of the input |
| 63 | + * coordinates. As the function works within an infinite space the value of |
| 64 | + * the coordinates doesn't matter as such, only the distance between |
| 65 | + * successive coordinates does (eg. when using <b>noise()</b> within a |
| 66 | + * loop). As a general rule the smaller the difference between coordinates, |
| 67 | + * the smoother the resulting noise sequence will be. Steps of 0.005-0.03 |
| 68 | + * work best for most applications, but this will differ depending on use. |
| 69 | + * <p> |
| 70 | + * @param x x-coordinate in noise space |
| 71 | + * @param y y-coordinate in noise space |
| 72 | + * @param z z-coordinate in noise space |
| 73 | + * @return |
| 74 | + */ |
| 75 | + float noise(float x, float y, float z); |
| 76 | + |
| 77 | + /** |
| 78 | + * Adjusts the character and level of detail produced by the Perlin noise |
| 79 | + * function.Similar to harmonics in physics, noise is computed over several |
| 80 | + * octaves. Lower octaves contribute more to the output signal and as such |
| 81 | + * define the overal intensity of the noise, whereas higher octaves create |
| 82 | + * finer grained details in the noise sequence. By default, noise is |
| 83 | + * computed over 4 octaves with each octave contributing exactly half than |
| 84 | + * its predecessor, starting at 50% strength for the 1st octave. This |
| 85 | + * falloff amount can be changed by adding an additional function parameter. |
| 86 | + * Eg. a falloff factor of 0.75 means each octave will now have 75% impact |
| 87 | + * (25% less) of the previous lower octave. Any value between 0.0 and 1.0 is |
| 88 | + * valid, however note that values greater than 0.5 might result in greater |
| 89 | + * than 1.0 values returned by <b>noise()</b>.By changing these parameters, |
| 90 | + * the signal created by the <b>noise()</b> |
| 91 | + * function can be adapted to fit very specific needs and characteristics. |
| 92 | + * |
| 93 | + * @param lod |
| 94 | + */ |
| 95 | + void noiseDetail(int lod); |
| 96 | + |
| 97 | + /** |
| 98 | + * @param lod |
| 99 | + * @param falloff falloff factor for each octave |
| 100 | + */ |
| 101 | + void noiseDetail(int lod, float falloff); |
| 102 | + |
| 103 | + /** |
| 104 | + * Sets the seed value for <b>noise()</b>.By default, <b>noise()</b> |
| 105 | + * produces different results each time the program is run. Set the |
| 106 | + * <b>value</b> parameter to a constant to return the same pseudo-random |
| 107 | + * numbers each time the software is run. |
| 108 | + * |
| 109 | + * @param seed |
| 110 | + */ |
| 111 | + void noiseSeed(long seed); |
| 112 | +} |
0 commit comments