propane 3.8.0-java → 4.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/maven-wrapper.properties +1 -1
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +7 -1
  6. data/README.md +7 -7
  7. data/Rakefile +6 -5
  8. data/lib/propane/app.rb +10 -17
  9. data/lib/propane/helper_methods.rb +6 -6
  10. data/lib/propane/version.rb +1 -1
  11. data/lib/propane-4.0.0.jar +0 -0
  12. data/library/pdf/itextpdf-5.5.13.2.jar +0 -0
  13. data/library/pdf/pdf.rb +7 -0
  14. data/library/slider/slider.rb +1 -1
  15. data/library/svg/batik-all-1.14.jar +0 -0
  16. data/library/svg/svg.rb +7 -0
  17. data/mvnw +3 -3
  18. data/mvnw.cmd +2 -2
  19. data/pom.rb +35 -8
  20. data/pom.xml +60 -9
  21. data/propane.gemspec +9 -7
  22. data/src/main/java/monkstone/ColorUtil.java +1 -1
  23. data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
  24. data/src/main/java/monkstone/MathToolModule.java +31 -31
  25. data/src/main/java/monkstone/PropaneLibrary.java +3 -1
  26. data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
  27. data/src/main/java/monkstone/fastmath/DegLutTables.java +25 -26
  28. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  29. data/src/main/java/monkstone/filechooser/Chooser.java +2 -2
  30. data/src/main/java/monkstone/noise/LICENSE +121 -0
  31. data/src/main/java/monkstone/noise/OpenSimplex2F.java +914 -0
  32. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
  33. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  34. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  35. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  36. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  37. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  38. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  39. data/src/main/java/monkstone/slider/WheelHandler.java +2 -2
  40. data/src/main/java/monkstone/vecmath/JRender.java +6 -6
  41. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  42. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +103 -83
  43. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +27 -41
  44. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  45. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  46. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  47. data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -4
  48. data/src/main/java/processing/awt/PImageAWT.java +8 -8
  49. data/src/main/java/processing/core/PApplet.java +245 -254
  50. data/src/main/java/processing/core/PConstants.java +155 -163
  51. data/src/main/java/processing/core/PGraphics.java +116 -109
  52. data/src/main/java/processing/core/PImage.java +3025 -3047
  53. data/src/main/java/processing/core/PMatrix.java +5 -2
  54. data/src/main/java/processing/data/DoubleDict.java +72 -43
  55. data/src/main/java/processing/data/DoubleList.java +6 -2
  56. data/src/main/java/processing/data/FloatDict.java +744 -756
  57. data/src/main/java/processing/data/FloatList.java +68 -26
  58. data/src/main/java/processing/data/IntDict.java +72 -45
  59. data/src/main/java/processing/data/IntList.java +63 -26
  60. data/src/main/java/processing/data/JSONArray.java +892 -931
  61. data/src/main/java/processing/data/JSONObject.java +1169 -1262
  62. data/src/main/java/processing/data/JSONTokener.java +30 -49
  63. data/src/main/java/processing/data/LongDict.java +699 -712
  64. data/src/main/java/processing/data/LongList.java +676 -700
  65. data/src/main/java/processing/data/Sort.java +1 -0
  66. data/src/main/java/processing/data/Table.java +4040 -3661
  67. data/src/main/java/processing/data/TableRow.java +16 -0
  68. data/src/main/java/processing/data/XML.java +1041 -956
  69. data/src/main/java/processing/event/TouchEvent.java +1 -1
  70. data/src/main/java/processing/opengl/FontTexture.java +2 -2
  71. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +28 -31
  72. data/src/main/java/processing/opengl/PJOGL.java +8 -7
  73. data/src/main/java/processing/opengl/PShader.java +1 -6
  74. data/src/main/java/processing/opengl/PShapeOpenGL.java +23 -24
  75. data/src/main/java/processing/opengl/PSurfaceJOGL.java +6 -6
  76. data/src/main/java/processing/pdf/PGraphicsPDF.java +581 -0
  77. data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
  78. data/src/main/{java/processing/opengl → resources}/cursors/arrow.png +0 -0
  79. data/src/main/{java/processing/opengl → resources}/cursors/cross.png +0 -0
  80. data/src/main/{java/processing/opengl → resources}/cursors/hand.png +0 -0
  81. data/src/main/{java/processing/opengl → resources}/cursors/license.txt +0 -0
  82. data/src/main/{java/processing/opengl → resources}/cursors/move.png +0 -0
  83. data/src/main/{java/processing/opengl → resources}/cursors/text.png +0 -0
  84. data/src/main/{java/processing/opengl → resources}/cursors/wait.png +0 -0
  85. data/src/main/{java/processing/opengl → resources}/shaders/ColorFrag.glsl +0 -0
  86. data/src/main/{java/processing/opengl → resources}/shaders/ColorVert.glsl +0 -0
  87. data/src/main/{java/processing/opengl → resources}/shaders/LightFrag.glsl +0 -0
  88. data/src/main/{java/processing/opengl → resources}/shaders/LightVert.glsl +0 -0
  89. data/src/main/{java/processing/opengl → resources}/shaders/LineFrag.glsl +0 -0
  90. data/src/main/{java/processing/opengl → resources}/shaders/LineVert.glsl +0 -0
  91. data/src/main/{java/processing/opengl → resources}/shaders/MaskFrag.glsl +0 -0
  92. data/src/main/{java/processing/opengl → resources}/shaders/PointFrag.glsl +0 -0
  93. data/src/main/{java/processing/opengl → resources}/shaders/PointVert.glsl +0 -0
  94. data/src/main/{java/processing/opengl → resources}/shaders/TexFrag.glsl +0 -0
  95. data/src/main/{java/processing/opengl → resources}/shaders/TexLightFrag.glsl +0 -0
  96. data/src/main/{java/processing/opengl → resources}/shaders/TexLightVert.glsl +0 -0
  97. data/src/main/{java/processing/opengl → resources}/shaders/TexVert.glsl +0 -0
  98. data/test/test_helper.rb +1 -0
  99. data/test/vecmath_spec_test.rb +14 -3
  100. data/vendors/Rakefile +1 -1
  101. metadata +53 -53
  102. data/lib/propane-3.8.0.jar +0 -0
  103. data/src/main/java/monkstone/noise/Noise.java +0 -116
  104. data/src/main/java/monkstone/noise/NoiseGenerator.java +0 -63
  105. data/src/main/java/monkstone/noise/NoiseMode.java +0 -15
  106. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -470
  107. data/src/main/java/monkstone/noise/ValueNoise.java +0 -170
@@ -1,470 +0,0 @@
1
- package monkstone.noise;
2
-
3
- /*
4
- * A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
5
- *
6
- * Based on example code by Stefan Gustavson (stegu@itn.liu.se).
7
- * Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
8
- * Better rank ordering method for 4D by Stefan Gustavson in 2012.
9
- *
10
- * This could be speeded up even further, but it's useful as it is.
11
- *
12
- * Version 2012-03-09
13
- *
14
- * This code was placed in the public domain by its original author,
15
- * Stefan Gustavson. You may use it as you see fit, but
16
- * attribution is appreciated.
17
- *
18
- */
19
-
20
-
21
- public class SimplexNoise implements Noise{ // Simplex noise in 2D, 3D and 4D
22
-
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),
24
- new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1),
25
- new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)};
26
-
27
- private static Grad grad4[] = {new Grad(0, 1, 1, 1), new Grad(0, 1, 1, -1), new Grad(0, 1, -1, 1), new Grad(0, 1, -1, -1),
28
- new Grad(0, -1, 1, 1), new Grad(0, -1, 1, -1), new Grad(0, -1, -1, 1), new Grad(0, -1, -1, -1),
29
- new Grad(1, 0, 1, 1), new Grad(1, 0, 1, -1), new Grad(1, 0, -1, 1), new Grad(1, 0, -1, -1),
30
- new Grad(-1, 0, 1, 1), new Grad(-1, 0, 1, -1), new Grad(-1, 0, -1, 1), new Grad(-1, 0, -1, -1),
31
- new Grad(1, 1, 0, 1), new Grad(1, 1, 0, -1), new Grad(1, -1, 0, 1), new Grad(1, -1, 0, -1),
32
- new Grad(-1, 1, 0, 1), new Grad(-1, 1, 0, -1), new Grad(-1, -1, 0, 1), new Grad(-1, -1, 0, -1),
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),
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)};
35
-
36
- private final static short p[] = {151, 160, 137, 91, 90, 15,
37
- 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
38
- 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
39
- 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
40
- 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
41
- 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
42
- 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123,
43
- 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
44
- 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
45
- 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
46
- 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
47
- 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
48
- 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
49
- // To remove the need for index wrapping, double the permutation table length
50
- final static short[] PERM = new short[512];
51
- static short[] PERM_MOD_12 = new short[512];
52
-
53
- static {
54
- for (int i = 0; i < 512; i++) {
55
- PERM[i] = p[i & 255];
56
- PERM_MOD_12[i] = (short) (PERM[i] % 12);
57
- }
58
- }
59
-
60
- // Skewing and unskewing factors for 2, 3, and 4 dimensions
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;
67
-
68
- // This method is a *lot* faster than using (int)Math.floor(x)
69
- private static int fastfloor(float x) {
70
- int xi = (int) x;
71
- return x < xi ? xi - 1 : xi;
72
- }
73
-
74
- private static float dot(Grad g, float x, float y) {
75
- return g.x * x + g.y * y;
76
- }
77
-
78
- private static float dot(Grad g, float x, float y, float z) {
79
- return g.x * x + g.y * y + g.z * z;
80
- }
81
-
82
- private static float dot(Grad g, float x, float y, float z, float w) {
83
- return g.x * x + g.y * y + g.z * z + g.w * w;
84
- }
85
-
86
- // 2D simplex noise
87
- @Override
88
- public float noise(float xin, float yin) {
89
- float n0, n1, n2; // Noise contributions from the three corners
90
- // Skew the input space to determine which simplex cell we're in
91
- float s = (xin + yin) * F2; // Hairy factor for 2D
92
- int i = fastfloor(xin + s);
93
- int j = fastfloor(yin + s);
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;
99
- // For the 2D case, the simplex shape is an equilateral triangle.
100
- // Determine which simplex we are in.
101
- int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
102
- if (x0 > y0) {
103
- i1 = 1;
104
- j1 = 0;
105
- } // lower triangle, XY order: (0,0)->(1,0)->(1,1)
106
- else {
107
- i1 = 0;
108
- j1 = 1;
109
- } // upper triangle, YX order: (0,0)->(0,1)->(1,1)
110
- // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
111
- // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
112
- // c = (3-sqrt(3))/6
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;
117
- // Work out the hashed gradient indices of the three simplex corners
118
- int ii = i & 255;
119
- int jj = j & 255;
120
- int gi0 = PERM_MOD_12[ii + PERM[jj]];
121
- int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1]];
122
- int gi2 = PERM_MOD_12[ii + 1 + PERM[jj + 1]];
123
- // Calculate the contribution from the three corners
124
- float t0 = 0.5f - x0 * x0 - y0 * y0;
125
- if (t0 < 0) {
126
- n0 = 0.0f;
127
- } else {
128
- t0 *= t0;
129
- n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
130
- }
131
- float t1 = 0.5f - x1 * x1 - y1 * y1;
132
- if (t1 < 0) {
133
- n1 = 0.0f;
134
- } else {
135
- t1 *= t1;
136
- n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
137
- }
138
- float t2 = 0.5f - x2 * x2 - y2 * y2;
139
- if (t2 < 0) {
140
- n2 = 0.0f;
141
- } else {
142
- t2 *= t2;
143
- n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
144
- }
145
- // Add contributions from each corner to get the final noise value.
146
- // The result is scaled to return values in the interval [-1,1].
147
- return 70.0f * (n0 + n1 + n2);
148
- }
149
-
150
- // 3D simplex noise
151
- @Override
152
- public float noise(float xin, float yin, float zin) {
153
- float n0, n1, n2, n3; // Noise contributions from the four corners
154
- // Skew the input space to determine which simplex cell we're in
155
- float s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D
156
- int i = fastfloor(xin + s);
157
- int j = fastfloor(yin + s);
158
- int k = fastfloor(zin + s);
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;
166
- // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
167
- // Determine which simplex we are in.
168
- int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
169
- int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
170
- if (x0 >= y0) {
171
- if (y0 >= z0) {
172
- i1 = 1;
173
- j1 = 0;
174
- k1 = 0;
175
- i2 = 1;
176
- j2 = 1;
177
- k2 = 0;
178
- } // X Y Z order
179
- else if (x0 >= z0) {
180
- i1 = 1;
181
- j1 = 0;
182
- k1 = 0;
183
- i2 = 1;
184
- j2 = 0;
185
- k2 = 1;
186
- } // X Z Y order
187
- else {
188
- i1 = 0;
189
- j1 = 0;
190
- k1 = 1;
191
- i2 = 1;
192
- j2 = 0;
193
- k2 = 1;
194
- } // Z X Y order
195
- } else { // x0<y0
196
- if (y0 < z0) {
197
- i1 = 0;
198
- j1 = 0;
199
- k1 = 1;
200
- i2 = 0;
201
- j2 = 1;
202
- k2 = 1;
203
- } // Z Y X order
204
- else if (x0 < z0) {
205
- i1 = 0;
206
- j1 = 1;
207
- k1 = 0;
208
- i2 = 0;
209
- j2 = 1;
210
- k2 = 1;
211
- } // Y Z X order
212
- else {
213
- i1 = 0;
214
- j1 = 1;
215
- k1 = 0;
216
- i2 = 1;
217
- j2 = 1;
218
- k2 = 0;
219
- } // Y X Z order
220
- }
221
- // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
222
- // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
223
- // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
224
- // c = 1/6.
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;
234
- // Work out the hashed gradient indices of the four simplex corners
235
- int ii = i & 255;
236
- int jj = j & 255;
237
- int kk = k & 255;
238
- int gi0 = PERM_MOD_12[ii + PERM[jj + PERM[kk]]];
239
- int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1 + PERM[kk + k1]]];
240
- int gi2 = PERM_MOD_12[ii + i2 + PERM[jj + j2 + PERM[kk + k2]]];
241
- int gi3 = PERM_MOD_12[ii + 1 + PERM[jj + 1 + PERM[kk + 1]]];
242
- // Calculate the contribution from the four corners
243
- float t0 = 0.5f - x0 * x0 - y0 * y0 - z0 * z0;
244
- if (t0 < 0) {
245
- n0 = 0.0f;
246
- } else {
247
- t0 *= t0;
248
- n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
249
- }
250
- float t1 = 0.5f - x1 * x1 - y1 * y1 - z1 * z1;
251
- if (t1 < 0) {
252
- n1 = 0.0f;
253
- } else {
254
- t1 *= t1;
255
- n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
256
- }
257
- float t2 = 0.5f - x2 * x2 - y2 * y2 - z2 * z2;
258
- if (t2 < 0) {
259
- n2 = 0.0f;
260
- } else {
261
- t2 *= t2;
262
- n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
263
- }
264
- float t3 = 0.5f - x3 * x3 - y3 * y3 - z3 * z3;
265
- if (t3 < 0) {
266
- n3 = 0.0f;
267
- } else {
268
- t3 *= t3;
269
- n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
270
- }
271
- // Add contributions from each corner to get the final noise value.
272
- // The result is scaled to stay just inside [-1,1]
273
- return 32.0f * (n0 + n1 + n2 + n3);
274
- }
275
-
276
- // 4D simplex noise, better simplex rank ordering method 2012-03-09
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) {
288
-
289
- float n0, n1, n2, n3, n4; // Noise contributions from the five corners
290
- // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
291
- float s = (x + y + z + w) * F4; // Factor for 4D skewing
292
- int i = fastfloor(x + s);
293
- int j = fastfloor(y + s);
294
- int k = fastfloor(z + s);
295
- int l = fastfloor(w + s);
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;
305
- // For the 4D case, the simplex is a 4D shape I won't even try to describe.
306
- // To find out which of the 24 possible simplices we're in, we need to
307
- // determine the magnitude ordering of x0, y0, z0 and w0.
308
- // Six pair-wise comparisons are performed between each possible pair
309
- // of the four coordinates, and the results are used to rank the numbers.
310
- int rankx = 0;
311
- int ranky = 0;
312
- int rankz = 0;
313
- int rankw = 0;
314
- if (x0 > y0) {
315
- rankx++;
316
- } else {
317
- ranky++;
318
- }
319
- if (x0 > z0) {
320
- rankx++;
321
- } else {
322
- rankz++;
323
- }
324
- if (x0 > w0) {
325
- rankx++;
326
- } else {
327
- rankw++;
328
- }
329
- if (y0 > z0) {
330
- ranky++;
331
- } else {
332
- rankz++;
333
- }
334
- if (y0 > w0) {
335
- ranky++;
336
- } else {
337
- rankw++;
338
- }
339
- if (z0 > w0) {
340
- rankz++;
341
- } else {
342
- rankw++;
343
- }
344
- int i1, j1, k1, l1; // The integer offsets for the second simplex corner
345
- int i2, j2, k2, l2; // The integer offsets for the third simplex corner
346
- int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
347
- // [rankx, ranky, rankz, rankw] is a 4-vector with the numbers 0, 1, 2 and 3
348
- // in some order. We use a thresholding to set the coordinates in turn.
349
- // Rank 3 denotes the largest coordinate.
350
- i1 = rankx >= 3 ? 1 : 0;
351
- j1 = ranky >= 3 ? 1 : 0;
352
- k1 = rankz >= 3 ? 1 : 0;
353
- l1 = rankw >= 3 ? 1 : 0;
354
- // Rank 2 denotes the second largest coordinate.
355
- i2 = rankx >= 2 ? 1 : 0;
356
- j2 = ranky >= 2 ? 1 : 0;
357
- k2 = rankz >= 2 ? 1 : 0;
358
- l2 = rankw >= 2 ? 1 : 0;
359
- // Rank 1 denotes the second smallest coordinate.
360
- i3 = rankx >= 1 ? 1 : 0;
361
- j3 = ranky >= 1 ? 1 : 0;
362
- k3 = rankz >= 1 ? 1 : 0;
363
- l3 = rankw >= 1 ? 1 : 0;
364
- // The fifth corner has all coordinate offsets = 1, so no need to compute that.
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;
381
- // Work out the hashed gradient indices of the five simplex corners
382
- int ii = i & 255;
383
- int jj = j & 255;
384
- int kk = k & 255;
385
- int ll = l & 255;
386
- int gi0 = PERM[ii + PERM[jj + PERM[kk + PERM[ll]]]] % 32;
387
- int gi1 = PERM[ii + i1 + PERM[jj + j1 + PERM[kk + k1 + PERM[ll + l1]]]] % 32;
388
- int gi2 = PERM[ii + i2 + PERM[jj + j2 + PERM[kk + k2 + PERM[ll + l2]]]] % 32;
389
- int gi3 = PERM[ii + i3 + PERM[jj + j3 + PERM[kk + k3 + PERM[ll + l3]]]] % 32;
390
- int gi4 = PERM[ii + 1 + PERM[jj + 1 + PERM[kk + 1 + PERM[ll + 1]]]] % 32;
391
- // Calculate the contribution from the five corners
392
- float t0 = 0.5f - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
393
- if (t0 < 0) {
394
- n0 = 0.0f;
395
- } else {
396
- t0 *= t0;
397
- n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
398
- }
399
- float t1 = 0.5f - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
400
- if (t1 < 0) {
401
- n1 = 0.0f;
402
- } else {
403
- t1 *= t1;
404
- n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
405
- }
406
- float t2 = 0.5f - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
407
- if (t2 < 0) {
408
- n2 = 0.0f;
409
- } else {
410
- t2 *= t2;
411
- n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
412
- }
413
- float t3 = 0.5f - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
414
- if (t3 < 0) {
415
- n3 = 0.0f;
416
- } else {
417
- t3 *= t3;
418
- n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
419
- }
420
- float t4 = 0.5f - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
421
- if (t4 < 0) {
422
- n4 = 0.0f;
423
- } else {
424
- t4 *= t4;
425
- n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
426
- }
427
- // Sum up and scale the result to cover the range [-1,1]
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
-
449
- }
450
-
451
- // Inner class to speed upp gradient computations
452
- // (In Java, array access is a lot slower than member access)
453
- private static class Grad {
454
-
455
- float x, y, z, w;
456
-
457
- Grad(float x, float y, float z) {
458
- this.x = x;
459
- this.y = y;
460
- this.z = z;
461
- }
462
-
463
- Grad(float x, float y, float z, float w) {
464
- this.x = x;
465
- this.y = y;
466
- this.z = z;
467
- this.w = w;
468
- }
469
- }
470
- }
@@ -1,170 +0,0 @@
1
- package monkstone.noise;
2
- import java.util.Random;
3
- import monkstone.fastmath.DegLutTables;
4
- import processing.core.PConstants;
5
-
6
- public class ValueNoise implements Noise {
7
-
8
- //////////////////////////////////////////////////////////////
9
- // PROCESSING NOISE, rewritten by cfloutier to change the way cosinus is computed
10
- // [toxi 040903]
11
- // octaves and amplitude amount per octave are now user controlled
12
- // via the noiseDetail() function.
13
- // [toxi 030902]
14
- // cleaned up code and now using bagel's cosine table to speed up
15
- // [toxi 030901]
16
- // implementation by the german demo group farbrausch
17
- // as used in their demo "art": http://www.farb-rausch.de/fr010src.zip
18
- static final int PERLIN_YWRAPB = 4;
19
- static final int PERLIN_YWRAP = 1 << PERLIN_YWRAPB;
20
- static final int PERLIN_ZWRAPB = 8;
21
- static final int PERLIN_ZWRAP = 1 << PERLIN_ZWRAPB;
22
- static final int PERLIN_SIZE = 4095;
23
-
24
- int perlin_octaves = 4; // default to medium smooth
25
- float perlin_amp_falloff = 0.5f; // 50% reduction/octave
26
- int perlin_PI;
27
- static final int PERLIN_TWOPI = 65536;
28
-
29
- //float[] perlin_cosTable;
30
- float[] perlin;
31
-
32
- Random perlinRandom;
33
-
34
- @Override
35
- public float noise(float x) {
36
- return noise(x, 0f, 0f);
37
- }
38
-
39
- @Override
40
- public float noise(float x, float y) {
41
- return noise(x, y, 0f);
42
- }
43
-
44
- private float noise_fsc(float i) {
45
- float cosvalue = DegLutTables.cos(i * PConstants.PI);
46
- return 0.5f * (1.0f - cosvalue);
47
- }
48
-
49
- /**
50
- *
51
- * @param x
52
- * @param y
53
- * @param z
54
- * @return
55
- */
56
- @Override
57
- public float noise(float x, float y, float z) {
58
- if (perlin == null) {
59
- if (perlinRandom == null) {
60
- perlinRandom = new Random();
61
- }
62
- perlin = new float[PERLIN_SIZE + 1];
63
- for (int i = 0; i < PERLIN_SIZE + 1; i++) {
64
- perlin[i] = perlinRandom.nextFloat();
65
- }
66
- }
67
-
68
- if (x < 0) {
69
- x = -x;
70
- }
71
- if (y < 0) {
72
- y = -y;
73
- }
74
- if (z < 0) {
75
- z = -z;
76
- }
77
-
78
- int xi = (int) x, yi = (int) y, zi = (int) z;
79
- float xf = x - xi;
80
- float yf = y - yi;
81
- float zf = z - zi;
82
- float rxf, ryf;
83
-
84
- float r = 0;
85
- float ampl = 0.5f;
86
-
87
- float n1, n2, n3;
88
-
89
- for (int i = 0; i < perlin_octaves; i++) {
90
- int of = xi + (yi << PERLIN_YWRAPB) + (zi << PERLIN_ZWRAPB);
91
-
92
- rxf = noise_fsc(xf);
93
- ryf = noise_fsc(yf);
94
-
95
- n1 = perlin[of & PERLIN_SIZE];
96
- n1 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n1);
97
- n2 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
98
- n2 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n2);
99
- n1 += ryf * (n2 - n1);
100
-
101
- of += PERLIN_ZWRAP;
102
- n2 = perlin[of & PERLIN_SIZE];
103
- n2 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n2);
104
- n3 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
105
- n3 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n3);
106
- n2 += ryf * (n3 - n2);
107
-
108
- n1 += noise_fsc(zf) * (n2 - n1);
109
-
110
- r += n1 * ampl;
111
- ampl *= perlin_amp_falloff;
112
- xi <<= 1;
113
- xf *= 2;
114
- yi <<= 1;
115
- yf *= 2;
116
- zi <<= 1;
117
- zf *= 2;
118
-
119
- if (xf >= 1.0f) {
120
- xi++;
121
- xf--;
122
- }
123
- if (yf >= 1.0f) {
124
- yi++;
125
- yf--;
126
- }
127
- if (zf >= 1.0f) {
128
- zi++;
129
- zf--;
130
- }
131
- }
132
- return r;
133
- }
134
-
135
- @Override
136
- public void noiseMode(NoiseMode mode) {
137
-
138
- }
139
-
140
- @Override
141
- public void noiseDetail(int lod) {
142
- if (lod > 0) {
143
- perlin_octaves = lod;
144
- }
145
- }
146
-
147
- @Override
148
- public void noiseDetail(int lod, float falloff) {
149
- if (lod > 0) {
150
- perlin_octaves = lod;
151
- }
152
- if (falloff > 0) {
153
- perlin_amp_falloff = falloff;
154
- }
155
- }
156
-
157
- @Override
158
- public void noiseSeed(long seed) {
159
- if (perlinRandom == null) {
160
- perlinRandom = new Random();
161
- }
162
- perlinRandom.setSeed(seed);
163
- perlin = null;
164
- }
165
-
166
- @Override
167
- public float noise(float x, float y, float z, float w) {
168
- throw new UnsupportedOperationException("Not supported yet.");
169
- }
170
- }