picrate 2.3.0-java → 2.5.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/docs/.gitignore +1 -0
- data/docs/_classes/{app_render → gfx_render}/app_render.md +5 -5
- data/docs/_methods/{noise_mode.md → noise_modes.md} +9 -21
- data/docs/_posts/2018-05-06-install_jruby.md +5 -5
- data/docs/_posts/2019-11-11-getting_started_buster.md +1 -1
- data/lib/picrate/app.rb +3 -7
- data/lib/picrate/native_folder.rb +1 -1
- data/lib/picrate/version.rb +1 -1
- data/lib/{picrate-2.3.0.jar → picrate-2.5.0.jar} +0 -0
- data/{lib → library/pdf}/itextpdf-5.5.13.2.jar +0 -0
- data/library/pdf/pdf.rb +1 -0
- data/library/svg/batik-all-1.14.jar +0 -0
- data/library/svg/svg.rb +7 -0
- data/picrate.gemspec +4 -3
- data/pom.rb +19 -10
- data/pom.xml +19 -6
- data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/PicrateLibrary.java +2 -0
- data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/noise/OpenSimplex2F.java +62 -29
- data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -1106
- data/src/main/java/monkstone/vecmath/GfxRender.java +10 -11
- data/src/main/java/monkstone/vecmath/JRender.java +7 -7
- data/src/main/java/monkstone/vecmath/ShapeRender.java +3 -4
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +28 -40
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +30 -45
- data/src/main/java/processing/awt/PImageAWT.java +1 -1
- data/src/main/java/processing/awt/ShimAWT.java +1 -1
- data/src/main/java/processing/core/PApplet.java +1 -92
- data/src/main/java/processing/core/PImage.java +14 -14
- data/src/main/java/processing/opengl/PShader.java +0 -6
- data/src/main/java/processing/pdf/PGraphicsPDF.java +61 -139
- data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
- data/test/noise_test.rb +17 -0
- data/test/respond_to_test.rb +0 -1
- data/test/test_helper.rb +1 -1
- data/vendors/Rakefile +1 -1
- metadata +21 -32
- data/src/main/java/japplemenubar/JAppleMenuBar.java +0 -96
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/complex/JComplex.java +0 -252
- data/src/main/java/monkstone/noise/FastTerrain.java +0 -874
- data/src/main/java/monkstone/noise/Noise.java +0 -90
- data/src/main/java/monkstone/noise/NoiseGenerator.java +0 -75
- data/src/main/java/monkstone/noise/NoiseMode.java +0 -28
- data/src/main/java/monkstone/noise/SmoothTerrain.java +0 -1099
- data/src/main/java/monkstone/vecmath/AppRender.java +0 -88
- data/src/main/java/monkstone/vecmath/package-info.java +0 -20
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +0 -6
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +0 -6
@@ -0,0 +1,127 @@
|
|
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;
|
7
|
+
|
8
|
+
import monkstone.noise.OpenSimplex2S;
|
9
|
+
import org.jruby.Ruby;
|
10
|
+
import org.jruby.RubyFixnum;
|
11
|
+
import org.jruby.RubyFloat;
|
12
|
+
import org.jruby.RubyModule;
|
13
|
+
import org.jruby.anno.JRubyMethod;
|
14
|
+
import org.jruby.anno.JRubyModule;
|
15
|
+
import org.jruby.runtime.ThreadContext;
|
16
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
17
|
+
|
18
|
+
/**
|
19
|
+
*
|
20
|
+
* @author Martin Prout
|
21
|
+
*/
|
22
|
+
@JRubyModule(name = "SmoothNoise")
|
23
|
+
public class SmoothNoiseModuleJava {
|
24
|
+
|
25
|
+
static OpenSimplex2S ng = new OpenSimplex2S(System.currentTimeMillis());
|
26
|
+
|
27
|
+
/**
|
28
|
+
*
|
29
|
+
* @param runtime Ruby
|
30
|
+
*/
|
31
|
+
public static void createNoiseModule(Ruby runtime) {
|
32
|
+
RubyModule noiseModule = runtime.defineModule("SmoothNoise");
|
33
|
+
noiseModule.defineAnnotatedMethods(SmoothNoiseModuleJava.class);
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
*
|
38
|
+
* @param context ThreadContext
|
39
|
+
* @param recv IRubyObject
|
40
|
+
* @param args array of numeric values
|
41
|
+
* @return mapped value RubyFloat
|
42
|
+
*/
|
43
|
+
@JRubyMethod(name = "tnoise", rest = true, module = true)
|
44
|
+
public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
45
|
+
double result = 0;
|
46
|
+
double one;
|
47
|
+
double two;
|
48
|
+
double three;
|
49
|
+
double four;
|
50
|
+
switch (args.length) {
|
51
|
+
case 2:
|
52
|
+
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
53
|
+
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
54
|
+
result = ng.noise2_XBeforeY(one, two);
|
55
|
+
break;
|
56
|
+
case 3:
|
57
|
+
three = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
58
|
+
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
59
|
+
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
60
|
+
result = ng.noise3_XYBeforeZ(one, two, three);
|
61
|
+
break;
|
62
|
+
case 4:
|
63
|
+
four = args[3] instanceof RubyFloat ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
|
64
|
+
three = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
65
|
+
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
66
|
+
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
67
|
+
result = ng.noise4_XYBeforeZW(one, two, three, four);
|
68
|
+
break;
|
69
|
+
default:
|
70
|
+
throw new RuntimeException("Min 2D Max 4D Noise");
|
71
|
+
}
|
72
|
+
return RubyFloat.newFloat(context.runtime, result);
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
*
|
77
|
+
* @param context ThreadContext
|
78
|
+
* @param recv IRubyObject
|
79
|
+
* @param args array of numeric values
|
80
|
+
* @return mapped value RubyFloat
|
81
|
+
*/
|
82
|
+
@JRubyMethod(name = "noise", rest = true, module = true)
|
83
|
+
public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
84
|
+
double result = 0;
|
85
|
+
double one;
|
86
|
+
double two;
|
87
|
+
double three;
|
88
|
+
double four;
|
89
|
+
switch (args.length) {
|
90
|
+
case 1:
|
91
|
+
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
92
|
+
result = ng.noise2(one, 0);
|
93
|
+
break;
|
94
|
+
case 2:
|
95
|
+
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
96
|
+
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
97
|
+
result = ng.noise2(one, two);
|
98
|
+
break;
|
99
|
+
case 3:
|
100
|
+
three = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
101
|
+
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
102
|
+
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
103
|
+
result = ng.noise3_Classic(one, two, three);
|
104
|
+
break;
|
105
|
+
case 4:
|
106
|
+
four = args[3] instanceof RubyFloat ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
|
107
|
+
three = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
108
|
+
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
109
|
+
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
110
|
+
result = ng.noise4_Classic(one, two, three, four);
|
111
|
+
break;
|
112
|
+
default:
|
113
|
+
throw new RuntimeException("Maximum of 4D Noise");
|
114
|
+
}
|
115
|
+
return RubyFloat.newFloat(context.runtime, result);
|
116
|
+
}
|
117
|
+
// @JRubyMethod(name = "noise_seed", rest = true, module = true)
|
118
|
+
// public static IRubyObject noiseSeedImpl(ThreadContext context, IRubyObject recv, IRubyObject arg) {
|
119
|
+
// long seed;
|
120
|
+
// if (arg instanceof RubyNumeric) {
|
121
|
+
// seed = ((RubyNumeric) arg).getLongValue();
|
122
|
+
// ng = new OpenSimplex2S(seed);
|
123
|
+
// return RubyBoolean.newBoolean(context.runtime, true);
|
124
|
+
// }
|
125
|
+
// return RubyBoolean.newBoolean(context.runtime, false);
|
126
|
+
// }
|
127
|
+
}
|
@@ -11,7 +11,7 @@ package monkstone.noise;
|
|
11
11
|
* Multiple versions of each function are provided. See the documentation above
|
12
12
|
* each, for more info.
|
13
13
|
*/
|
14
|
-
public class OpenSimplex2F
|
14
|
+
public class OpenSimplex2F {
|
15
15
|
|
16
16
|
private static final int PSIZE = 2048;
|
17
17
|
private static final int PMASK = 2047;
|
@@ -21,6 +21,10 @@ public class OpenSimplex2F implements Noise {
|
|
21
21
|
private final Grad3[] permGrad3;
|
22
22
|
private final Grad4[] permGrad4;
|
23
23
|
|
24
|
+
/**
|
25
|
+
*
|
26
|
+
* @param seed
|
27
|
+
*/
|
24
28
|
public OpenSimplex2F(long seed) {
|
25
29
|
perm = new short[PSIZE];
|
26
30
|
permGrad2 = new Grad2[PSIZE];
|
@@ -34,7 +38,7 @@ public class OpenSimplex2F implements Noise {
|
|
34
38
|
seed = seed * 6364136223846793005L + 1442695040888963407L;
|
35
39
|
int r = (int) ((seed + 31) % (i + 1));
|
36
40
|
if (r < 0) {
|
37
|
-
r +=
|
41
|
+
r += i + 1;
|
38
42
|
}
|
39
43
|
perm[i] = source[r];
|
40
44
|
permGrad2[i] = GRADIENTS_2D[perm[i]];
|
@@ -141,6 +145,34 @@ public class OpenSimplex2F implements Noise {
|
|
141
145
|
return noise3_BCC(xr, yr, zr);
|
142
146
|
}
|
143
147
|
|
148
|
+
/**
|
149
|
+
* 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X,
|
150
|
+
* Y).Recommended for 3D terrain and time-varied animations.The Z coordinate
|
151
|
+
* should always be the "different" coordinate in your use case.If Y is
|
152
|
+
* vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use
|
153
|
+
* noise3_XZBeforeY.If Z is vertical in world coordinates, call
|
154
|
+
* noise3_XYBeforeZ(x, y, Z). For a time varied animation, call
|
155
|
+
* noise3_XYBeforeZ(x, y, T).
|
156
|
+
*
|
157
|
+
* @param x
|
158
|
+
* @param y
|
159
|
+
* @param z
|
160
|
+
* @return
|
161
|
+
*/
|
162
|
+
public double noise3_XYBeforeZ(double x, double y, double z) {
|
163
|
+
|
164
|
+
// Re-orient the cubic lattices without skewing, to make X and Y triangular like 2D.
|
165
|
+
// Orthonormal rotation. Not a skew transform.
|
166
|
+
double xy = x + y;
|
167
|
+
double s2 = xy * -0.211324865405187;
|
168
|
+
double zz = z * 0.577350269189626;
|
169
|
+
double xr = x + s2 - zz, yr = y + s2 - zz;
|
170
|
+
double zr = xy * 0.577350269189626 + zz;
|
171
|
+
|
172
|
+
// Evaluate both lattices to form a BCC lattice.
|
173
|
+
return noise3_BCC(xr, yr, zr);
|
174
|
+
}
|
175
|
+
|
144
176
|
/**
|
145
177
|
* 3D Re-oriented 4-point BCC noise, with better visual isotropy in (X,
|
146
178
|
* Z).Recommended for 3D terrain and time-varied animations.The Y coordinate
|
@@ -213,8 +245,8 @@ public class OpenSimplex2F implements Noise {
|
|
213
245
|
*
|
214
246
|
* @param x
|
215
247
|
* @param y
|
216
|
-
* @param z
|
217
248
|
* @param w
|
249
|
+
* @param z
|
218
250
|
* @return
|
219
251
|
*/
|
220
252
|
public double noise4_Classic(double x, double y, double z, double w) {
|
@@ -233,8 +265,8 @@ public class OpenSimplex2F implements Noise {
|
|
233
265
|
* trick.
|
234
266
|
*
|
235
267
|
* @param x
|
236
|
-
* @param y
|
237
268
|
* @param z
|
269
|
+
* @param y
|
238
270
|
* @param w
|
239
271
|
* @return
|
240
272
|
*/
|
@@ -247,15 +279,35 @@ public class OpenSimplex2F implements Noise {
|
|
247
279
|
return noise4_Base(xs, ys, zs, ws);
|
248
280
|
}
|
249
281
|
|
282
|
+
/**
|
283
|
+
* 4D OpenSimplex2F noise, with XZ and YW forming orthogonal
|
284
|
+
* triangular-based planes.Recommended for 3D terrain, where X and Z (or Y
|
285
|
+
* and W) are horizontal.
|
286
|
+
*
|
287
|
+
* @param x
|
288
|
+
* @param z
|
289
|
+
* @param y
|
290
|
+
* @param w
|
291
|
+
* @return
|
292
|
+
*/
|
293
|
+
public double noise4_XZBeforeYW(double x, double y, double z, double w) {
|
294
|
+
|
295
|
+
double s2 = (x + z) * -0.178275657951399372 + (y + w) * 0.215623393288842828;
|
296
|
+
double t2 = (y + w) * -0.403949762580207112 + (x + z) * -0.375199083010075342;
|
297
|
+
double xs = x + s2, ys = y + t2, zs = z + s2, ws = w + t2;
|
298
|
+
|
299
|
+
return noise4_Base(xs, ys, zs, ws);
|
300
|
+
}
|
301
|
+
|
250
302
|
/**
|
251
303
|
* 4D OpenSimplex2F noise, with XYZ oriented like noise3_Classic, and W for
|
252
304
|
* an extra degree of freedom.W repeats eventually.Recommended for
|
253
305
|
* time-varied animations which texture a 3D object (W=time)
|
254
306
|
*
|
255
307
|
* @param x
|
308
|
+
* @param w
|
256
309
|
* @param y
|
257
310
|
* @param z
|
258
|
-
* @param w
|
259
311
|
* @return
|
260
312
|
*/
|
261
313
|
public double noise4_XYZBeforeW(double x, double y, double z, double w) {
|
@@ -283,7 +335,7 @@ public class OpenSimplex2F implements Noise {
|
|
283
335
|
// If we're in the lower half, flip so we can repeat the code for the upper half. We'll flip back later.
|
284
336
|
double siSum = xsi + ysi + zsi + wsi;
|
285
337
|
double ssi = siSum * 0.309016994374947; // Prep for vertex contributions.
|
286
|
-
boolean inLowerHalf =
|
338
|
+
boolean inLowerHalf = siSum < 2;
|
287
339
|
if (inLowerHalf) {
|
288
340
|
xsi = 1 - xsi;
|
289
341
|
ysi = 1 - ysi;
|
@@ -491,25 +543,6 @@ public class OpenSimplex2F implements Noise {
|
|
491
543
|
}
|
492
544
|
}
|
493
545
|
|
494
|
-
@Override
|
495
|
-
public float noise(float x, float y, float z) {
|
496
|
-
return (float)noise3_Classic(x, y, z);
|
497
|
-
}
|
498
|
-
|
499
|
-
@Override
|
500
|
-
public float noise(float x, float y, float z, float w) {
|
501
|
-
return (float)noise4_Classic(x, y, z, w);
|
502
|
-
}
|
503
|
-
|
504
|
-
@Override
|
505
|
-
public void noiseMode(NoiseMode mode) {
|
506
|
-
|
507
|
-
}
|
508
|
-
|
509
|
-
@Override
|
510
|
-
public void noiseSeed(long seed) {
|
511
|
-
}
|
512
|
-
|
513
546
|
private static class LatticePoint2D {
|
514
547
|
|
515
548
|
int xsv, ysv;
|
@@ -557,10 +590,10 @@ public class OpenSimplex2F implements Noise {
|
|
557
590
|
this.dy = -ysv - ssv;
|
558
591
|
this.dz = -zsv - ssv;
|
559
592
|
this.dw = -wsv - ssv;
|
560
|
-
this.xsi =
|
561
|
-
this.ysi =
|
562
|
-
this.zsi =
|
563
|
-
this.wsi =
|
593
|
+
this.xsi = 0.2 - xsv;
|
594
|
+
this.ysi = 0.2 - ysv;
|
595
|
+
this.zsi = 0.2 - zsv;
|
596
|
+
this.wsi = 0.2 - wsv;
|
564
597
|
this.ssiDelta = (0.8 - xsv - ysv - zsv - wsv) * 0.309016994374947;
|
565
598
|
}
|
566
599
|
}
|