propane 3.4.2-java → 3.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG.md +9 -1
  7. data/Gemfile +2 -0
  8. data/README.md +7 -10
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +4 -2
  12. data/lib/propane/app.rb +5 -1
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +22 -23
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +10 -9
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +20 -14
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +2 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +2 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +2 -0
  33. data/library/slider/slider.rb +23 -22
  34. data/library/vector_utils/vector_utils.rb +4 -0
  35. data/library/video_event/video_event.rb +2 -0
  36. data/pom.rb +37 -36
  37. data/pom.xml +7 -7
  38. data/propane.gemspec +13 -9
  39. data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
  40. data/src/main/java/monkstone/ColorUtil.java +1 -3
  41. data/src/main/java/monkstone/MathToolModule.java +1 -1
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  44. data/src/main/java/monkstone/fastmath/Deglut.java +6 -56
  45. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  46. data/src/main/java/monkstone/noise/Noise.java +116 -0
  47. data/src/main/java/monkstone/noise/NoiseGenerator.java +63 -0
  48. data/src/main/java/monkstone/noise/NoiseMode.java +15 -0
  49. data/src/main/java/monkstone/noise/SimplexNoise.java +137 -103
  50. data/src/main/java/monkstone/noise/ValueNoise.java +170 -0
  51. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  53. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  54. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  55. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  56. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  57. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  58. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  59. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  60. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  61. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  62. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  63. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  64. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  65. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  66. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  67. data/src/main/java/processing/awt/PSurfaceAWT.java +308 -208
  68. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  69. data/src/main/java/processing/core/PApplet.java +13142 -13883
  70. data/src/main/java/processing/core/PConstants.java +477 -447
  71. data/src/main/java/processing/core/PFont.java +914 -880
  72. data/src/main/java/processing/core/PGraphics.java +152 -136
  73. data/src/main/java/processing/core/PImage.java +275 -372
  74. data/src/main/java/processing/core/PMatrix.java +172 -159
  75. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  76. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  77. data/src/main/java/processing/core/PShape.java +2887 -2651
  78. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  79. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  80. data/src/main/java/processing/core/PStyle.java +40 -37
  81. data/src/main/java/processing/core/PSurface.java +139 -97
  82. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  83. data/src/main/java/processing/core/PVector.java +995 -963
  84. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  85. data/src/main/java/processing/data/DoubleDict.java +756 -710
  86. data/src/main/java/processing/data/DoubleList.java +749 -696
  87. data/src/main/java/processing/data/FloatDict.java +748 -702
  88. data/src/main/java/processing/data/FloatList.java +751 -697
  89. data/src/main/java/processing/data/IntDict.java +720 -673
  90. data/src/main/java/processing/data/IntList.java +699 -633
  91. data/src/main/java/processing/data/JSONArray.java +931 -873
  92. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  93. data/src/main/java/processing/data/JSONTokener.java +351 -341
  94. data/src/main/java/processing/data/LongDict.java +710 -663
  95. data/src/main/java/processing/data/LongList.java +701 -635
  96. data/src/main/java/processing/data/Sort.java +37 -41
  97. data/src/main/java/processing/data/StringDict.java +525 -486
  98. data/src/main/java/processing/data/StringList.java +626 -580
  99. data/src/main/java/processing/data/Table.java +3690 -3510
  100. data/src/main/java/processing/data/TableRow.java +182 -183
  101. data/src/main/java/processing/data/XML.java +957 -883
  102. data/src/main/java/processing/event/Event.java +87 -67
  103. data/src/main/java/processing/event/KeyEvent.java +48 -41
  104. data/src/main/java/processing/event/MouseEvent.java +88 -113
  105. data/src/main/java/processing/event/TouchEvent.java +10 -6
  106. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  107. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  108. data/src/main/java/processing/net/Client.java +20 -20
  109. data/src/main/java/processing/net/Server.java +9 -9
  110. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  111. data/src/main/java/processing/opengl/FrameBuffer.java +389 -377
  112. data/src/main/java/processing/opengl/LinePath.java +132 -89
  113. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  114. data/src/main/java/processing/opengl/PGL.java +660 -567
  115. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  116. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  117. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  118. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  119. data/src/main/java/processing/opengl/PShader.java +369 -461
  120. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  121. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  122. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  123. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  124. data/test/create_test.rb +21 -20
  125. data/test/deglut_spec_test.rb +4 -2
  126. data/test/helper_methods_test.rb +49 -20
  127. data/test/math_tool_test.rb +39 -32
  128. data/test/native_folder.rb +47 -0
  129. data/test/respond_to_test.rb +3 -2
  130. data/test/sketches/key_event.rb +2 -2
  131. data/test/sketches/library/my_library/my_library.rb +3 -0
  132. data/test/test_helper.rb +2 -0
  133. data/test/vecmath_spec_test.rb +35 -22
  134. data/vendors/Rakefile +35 -40
  135. metadata +47 -23
  136. data/library/simplex_noise/simplex_noise.rb +0 -3
  137. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  138. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  139. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  140. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-19 Martin Prout
2
+ * Copyright (c) 2015-20 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -0,0 +1,116 @@
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
+ float noise(float x, float y, float z, float w);
78
+
79
+ void noiseMode(NoiseMode mode);
80
+
81
+ /**
82
+ * Adjusts the character and level of detail produced by the Perlin noise
83
+ * function.Similar to harmonics in physics, noise is computed over several
84
+ * octaves. Lower octaves contribute more to the output signal and as such
85
+ * define the overal intensity of the noise, whereas higher octaves create
86
+ * finer grained details in the noise sequence. By default, noise is
87
+ * computed over 4 octaves with each octave contributing exactly half than
88
+ * its predecessor, starting at 50% strength for the 1st octave. This
89
+ * falloff amount can be changed by adding an additional function parameter.
90
+ * Eg. a falloff factor of 0.75 means each octave will now have 75% impact
91
+ * (25% less) of the previous lower octave. Any value between 0.0 and 1.0 is
92
+ * valid, however note that values greater than 0.5 might result in greater
93
+ * than 1.0 values returned by <b>noise()</b>.By changing these parameters,
94
+ * the signal created by the <b>noise()</b>
95
+ * function can be adapted to fit very specific needs and characteristics.
96
+ *
97
+ * @param lod
98
+ */
99
+ void noiseDetail(int lod);
100
+
101
+ /**
102
+ * @param lod
103
+ * @param falloff falloff factor for each octave
104
+ */
105
+ void noiseDetail(int lod, float falloff);
106
+
107
+ /**
108
+ * Sets the seed value for <b>noise()</b>.By default, <b>noise()</b>
109
+ * produces different results each time the program is run. Set the
110
+ * <b>value</b> parameter to a constant to return the same pseudo-random
111
+ * numbers each time the software is run.
112
+ *
113
+ * @param seed
114
+ */
115
+ void noiseSeed(long seed);
116
+ }
@@ -0,0 +1,63 @@
1
+ /*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+ package monkstone.noise;
7
+
8
+ /**
9
+ *
10
+ * @author Martin Prout
11
+ */
12
+ public class NoiseGenerator implements Noise {
13
+
14
+ private Noise implementation;
15
+ private NoiseMode mode;
16
+
17
+ public NoiseGenerator() {
18
+ this.implementation = new ValueNoise();
19
+ this.mode = NoiseMode.PERLIN;
20
+ }
21
+
22
+ public void noiseMode(NoiseMode mode) {
23
+ if (this.mode != mode && this.mode != NoiseMode.PERLIN) {
24
+ this.implementation = new ValueNoise();
25
+ this.mode = NoiseMode.PERLIN;
26
+ }
27
+ if (this.mode != mode && this.mode != NoiseMode.SIMPLEX) {
28
+ this.implementation = new SimplexNoise();
29
+ this.mode = NoiseMode.SIMPLEX;
30
+ }
31
+ }
32
+
33
+ public NoiseMode noiseMode(){
34
+ return this.mode;
35
+ }
36
+
37
+ @Override
38
+ public float noise(float x, float y, float z) {
39
+ return implementation.noise(x, y, z);
40
+ }
41
+
42
+ @Override
43
+ public float noise(float x, float y, float z, float w) {
44
+ if (mode == NoiseMode.PERLIN) { return 0.5f;}
45
+ return implementation.noise(x, y, z, w);
46
+ }
47
+
48
+ @Override
49
+ public void noiseDetail(int lod) {
50
+ implementation.noiseDetail(lod);
51
+ }
52
+
53
+ @Override
54
+ public void noiseDetail(int lod, float falloff) {
55
+ implementation.noiseDetail(lod, falloff);
56
+ }
57
+
58
+ @Override
59
+ public void noiseSeed(long seed) {
60
+ implementation.noiseSeed(seed);
61
+ }
62
+
63
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+ package monkstone.noise;
7
+
8
+ /**
9
+ *
10
+ * @author tux
11
+ */
12
+ public enum NoiseMode {
13
+ SIMPLEX,
14
+ PERLIN;
15
+ }
@@ -1,3 +1,5 @@
1
+ package monkstone.noise;
2
+
1
3
  /*
2
4
  * A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
3
5
  *
@@ -14,9 +16,9 @@
14
16
  * attribution is appreciated.
15
17
  *
16
18
  */
17
- package monkstone.noise;
18
19
 
19
- public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
20
+
21
+ public class SimplexNoise implements Noise{ // Simplex noise in 2D, 3D and 4D
20
22
 
21
23
  private static Grad grad3[] = {new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0),
22
24
  new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1),
@@ -31,7 +33,7 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
31
33
  new Grad(1, 1, 1, 0), new Grad(1, 1, -1, 0), new Grad(1, -1, 1, 0), new Grad(1, -1, -1, 0),
32
34
  new Grad(-1, 1, 1, 0), new Grad(-1, 1, -1, 0), new Grad(-1, -1, 1, 0), new Grad(-1, -1, -1, 0)};
33
35
 
34
- private static short p[] = {151, 160, 137, 91, 90, 15,
36
+ private final static short p[] = {151, 160, 137, 91, 90, 15,
35
37
  131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
36
38
  190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
37
39
  88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
@@ -45,7 +47,7 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
45
47
  49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
46
48
  138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
47
49
  // To remove the need for index wrapping, double the permutation table length
48
- static short[] PERM = new short[512];
50
+ final static short[] PERM = new short[512];
49
51
  static short[] PERM_MOD_12 = new short[512];
50
52
 
51
53
  static {
@@ -56,43 +58,44 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
56
58
  }
57
59
 
58
60
  // Skewing and unskewing factors for 2, 3, and 4 dimensions
59
- private static final double F2 = 0.5 * (Math.sqrt(3.0) - 1.0);
60
- private static final double G2 = (3.0 - Math.sqrt(3.0)) / 6.0;
61
- private static final double F3 = 1.0 / 3.0;
62
- private static final double G3 = 1.0 / 6.0;
63
- private static final double F4 = (Math.sqrt(5.0) - 1.0) / 4.0;
64
- private static final double G4 = (5.0 - Math.sqrt(5.0)) / 20.0;
61
+ private static final float F2 = 0.5f * (float)(Math.sqrt(3.0) - 1.0);
62
+ private static final float G2 = (float)(3.0 - Math.sqrt(3.0)) / 6.0f;
63
+ private static final float F3 = 1.0f / 3.0f;
64
+ private static final float G3 = 1.0f / 6.0f;
65
+ private static final float F4 = (float)(Math.sqrt(5.0) - 1.0) / 4.0f;
66
+ private static final float G4 = (float)(5.0 - Math.sqrt(5.0)) / 20.0f;
65
67
 
66
68
  // This method is a *lot* faster than using (int)Math.floor(x)
67
- private static int fastfloor(double x) {
69
+ private static int fastfloor(float x) {
68
70
  int xi = (int) x;
69
71
  return x < xi ? xi - 1 : xi;
70
72
  }
71
73
 
72
- private static double dot(Grad g, double x, double y) {
74
+ private static float dot(Grad g, float x, float y) {
73
75
  return g.x * x + g.y * y;
74
76
  }
75
77
 
76
- private static double dot(Grad g, double x, double y, double z) {
78
+ private static float dot(Grad g, float x, float y, float z) {
77
79
  return g.x * x + g.y * y + g.z * z;
78
80
  }
79
81
 
80
- private static double dot(Grad g, double x, double y, double z, double w) {
82
+ private static float dot(Grad g, float x, float y, float z, float w) {
81
83
  return g.x * x + g.y * y + g.z * z + g.w * w;
82
84
  }
83
85
 
84
86
  // 2D simplex noise
85
- public static double noise(double xin, double yin) {
86
- double n0, n1, n2; // Noise contributions from the three corners
87
+ @Override
88
+ public float noise(float xin, float yin) {
89
+ float n0, n1, n2; // Noise contributions from the three corners
87
90
  // Skew the input space to determine which simplex cell we're in
88
- double s = (xin + yin) * F2; // Hairy factor for 2D
91
+ float s = (xin + yin) * F2; // Hairy factor for 2D
89
92
  int i = fastfloor(xin + s);
90
93
  int j = fastfloor(yin + s);
91
- double t = (i + j) * G2;
92
- double X0 = i - t; // Unskew the cell origin back to (x,y) space
93
- double Y0 = j - t;
94
- double x0 = xin - X0; // The x,y distances from the cell origin
95
- double y0 = yin - Y0;
94
+ float t = (i + j) * G2;
95
+ float X0 = i - t; // Unskew the cell origin back to (x,y) space
96
+ float Y0 = j - t;
97
+ float x0 = xin - X0; // The x,y distances from the cell origin
98
+ float y0 = yin - Y0;
96
99
  // For the 2D case, the simplex shape is an equilateral triangle.
97
100
  // Determine which simplex we are in.
98
101
  int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
@@ -107,10 +110,10 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
107
110
  // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
108
111
  // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
109
112
  // c = (3-sqrt(3))/6
110
- double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
111
- double y1 = y0 - j1 + G2;
112
- double x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords
113
- double y2 = y0 - 1.0 + 2.0 * G2;
113
+ float x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
114
+ float y1 = y0 - j1 + G2;
115
+ float x2 = x0 - 1.0f + 2.0f * G2; // Offsets for last corner in (x,y) unskewed coords
116
+ float y2 = y0 - 1.0f + 2.0f * G2;
114
117
  // Work out the hashed gradient indices of the three simplex corners
115
118
  int ii = i & 255;
116
119
  int jj = j & 255;
@@ -118,47 +121,48 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
118
121
  int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1]];
119
122
  int gi2 = PERM_MOD_12[ii + 1 + PERM[jj + 1]];
120
123
  // Calculate the contribution from the three corners
121
- double t0 = 0.5 - x0 * x0 - y0 * y0;
124
+ float t0 = 0.5f - x0 * x0 - y0 * y0;
122
125
  if (t0 < 0) {
123
- n0 = 0.0;
126
+ n0 = 0.0f;
124
127
  } else {
125
128
  t0 *= t0;
126
129
  n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
127
130
  }
128
- double t1 = 0.5 - x1 * x1 - y1 * y1;
131
+ float t1 = 0.5f - x1 * x1 - y1 * y1;
129
132
  if (t1 < 0) {
130
- n1 = 0.0;
133
+ n1 = 0.0f;
131
134
  } else {
132
135
  t1 *= t1;
133
136
  n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
134
137
  }
135
- double t2 = 0.5 - x2 * x2 - y2 * y2;
138
+ float t2 = 0.5f - x2 * x2 - y2 * y2;
136
139
  if (t2 < 0) {
137
- n2 = 0.0;
140
+ n2 = 0.0f;
138
141
  } else {
139
142
  t2 *= t2;
140
143
  n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
141
144
  }
142
145
  // Add contributions from each corner to get the final noise value.
143
146
  // The result is scaled to return values in the interval [-1,1].
144
- return 70.0 * (n0 + n1 + n2);
147
+ return 70.0f * (n0 + n1 + n2);
145
148
  }
146
149
 
147
150
  // 3D simplex noise
148
- public static double noise(double xin, double yin, double zin) {
149
- double n0, n1, n2, n3; // Noise contributions from the four corners
151
+ @Override
152
+ public float noise(float xin, float yin, float zin) {
153
+ float n0, n1, n2, n3; // Noise contributions from the four corners
150
154
  // Skew the input space to determine which simplex cell we're in
151
- double s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D
155
+ float s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D
152
156
  int i = fastfloor(xin + s);
153
157
  int j = fastfloor(yin + s);
154
158
  int k = fastfloor(zin + s);
155
- double t = (i + j + k) * G3;
156
- double X0 = i - t; // Unskew the cell origin back to (x,y,z) space
157
- double Y0 = j - t;
158
- double Z0 = k - t;
159
- double x0 = xin - X0; // The x,y,z distances from the cell origin
160
- double y0 = yin - Y0;
161
- double z0 = zin - Z0;
159
+ float t = (i + j + k) * G3;
160
+ float X0 = i - t; // Unskew the cell origin back to (x,y,z) space
161
+ float Y0 = j - t;
162
+ float Z0 = k - t;
163
+ float x0 = xin - X0; // The x,y,z distances from the cell origin
164
+ float y0 = yin - Y0;
165
+ float z0 = zin - Z0;
162
166
  // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
163
167
  // Determine which simplex we are in.
164
168
  int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
@@ -218,15 +222,15 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
218
222
  // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
219
223
  // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
220
224
  // c = 1/6.
221
- double x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
222
- double y1 = y0 - j1 + G3;
223
- double z1 = z0 - k1 + G3;
224
- double x2 = x0 - i2 + 2.0 * G3; // Offsets for third corner in (x,y,z) coords
225
- double y2 = y0 - j2 + 2.0 * G3;
226
- double z2 = z0 - k2 + 2.0 * G3;
227
- double x3 = x0 - 1.0 + 3.0 * G3; // Offsets for last corner in (x,y,z) coords
228
- double y3 = y0 - 1.0 + 3.0 * G3;
229
- double z3 = z0 - 1.0 + 3.0 * G3;
225
+ float x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
226
+ float y1 = y0 - j1 + G3;
227
+ float z1 = z0 - k1 + G3;
228
+ float x2 = x0 - i2 + 2.0f * G3; // Offsets for third corner in (x,y,z) coords
229
+ float y2 = y0 - j2 + 2.0f * G3;
230
+ float z2 = z0 - k2 + 2.0f * G3;
231
+ float x3 = x0 - 1.0f + 3.0f * G3; // Offsets for last corner in (x,y,z) coords
232
+ float y3 = y0 - 1.0f + 3.0f * G3;
233
+ float z3 = z0 - 1.0f + 3.0f * G3;
230
234
  // Work out the hashed gradient indices of the four simplex corners
231
235
  int ii = i & 255;
232
236
  int jj = j & 255;
@@ -236,58 +240,68 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
236
240
  int gi2 = PERM_MOD_12[ii + i2 + PERM[jj + j2 + PERM[kk + k2]]];
237
241
  int gi3 = PERM_MOD_12[ii + 1 + PERM[jj + 1 + PERM[kk + 1]]];
238
242
  // Calculate the contribution from the four corners
239
- double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;
243
+ float t0 = 0.5f - x0 * x0 - y0 * y0 - z0 * z0;
240
244
  if (t0 < 0) {
241
- n0 = 0.0;
245
+ n0 = 0.0f;
242
246
  } else {
243
247
  t0 *= t0;
244
248
  n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
245
249
  }
246
- double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;
250
+ float t1 = 0.5f - x1 * x1 - y1 * y1 - z1 * z1;
247
251
  if (t1 < 0) {
248
- n1 = 0.0;
252
+ n1 = 0.0f;
249
253
  } else {
250
254
  t1 *= t1;
251
255
  n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
252
256
  }
253
- double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;
257
+ float t2 = 0.5f - x2 * x2 - y2 * y2 - z2 * z2;
254
258
  if (t2 < 0) {
255
- n2 = 0.0;
259
+ n2 = 0.0f;
256
260
  } else {
257
261
  t2 *= t2;
258
262
  n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
259
263
  }
260
- double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;
264
+ float t3 = 0.5f - x3 * x3 - y3 * y3 - z3 * z3;
261
265
  if (t3 < 0) {
262
- n3 = 0.0;
266
+ n3 = 0.0f;
263
267
  } else {
264
268
  t3 *= t3;
265
269
  n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
266
270
  }
267
271
  // Add contributions from each corner to get the final noise value.
268
272
  // The result is scaled to stay just inside [-1,1]
269
- return 32.0 * (n0 + n1 + n2 + n3);
273
+ return 32.0f * (n0 + n1 + n2 + n3);
270
274
  }
271
275
 
272
276
  // 4D simplex noise, better simplex rank ordering method 2012-03-09
273
- public static double noise(double x, double y, double z, double w) {
274
277
 
275
- double n0, n1, n2, n3, n4; // Noise contributions from the five corners
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) {
288
+
289
+ float n0, n1, n2, n3, n4; // Noise contributions from the five corners
276
290
  // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
277
- double s = (x + y + z + w) * F4; // Factor for 4D skewing
291
+ float s = (x + y + z + w) * F4; // Factor for 4D skewing
278
292
  int i = fastfloor(x + s);
279
293
  int j = fastfloor(y + s);
280
294
  int k = fastfloor(z + s);
281
295
  int l = fastfloor(w + s);
282
- double t = (i + j + k + l) * G4; // Factor for 4D unskewing
283
- double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
284
- double Y0 = j - t;
285
- double Z0 = k - t;
286
- double W0 = l - t;
287
- double x0 = x - X0; // The x,y,z,w distances from the cell origin
288
- double y0 = y - Y0;
289
- double z0 = z - Z0;
290
- double w0 = w - W0;
296
+ float t = (i + j + k + l) * G4; // Factor for 4D unskewing
297
+ float X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
298
+ float Y0 = j - t;
299
+ float Z0 = k - t;
300
+ float W0 = l - t;
301
+ float x0 = x - X0; // The x,y,z,w distances from the cell origin
302
+ float y0 = y - Y0;
303
+ float z0 = z - Z0;
304
+ float w0 = w - W0;
291
305
  // For the 4D case, the simplex is a 4D shape I won't even try to describe.
292
306
  // To find out which of the 24 possible simplices we're in, we need to
293
307
  // determine the magnitude ordering of x0, y0, z0 and w0.
@@ -348,22 +362,22 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
348
362
  k3 = rankz >= 1 ? 1 : 0;
349
363
  l3 = rankw >= 1 ? 1 : 0;
350
364
  // The fifth corner has all coordinate offsets = 1, so no need to compute that.
351
- double x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
352
- double y1 = y0 - j1 + G4;
353
- double z1 = z0 - k1 + G4;
354
- double w1 = w0 - l1 + G4;
355
- double x2 = x0 - i2 + 2.0 * G4; // Offsets for third corner in (x,y,z,w) coords
356
- double y2 = y0 - j2 + 2.0 * G4;
357
- double z2 = z0 - k2 + 2.0 * G4;
358
- double w2 = w0 - l2 + 2.0 * G4;
359
- double x3 = x0 - i3 + 3.0 * G4; // Offsets for fourth corner in (x,y,z,w) coords
360
- double y3 = y0 - j3 + 3.0 * G4;
361
- double z3 = z0 - k3 + 3.0 * G4;
362
- double w3 = w0 - l3 + 3.0 * G4;
363
- double x4 = x0 - 1.0 + 4.0 * G4; // Offsets for last corner in (x,y,z,w) coords
364
- double y4 = y0 - 1.0 + 4.0 * G4;
365
- double z4 = z0 - 1.0 + 4.0 * G4;
366
- double w4 = w0 - 1.0 + 4.0 * G4;
365
+ float x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
366
+ float y1 = y0 - j1 + G4;
367
+ float z1 = z0 - k1 + G4;
368
+ float w1 = w0 - l1 + G4;
369
+ float x2 = x0 - i2 + 20.f * G4; // Offsets for third corner in (x,y,z,w) coords
370
+ float y2 = y0 - j2 + 20.f * G4;
371
+ float z2 = z0 - k2 + 20.f * G4;
372
+ float w2 = w0 - l2 + 20.f * G4;
373
+ float x3 = x0 - i3 + 30.f * G4; // Offsets for fourth corner in (x,y,z,w) coords
374
+ float y3 = y0 - j3 + 30.f * G4;
375
+ float z3 = z0 - k3 + 30.f * G4;
376
+ float w3 = w0 - l3 + 30.f * G4;
377
+ float x4 = x0 - 1.0f + 40.f * G4; // Offsets for last corner in (x,y,z,w) coords
378
+ float y4 = y0 - 1.0f + 40.f * G4;
379
+ float z4 = z0 - 1.0f + 40.f * G4;
380
+ float w4 = w0 - 1.0f + 40.f * G4;
367
381
  // Work out the hashed gradient indices of the five simplex corners
368
382
  int ii = i & 255;
369
383
  int jj = j & 255;
@@ -375,58 +389,78 @@ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
375
389
  int gi3 = PERM[ii + i3 + PERM[jj + j3 + PERM[kk + k3 + PERM[ll + l3]]]] % 32;
376
390
  int gi4 = PERM[ii + 1 + PERM[jj + 1 + PERM[kk + 1 + PERM[ll + 1]]]] % 32;
377
391
  // Calculate the contribution from the five corners
378
- double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
392
+ float t0 = 0.5f - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
379
393
  if (t0 < 0) {
380
- n0 = 0.0;
394
+ n0 = 0.0f;
381
395
  } else {
382
396
  t0 *= t0;
383
397
  n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
384
398
  }
385
- double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
399
+ float t1 = 0.5f - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
386
400
  if (t1 < 0) {
387
- n1 = 0.0;
401
+ n1 = 0.0f;
388
402
  } else {
389
403
  t1 *= t1;
390
404
  n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
391
405
  }
392
- double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
406
+ float t2 = 0.5f - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
393
407
  if (t2 < 0) {
394
- n2 = 0.0;
408
+ n2 = 0.0f;
395
409
  } else {
396
410
  t2 *= t2;
397
411
  n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
398
412
  }
399
- double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
413
+ float t3 = 0.5f - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
400
414
  if (t3 < 0) {
401
- n3 = 0.0;
415
+ n3 = 0.0f;
402
416
  } else {
403
417
  t3 *= t3;
404
418
  n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
405
419
  }
406
- double t4 = 0.5 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
420
+ float t4 = 0.5f - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
407
421
  if (t4 < 0) {
408
- n4 = 0.0;
422
+ n4 = 0.0f;
409
423
  } else {
410
424
  t4 *= t4;
411
425
  n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
412
426
  }
413
427
  // Sum up and scale the result to cover the range [-1,1]
414
- return 27.0 * (n0 + n1 + n2 + n3 + n4);
428
+ return 27.0f * (n0 + n1 + n2 + n3 + n4);
429
+ }
430
+
431
+ @Override
432
+ public void noiseDetail(int lod) {
433
+
434
+ }
435
+
436
+ @Override
437
+ public void noiseDetail(int lod, float falloff) {
438
+
439
+ }
440
+
441
+ @Override
442
+ public void noiseSeed(long seed) {
443
+
444
+ }
445
+
446
+ @Override
447
+ public void noiseMode(NoiseMode mode) {
448
+
415
449
  }
416
450
 
417
451
  // Inner class to speed upp gradient computations
418
452
  // (In Java, array access is a lot slower than member access)
419
453
  private static class Grad {
420
454
 
421
- double x, y, z, w;
455
+ float x, y, z, w;
422
456
 
423
- Grad(double x, double y, double z) {
457
+ Grad(float x, float y, float z) {
424
458
  this.x = x;
425
459
  this.y = y;
426
460
  this.z = z;
427
461
  }
428
462
 
429
- Grad(double x, double y, double z, double w) {
463
+ Grad(float x, float y, float z, float w) {
430
464
  this.x = x;
431
465
  this.y = y;
432
466
  this.z = z;