picrate 2.1.0-java → 2.4.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/CHANGELOG.md +10 -0
  6. data/README.md +6 -3
  7. data/Rakefile +2 -1
  8. data/docs/_includes/footer.html +1 -1
  9. data/docs/_layouts/post.html +1 -1
  10. data/docs/_methods/alternative_methods.md +2 -1
  11. data/docs/_methods/noise_mode.md +88 -0
  12. data/docs/_posts/2018-05-06-install_jruby.md +3 -3
  13. data/docs/_posts/2018-11-18-building-gem.md +3 -1
  14. data/docs/_posts/2020-03-09-auto_install_picrate.md +2 -3
  15. data/docs/_posts/2020-05-11-getting_started_manjaro.md +19 -7
  16. data/docs/classes.md +2 -2
  17. data/docs/editors.md +2 -2
  18. data/docs/gems.md +3 -3
  19. data/docs/index.html +1 -1
  20. data/docs/libraries.md +2 -2
  21. data/docs/live.md +2 -2
  22. data/docs/magic.md +2 -2
  23. data/docs/methods.md +2 -2
  24. data/docs/modules.md +3 -3
  25. data/docs/objects.md +2 -2
  26. data/lib/picrate.rb +2 -1
  27. data/lib/picrate/app.rb +3 -2
  28. data/lib/picrate/helper_methods.rb +1 -1
  29. data/lib/picrate/native_folder.rb +1 -3
  30. data/lib/picrate/runner.rb +4 -4
  31. data/lib/picrate/version.rb +1 -1
  32. data/library/jcomplex/jcomplex.rb +1 -0
  33. data/library/pdf/pdf.rb +7 -0
  34. data/library/svg/svg.rb +7 -0
  35. data/mvnw +2 -2
  36. data/mvnw.cmd +2 -2
  37. data/picrate.gemspec +5 -3
  38. data/pom.rb +31 -9
  39. data/pom.xml +41 -6
  40. data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
  41. data/src/main/java/monkstone/PicrateLibrary.java +3 -1
  42. data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
  43. data/src/main/java/monkstone/complex/JComplex.java +252 -0
  44. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  45. data/src/main/java/monkstone/fastmath/Deglut.java +41 -93
  46. data/src/main/java/monkstone/noise/OpenSimplex2F.java +813 -0
  47. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
  48. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  49. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  50. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  51. data/src/main/java/processing/awt/ShimAWT.java +260 -94
  52. data/src/main/java/processing/core/PApplet.java +14664 -13450
  53. data/src/main/java/processing/core/PConstants.java +5 -5
  54. data/src/main/java/processing/core/PFont.java +1 -1
  55. data/src/main/java/processing/core/PGraphics.java +200 -201
  56. data/src/main/java/processing/core/PImage.java +539 -549
  57. data/src/main/java/processing/core/PShape.java +18 -18
  58. data/src/main/java/processing/core/PVector.java +23 -23
  59. data/src/main/java/processing/data/Table.java +4 -4
  60. data/src/main/java/processing/net/Client.java +13 -13
  61. data/src/main/java/processing/net/Server.java +5 -5
  62. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +4 -4
  63. data/src/main/java/processing/pdf/PGraphicsPDF.java +529 -0
  64. data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
  65. data/test/deglut_spec_test.rb +2 -2
  66. data/test/respond_to_test.rb +0 -2
  67. data/vendors/Rakefile +31 -22
  68. data/vendors/geany.rb +3 -3
  69. metadata +26 -13
  70. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -465
data/vendors/geany.rb CHANGED
@@ -25,7 +25,7 @@ indent_mode=2
25
25
 
26
26
  [project]
27
27
  name=picrate_samples
28
- base_path=<%= home %>
28
+ base_path=examples
29
29
  description=Exploring PiCrate
30
30
  file_patterns=*.rb;*.glsl;*.txt;
31
31
 
@@ -69,9 +69,9 @@ class GeanyConfig
69
69
  include ERB::Util
70
70
  attr_accessor :home, :directory, :template
71
71
 
72
- def initialize(home, directory, template = geany_config)
72
+ def initialize(directory, template = geany_config)
73
73
  @home = home
74
- @directory = File.join(home, directory)
74
+ @directory = directory
75
75
  @template = template
76
76
  end
77
77
 
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.4.0
5
5
  platform: java
6
6
  authors:
7
7
  - monkstone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '5.10'
18
+ version: '5.14'
19
19
  name: minitest
20
- type: :development
21
20
  prerelease: false
21
+ type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.10'
26
+ version: '5.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '12.3'
32
+ version: '13.0'
33
33
  name: rake
34
- type: :development
35
34
  prerelease: false
35
+ type: :runtime
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '12.3'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
@@ -48,8 +48,8 @@ dependencies:
48
48
  - !ruby/object:Gem::Version
49
49
  version: 1.0.1
50
50
  name: arcball
51
- type: :runtime
52
51
  prerelease: false
52
+ type: :runtime
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
@@ -130,6 +130,7 @@ files:
130
130
  - docs/_methods/map1d.md
131
131
  - docs/_methods/methods_summary.md
132
132
  - docs/_methods/mouse_pressed.md
133
+ - docs/_methods/noise_mode.md
133
134
  - docs/_methods/post_initialize.md
134
135
  - docs/_methods/processing_api.md
135
136
  - docs/_methods/settings.md
@@ -190,7 +191,7 @@ files:
190
191
  - lib/jogl-all-natives-linux-amd64.jar
191
192
  - lib/jogl-all-natives-linux-armv6hf.jar
192
193
  - lib/jogl-all.jar
193
- - lib/picrate-2.1.0.jar
194
+ - lib/picrate-2.4.0.jar
194
195
  - lib/picrate.rb
195
196
  - lib/picrate/app.rb
196
197
  - lib/picrate/creators/parameters.rb
@@ -209,10 +210,15 @@ files:
209
210
  - library/color_group/color_group.rb
210
211
  - library/control_panel/control_panel.rb
211
212
  - library/dxf/dxf.rb
213
+ - library/jcomplex/jcomplex.rb
212
214
  - library/library_proxy/README.md
213
215
  - library/library_proxy/library_proxy.rb
214
216
  - library/net/net.rb
217
+ - library/pdf/itextpdf-5.5.13.2.jar
218
+ - library/pdf/pdf.rb
215
219
  - library/slider/slider.rb
220
+ - library/svg/batik-all-1.14.jar
221
+ - library/svg/svg.rb
216
222
  - library/vector_utils/vector_utils.rb
217
223
  - library/video_event/video_event.rb
218
224
  - license.txt
@@ -224,13 +230,18 @@ files:
224
230
  - src/main/java/japplemenubar/JAppleMenuBar.java
225
231
  - src/main/java/japplemenubar/libjAppleMenuBar.jnilib
226
232
  - src/main/java/monkstone/ColorUtil.java
233
+ - src/main/java/monkstone/FastNoiseModuleJava.java
227
234
  - src/main/java/monkstone/MathToolModule.java
228
235
  - src/main/java/monkstone/PicrateLibrary.java
236
+ - src/main/java/monkstone/SmoothNoiseModuleJava.java
237
+ - src/main/java/monkstone/complex/JComplex.java
229
238
  - src/main/java/monkstone/core/LibraryProxy.java
239
+ - src/main/java/monkstone/fastmath/DegLutTables.java
230
240
  - src/main/java/monkstone/fastmath/Deglut.java
231
241
  - src/main/java/monkstone/fastmath/package-info.java
232
242
  - src/main/java/monkstone/filechooser/Chooser.java
233
- - src/main/java/monkstone/noise/SimplexNoise.java
243
+ - src/main/java/monkstone/noise/OpenSimplex2F.java
244
+ - src/main/java/monkstone/noise/OpenSimplex2S.java
234
245
  - src/main/java/monkstone/slider/CustomHorizontalSlider.java
235
246
  - src/main/java/monkstone/slider/CustomVerticalSlider.java
236
247
  - src/main/java/monkstone/slider/SimpleHorizontalSlider.java
@@ -327,6 +338,8 @@ files:
327
338
  - src/main/java/processing/opengl/shaders/TexLightFrag.glsl
328
339
  - src/main/java/processing/opengl/shaders/TexLightVert.glsl
329
340
  - src/main/java/processing/opengl/shaders/TexVert.glsl
341
+ - src/main/java/processing/pdf/PGraphicsPDF.java
342
+ - src/main/java/processing/svg/PGraphicsSVG.java
330
343
  - src/main/resources/icon/icon-128.png
331
344
  - src/main/resources/icon/icon-16.png
332
345
  - src/main/resources/icon/icon-256.png
@@ -367,8 +380,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
367
380
  - !ruby/object:Gem::Version
368
381
  version: '0'
369
382
  requirements:
370
- - java runtime == 11
371
- rubygems_version: 3.0.6
383
+ - java runtime == 11+
384
+ rubygems_version: 3.1.6
372
385
  signing_key:
373
386
  specification_version: 4
374
387
  summary: ruby implementation of processing-3 on raspberrypi and linux64
@@ -1,465 +0,0 @@
1
- /*
2
- * A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
3
- *
4
- * Based on example code by Stefan Gustavson (stegu@itn.liu.se).
5
- * Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
6
- * Better rank ordering method for 4D by Stefan Gustavson in 2012.
7
- *
8
- * This could be speeded up even further, but it's useful as it is.
9
- *
10
- * Version 2012-03-09
11
- *
12
- * This code was placed in the public domain by its original author,
13
- * Stefan Gustavson. You may use it as you see fit, but
14
- * attribution is appreciated.
15
- *
16
- */
17
-
18
- package monkstone.noise;
19
-
20
- /**
21
- *
22
- * @author Martin Prout
23
- */
24
- public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
25
-
26
- private static Grad grad3[] = {new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0),
27
- new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1),
28
- new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)};
29
-
30
- 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),
31
- new Grad(0, -1, 1, 1), new Grad(0, -1, 1, -1), new Grad(0, -1, -1, 1), new Grad(0, -1, -1, -1),
32
- new Grad(1, 0, 1, 1), new Grad(1, 0, 1, -1), new Grad(1, 0, -1, 1), new Grad(1, 0, -1, -1),
33
- new Grad(-1, 0, 1, 1), new Grad(-1, 0, 1, -1), new Grad(-1, 0, -1, 1), new Grad(-1, 0, -1, -1),
34
- new Grad(1, 1, 0, 1), new Grad(1, 1, 0, -1), new Grad(1, -1, 0, 1), new Grad(1, -1, 0, -1),
35
- new Grad(-1, 1, 0, 1), new Grad(-1, 1, 0, -1), new Grad(-1, -1, 0, 1), new Grad(-1, -1, 0, -1),
36
- new Grad(1, 1, 1, 0), new Grad(1, 1, -1, 0), new Grad(1, -1, 1, 0), new Grad(1, -1, -1, 0),
37
- new Grad(-1, 1, 1, 0), new Grad(-1, 1, -1, 0), new Grad(-1, -1, 1, 0), new Grad(-1, -1, -1, 0)};
38
-
39
- private final static short PERMS[] = {151, 160, 137, 91, 90, 15,
40
- 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
41
- 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
42
- 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
43
- 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
44
- 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
45
- 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123,
46
- 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
47
- 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
48
- 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
49
- 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
50
- 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
51
- 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
52
- // To remove the need for index wrapping, double the permutation table length
53
- static final short[] PERM = new short[512];
54
- static final short[] PERM_MOD_12 = new short[512];
55
-
56
- static {
57
- for (int i = 0; i < 512; i++) {
58
- PERM[i] = PERMS[i & 255];
59
- PERM_MOD_12[i] = (short) (PERM[i] % 12);
60
- }
61
- }
62
-
63
- // Skewing and unskewing factors for 2, 3, and 4 dimensions
64
- private static final double F2 = 0.5 * (Math.sqrt(3.0) - 1.0);
65
- private static final double G2 = (3.0 - Math.sqrt(3.0)) / 6.0;
66
- private static final double F3 = 1.0 / 3.0;
67
- private static final double G3 = 1.0 / 6.0;
68
- private static final double F4 = (Math.sqrt(5.0) - 1.0) / 4.0;
69
- private static final double G4 = (5.0 - Math.sqrt(5.0)) / 20.0;
70
-
71
- // This method is a *lot* faster than using (int)Math.floor(x)
72
- private static int fastfloor(double x) {
73
- int xi = (int) x;
74
- return x < xi ? xi - 1 : xi;
75
- }
76
-
77
- private static double dot(Grad g, double x, double y) {
78
- return g.x * x + g.y * y;
79
- }
80
-
81
- private static double dot(Grad g, double x, double y, double z) {
82
- return g.x * x + g.y * y + g.z * z;
83
- }
84
-
85
- private static double dot(Grad g, double x, double y, double z, double w) {
86
- return g.x * x + g.y * y + g.z * z + g.w * w;
87
- }
88
-
89
- // 2D simplex noise
90
-
91
- /**
92
- *
93
- * @param xin
94
- * @param yin
95
- * @return noise double
96
- */
97
- public static double noise(double xin, double yin) {
98
- double n0, n1, n2; // Noise contributions from the three corners
99
- // Skew the input space to determine which simplex cell we're in
100
- double s = (xin + yin) * F2; // Hairy factor for 2D
101
- int i = fastfloor(xin + s);
102
- int j = fastfloor(yin + s);
103
- double t = (i + j) * G2;
104
- double X0 = i - t; // Unskew the cell origin back to (x,y) space
105
- double Y0 = j - t;
106
- double x0 = xin - X0; // The x,y distances from the cell origin
107
- double y0 = yin - Y0;
108
- // For the 2D case, the simplex shape is an equilateral triangle.
109
- // Determine which simplex we are in.
110
- int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
111
- if (x0 > y0) {
112
- i1 = 1;
113
- j1 = 0;
114
- } // lower triangle, XY order: (0,0)->(1,0)->(1,1)
115
- else {
116
- i1 = 0;
117
- j1 = 1;
118
- } // upper triangle, YX order: (0,0)->(0,1)->(1,1)
119
- // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
120
- // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
121
- // c = (3-sqrt(3))/6
122
- double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
123
- double y1 = y0 - j1 + G2;
124
- double x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords
125
- double y2 = y0 - 1.0 + 2.0 * G2;
126
- // Work out the hashed gradient indices of the three simplex corners
127
- int ii = i & 255;
128
- int jj = j & 255;
129
- int gi0 = PERM_MOD_12[ii + PERM[jj]];
130
- int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1]];
131
- int gi2 = PERM_MOD_12[ii + 1 + PERM[jj + 1]];
132
- // Calculate the contribution from the three corners
133
- double t0 = 0.5 - x0 * x0 - y0 * y0;
134
- if (t0 < 0) {
135
- n0 = 0.0;
136
- } else {
137
- t0 *= t0;
138
- n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
139
- }
140
- double t1 = 0.5 - x1 * x1 - y1 * y1;
141
- if (t1 < 0) {
142
- n1 = 0.0;
143
- } else {
144
- t1 *= t1;
145
- n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
146
- }
147
- double t2 = 0.5 - x2 * x2 - y2 * y2;
148
- if (t2 < 0) {
149
- n2 = 0.0;
150
- } else {
151
- t2 *= t2;
152
- n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
153
- }
154
- // Add contributions from each corner to get the final noise value.
155
- // The result is scaled to return values in the interval [-1,1].
156
- return 70.0 * (n0 + n1 + n2);
157
- }
158
-
159
- // 3D simplex noise
160
-
161
- /**
162
- *
163
- * @param xin
164
- * @param yin
165
- * @param zin
166
- * @return
167
- */
168
- public static double noise(double xin, double yin, double zin) {
169
- double n0, n1, n2, n3; // Noise contributions from the four corners
170
- // Skew the input space to determine which simplex cell we're in
171
- double s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D
172
- int i = fastfloor(xin + s);
173
- int j = fastfloor(yin + s);
174
- int k = fastfloor(zin + s);
175
- double t = (i + j + k) * G3;
176
- double X0 = i - t; // Unskew the cell origin back to (x,y,z) space
177
- double Y0 = j - t;
178
- double Z0 = k - t;
179
- double x0 = xin - X0; // The x,y,z distances from the cell origin
180
- double y0 = yin - Y0;
181
- double z0 = zin - Z0;
182
- // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
183
- // Determine which simplex we are in.
184
- int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
185
- int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
186
- if (x0 >= y0) {
187
- if (y0 >= z0) {
188
- i1 = 1;
189
- j1 = 0;
190
- k1 = 0;
191
- i2 = 1;
192
- j2 = 1;
193
- k2 = 0;
194
- } // X Y Z order
195
- else if (x0 >= z0) {
196
- i1 = 1;
197
- j1 = 0;
198
- k1 = 0;
199
- i2 = 1;
200
- j2 = 0;
201
- k2 = 1;
202
- } // X Z Y order
203
- else {
204
- i1 = 0;
205
- j1 = 0;
206
- k1 = 1;
207
- i2 = 1;
208
- j2 = 0;
209
- k2 = 1;
210
- } // Z X Y order
211
- } else { // x0<y0
212
- if (y0 < z0) {
213
- i1 = 0;
214
- j1 = 0;
215
- k1 = 1;
216
- i2 = 0;
217
- j2 = 1;
218
- k2 = 1;
219
- } // Z Y X order
220
- else if (x0 < z0) {
221
- i1 = 0;
222
- j1 = 1;
223
- k1 = 0;
224
- i2 = 0;
225
- j2 = 1;
226
- k2 = 1;
227
- } // Y Z X order
228
- else {
229
- i1 = 0;
230
- j1 = 1;
231
- k1 = 0;
232
- i2 = 1;
233
- j2 = 1;
234
- k2 = 0;
235
- } // Y X Z order
236
- }
237
- // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
238
- // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
239
- // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
240
- // c = 1/6.
241
- double x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
242
- double y1 = y0 - j1 + G3;
243
- double z1 = z0 - k1 + G3;
244
- double x2 = x0 - i2 + 2.0 * G3; // Offsets for third corner in (x,y,z) coords
245
- double y2 = y0 - j2 + 2.0 * G3;
246
- double z2 = z0 - k2 + 2.0 * G3;
247
- double x3 = x0 - 1.0 + 3.0 * G3; // Offsets for last corner in (x,y,z) coords
248
- double y3 = y0 - 1.0 + 3.0 * G3;
249
- double z3 = z0 - 1.0 + 3.0 * G3;
250
- // Work out the hashed gradient indices of the four simplex corners
251
- int ii = i & 255;
252
- int jj = j & 255;
253
- int kk = k & 255;
254
- int gi0 = PERM_MOD_12[ii + PERM[jj + PERM[kk]]];
255
- int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1 + PERM[kk + k1]]];
256
- int gi2 = PERM_MOD_12[ii + i2 + PERM[jj + j2 + PERM[kk + k2]]];
257
- int gi3 = PERM_MOD_12[ii + 1 + PERM[jj + 1 + PERM[kk + 1]]];
258
- // Calculate the contribution from the four corners
259
- double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;
260
- if (t0 < 0) {
261
- n0 = 0.0;
262
- } else {
263
- t0 *= t0;
264
- n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
265
- }
266
- double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;
267
- if (t1 < 0) {
268
- n1 = 0.0;
269
- } else {
270
- t1 *= t1;
271
- n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
272
- }
273
- double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;
274
- if (t2 < 0) {
275
- n2 = 0.0;
276
- } else {
277
- t2 *= t2;
278
- n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
279
- }
280
- double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;
281
- if (t3 < 0) {
282
- n3 = 0.0;
283
- } else {
284
- t3 *= t3;
285
- n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
286
- }
287
- // Add contributions from each corner to get the final noise value.
288
- // The result is scaled to stay just inside [-1,1]
289
- return 32.0 * (n0 + n1 + n2 + n3);
290
- }
291
-
292
- // 4D simplex noise, better simplex rank ordering method 2012-03-09
293
-
294
- /**
295
- *
296
- * @param x
297
- * @param y
298
- * @param z
299
- * @param w
300
- * @return noise double
301
- */
302
- public static double noise(double x, double y, double z, double w) {
303
-
304
- double n0, n1, n2, n3, n4; // Noise contributions from the five corners
305
- // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
306
- double s = (x + y + z + w) * F4; // Factor for 4D skewing
307
- int i = fastfloor(x + s);
308
- int j = fastfloor(y + s);
309
- int k = fastfloor(z + s);
310
- int l = fastfloor(w + s);
311
- double t = (i + j + k + l) * G4; // Factor for 4D unskewing
312
- double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
313
- double Y0 = j - t;
314
- double Z0 = k - t;
315
- double W0 = l - t;
316
- double x0 = x - X0; // The x,y,z,w distances from the cell origin
317
- double y0 = y - Y0;
318
- double z0 = z - Z0;
319
- double w0 = w - W0;
320
- // For the 4D case, the simplex is a 4D shape I won't even try to describe.
321
- // To find out which of the 24 possible simplices we're in, we need to
322
- // determine the magnitude ordering of x0, y0, z0 and w0.
323
- // Six pair-wise comparisons are performed between each possible pair
324
- // of the four coordinates, and the results are used to rank the numbers.
325
- int rankx = 0;
326
- int ranky = 0;
327
- int rankz = 0;
328
- int rankw = 0;
329
- if (x0 > y0) {
330
- rankx++;
331
- } else {
332
- ranky++;
333
- }
334
- if (x0 > z0) {
335
- rankx++;
336
- } else {
337
- rankz++;
338
- }
339
- if (x0 > w0) {
340
- rankx++;
341
- } else {
342
- rankw++;
343
- }
344
- if (y0 > z0) {
345
- ranky++;
346
- } else {
347
- rankz++;
348
- }
349
- if (y0 > w0) {
350
- ranky++;
351
- } else {
352
- rankw++;
353
- }
354
- if (z0 > w0) {
355
- rankz++;
356
- } else {
357
- rankw++;
358
- }
359
- int i1, j1, k1, l1; // The integer offsets for the second simplex corner
360
- int i2, j2, k2, l2; // The integer offsets for the third simplex corner
361
- int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
362
- // [rankx, ranky, rankz, rankw] is a 4-vector with the numbers 0, 1, 2 and 3
363
- // in some order. We use a thresholding to set the coordinates in turn.
364
- // Rank 3 denotes the largest coordinate.
365
- i1 = rankx >= 3 ? 1 : 0;
366
- j1 = ranky >= 3 ? 1 : 0;
367
- k1 = rankz >= 3 ? 1 : 0;
368
- l1 = rankw >= 3 ? 1 : 0;
369
- // Rank 2 denotes the second largest coordinate.
370
- i2 = rankx >= 2 ? 1 : 0;
371
- j2 = ranky >= 2 ? 1 : 0;
372
- k2 = rankz >= 2 ? 1 : 0;
373
- l2 = rankw >= 2 ? 1 : 0;
374
- // Rank 1 denotes the second smallest coordinate.
375
- i3 = rankx >= 1 ? 1 : 0;
376
- j3 = ranky >= 1 ? 1 : 0;
377
- k3 = rankz >= 1 ? 1 : 0;
378
- l3 = rankw >= 1 ? 1 : 0;
379
- // The fifth corner has all coordinate offsets = 1, so no need to compute that.
380
- double x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
381
- double y1 = y0 - j1 + G4;
382
- double z1 = z0 - k1 + G4;
383
- double w1 = w0 - l1 + G4;
384
- double x2 = x0 - i2 + 2.0 * G4; // Offsets for third corner in (x,y,z,w) coords
385
- double y2 = y0 - j2 + 2.0 * G4;
386
- double z2 = z0 - k2 + 2.0 * G4;
387
- double w2 = w0 - l2 + 2.0 * G4;
388
- double x3 = x0 - i3 + 3.0 * G4; // Offsets for fourth corner in (x,y,z,w) coords
389
- double y3 = y0 - j3 + 3.0 * G4;
390
- double z3 = z0 - k3 + 3.0 * G4;
391
- double w3 = w0 - l3 + 3.0 * G4;
392
- double x4 = x0 - 1.0 + 4.0 * G4; // Offsets for last corner in (x,y,z,w) coords
393
- double y4 = y0 - 1.0 + 4.0 * G4;
394
- double z4 = z0 - 1.0 + 4.0 * G4;
395
- double w4 = w0 - 1.0 + 4.0 * G4;
396
- // Work out the hashed gradient indices of the five simplex corners
397
- int ii = i & 255;
398
- int jj = j & 255;
399
- int kk = k & 255;
400
- int ll = l & 255;
401
- int gi0 = PERM[ii + PERM[jj + PERM[kk + PERM[ll]]]] % 32;
402
- int gi1 = PERM[ii + i1 + PERM[jj + j1 + PERM[kk + k1 + PERM[ll + l1]]]] % 32;
403
- int gi2 = PERM[ii + i2 + PERM[jj + j2 + PERM[kk + k2 + PERM[ll + l2]]]] % 32;
404
- int gi3 = PERM[ii + i3 + PERM[jj + j3 + PERM[kk + k3 + PERM[ll + l3]]]] % 32;
405
- int gi4 = PERM[ii + 1 + PERM[jj + 1 + PERM[kk + 1 + PERM[ll + 1]]]] % 32;
406
- // Calculate the contribution from the five corners
407
- double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
408
- if (t0 < 0) {
409
- n0 = 0.0;
410
- } else {
411
- t0 *= t0;
412
- n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
413
- }
414
- double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
415
- if (t1 < 0) {
416
- n1 = 0.0;
417
- } else {
418
- t1 *= t1;
419
- n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
420
- }
421
- double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
422
- if (t2 < 0) {
423
- n2 = 0.0;
424
- } else {
425
- t2 *= t2;
426
- n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
427
- }
428
- double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
429
- if (t3 < 0) {
430
- n3 = 0.0;
431
- } else {
432
- t3 *= t3;
433
- n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
434
- }
435
- double t4 = 0.5 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
436
- if (t4 < 0) {
437
- n4 = 0.0;
438
- } else {
439
- t4 *= t4;
440
- n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
441
- }
442
- // Sum up and scale the result to cover the range [-1,1]
443
- return 27.0 * (n0 + n1 + n2 + n3 + n4);
444
- }
445
-
446
- // Inner class to speed upp gradient computations
447
- // (In Java, array access is a lot slower than member access)
448
- private static class Grad {
449
-
450
- double x, y, z, w;
451
-
452
- Grad(double x, double y, double z) {
453
- this.x = x;
454
- this.y = y;
455
- this.z = z;
456
- }
457
-
458
- Grad(double x, double y, double z, double w) {
459
- this.x = x;
460
- this.y = y;
461
- this.z = z;
462
- this.w = w;
463
- }
464
- }
465
- }