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.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/.mvn/wrapper/maven-wrapper.properties +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +7 -1
- data/README.md +7 -7
- data/Rakefile +6 -5
- data/lib/propane/app.rb +10 -17
- data/lib/propane/helper_methods.rb +6 -6
- data/lib/propane/version.rb +1 -1
- data/lib/propane-4.0.0.jar +0 -0
- data/library/pdf/itextpdf-5.5.13.2.jar +0 -0
- data/library/pdf/pdf.rb +7 -0
- data/library/slider/slider.rb +1 -1
- data/library/svg/batik-all-1.14.jar +0 -0
- data/library/svg/svg.rb +7 -0
- data/mvnw +3 -3
- data/mvnw.cmd +2 -2
- data/pom.rb +35 -8
- data/pom.xml +60 -9
- data/propane.gemspec +9 -7
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/MathToolModule.java +31 -31
- data/src/main/java/monkstone/PropaneLibrary.java +3 -1
- data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/fastmath/DegLutTables.java +25 -26
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +2 -2
- data/src/main/java/monkstone/noise/LICENSE +121 -0
- data/src/main/java/monkstone/noise/OpenSimplex2F.java +914 -0
- data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +2 -2
- data/src/main/java/monkstone/vecmath/JRender.java +6 -6
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +103 -83
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +27 -41
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -4
- data/src/main/java/processing/awt/PImageAWT.java +8 -8
- data/src/main/java/processing/core/PApplet.java +245 -254
- data/src/main/java/processing/core/PConstants.java +155 -163
- data/src/main/java/processing/core/PGraphics.java +116 -109
- data/src/main/java/processing/core/PImage.java +3025 -3047
- data/src/main/java/processing/core/PMatrix.java +5 -2
- data/src/main/java/processing/data/DoubleDict.java +72 -43
- data/src/main/java/processing/data/DoubleList.java +6 -2
- data/src/main/java/processing/data/FloatDict.java +744 -756
- data/src/main/java/processing/data/FloatList.java +68 -26
- data/src/main/java/processing/data/IntDict.java +72 -45
- data/src/main/java/processing/data/IntList.java +63 -26
- data/src/main/java/processing/data/JSONArray.java +892 -931
- data/src/main/java/processing/data/JSONObject.java +1169 -1262
- data/src/main/java/processing/data/JSONTokener.java +30 -49
- data/src/main/java/processing/data/LongDict.java +699 -712
- data/src/main/java/processing/data/LongList.java +676 -700
- data/src/main/java/processing/data/Sort.java +1 -0
- data/src/main/java/processing/data/Table.java +4040 -3661
- data/src/main/java/processing/data/TableRow.java +16 -0
- data/src/main/java/processing/data/XML.java +1041 -956
- data/src/main/java/processing/event/TouchEvent.java +1 -1
- data/src/main/java/processing/opengl/FontTexture.java +2 -2
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +28 -31
- data/src/main/java/processing/opengl/PJOGL.java +8 -7
- data/src/main/java/processing/opengl/PShader.java +1 -6
- data/src/main/java/processing/opengl/PShapeOpenGL.java +23 -24
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +6 -6
- data/src/main/java/processing/pdf/PGraphicsPDF.java +581 -0
- data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
- data/src/main/{java/processing/opengl → resources}/cursors/arrow.png +0 -0
- data/src/main/{java/processing/opengl → resources}/cursors/cross.png +0 -0
- data/src/main/{java/processing/opengl → resources}/cursors/hand.png +0 -0
- data/src/main/{java/processing/opengl → resources}/cursors/license.txt +0 -0
- data/src/main/{java/processing/opengl → resources}/cursors/move.png +0 -0
- data/src/main/{java/processing/opengl → resources}/cursors/text.png +0 -0
- data/src/main/{java/processing/opengl → resources}/cursors/wait.png +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/ColorFrag.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/ColorVert.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/LightFrag.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/LightVert.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/LineFrag.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/LineVert.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/MaskFrag.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/PointFrag.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/PointVert.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/TexFrag.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/TexLightFrag.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/TexLightVert.glsl +0 -0
- data/src/main/{java/processing/opengl → resources}/shaders/TexVert.glsl +0 -0
- data/test/test_helper.rb +1 -0
- data/test/vecmath_spec_test.rb +14 -3
- data/vendors/Rakefile +1 -1
- metadata +53 -53
- data/lib/propane-3.8.0.jar +0 -0
- data/src/main/java/monkstone/noise/Noise.java +0 -116
- data/src/main/java/monkstone/noise/NoiseGenerator.java +0 -63
- data/src/main/java/monkstone/noise/NoiseMode.java +0 -15
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -470
- data/src/main/java/monkstone/noise/ValueNoise.java +0 -170
@@ -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.OpenSimplex2F;
|
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 = "FastNoise")
|
23
|
+
public class FastNoiseModuleJava {
|
24
|
+
|
25
|
+
static OpenSimplex2F ng = new OpenSimplex2F(System.currentTimeMillis());
|
26
|
+
|
27
|
+
/**
|
28
|
+
*
|
29
|
+
* @param runtime Ruby
|
30
|
+
*/
|
31
|
+
public static void createNoiseModule(Ruby runtime) {
|
32
|
+
RubyModule noiseModule = runtime.defineModule("FastNoise");
|
33
|
+
noiseModule.defineAnnotatedMethods(FastNoiseModuleJava.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 OpenSimplex2F(seed);
|
123
|
+
// return RubyBoolean.newBoolean(context.runtime, true);
|
124
|
+
// }
|
125
|
+
// return RubyBoolean.newBoolean(context.runtime, false);
|
126
|
+
// }
|
127
|
+
}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* The purpose of this tool is to allow JRubyArt users to use an alternative
|
3
3
|
* to processing.org map, lerp and norm methods in their sketches and to implement
|
4
4
|
* JRubyArt convenenience method grid(width, height, stepW, stepH) { |x, y| do stuff }
|
5
|
-
* Copyright (c) 2015-
|
5
|
+
* Copyright (c) 2015-22 Martin Prout. This tool is free software; you can
|
6
6
|
* redistribute it and/or modify it under the terms of the GNU Lesser General
|
7
7
|
* Public License as published by the Free Software Foundation; either version
|
8
8
|
* 2.1 of the License, or (at your option) any later version.
|
@@ -47,17 +47,17 @@ public class MathToolModule {
|
|
47
47
|
*/
|
48
48
|
@JRubyMethod(name = "map1d", rest = true, module = true)
|
49
49
|
public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
50
|
-
double value =
|
50
|
+
double value = args[0] instanceof RubyFloat
|
51
51
|
? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
52
52
|
RubyRange r1 = (RubyRange) args[1];
|
53
53
|
RubyRange r2 = (RubyRange) args[2];
|
54
|
-
double first1 =
|
54
|
+
double first1 = r1.first(context) instanceof RubyFloat
|
55
55
|
? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
|
56
|
-
double first2 =
|
56
|
+
double first2 = r2.first(context) instanceof RubyFloat
|
57
57
|
? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
|
58
|
-
double last1 =
|
58
|
+
double last1 = r1.last(context) instanceof RubyFloat
|
59
59
|
? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
|
60
|
-
double last2 =
|
60
|
+
double last2 = r2.last(context) instanceof RubyFloat
|
61
61
|
? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
|
62
62
|
return mapMt(context, value, first1, last1, first2, last2);
|
63
63
|
}
|
@@ -71,16 +71,16 @@ public class MathToolModule {
|
|
71
71
|
*/
|
72
72
|
@JRubyMethod(name = "constrained_map", rest = true, module = true)
|
73
73
|
public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
74
|
-
double value =
|
74
|
+
double value = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
75
75
|
RubyRange r1 = (RubyRange) args[1];
|
76
76
|
RubyRange r2 = (RubyRange) args[2];
|
77
|
-
double first1 =
|
77
|
+
double first1 = r1.first(context) instanceof RubyFloat
|
78
78
|
? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
|
79
|
-
double first2 =
|
79
|
+
double first2 = r2.first(context) instanceof RubyFloat
|
80
80
|
? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
|
81
|
-
double last1 =
|
81
|
+
double last1 = r1.last(context) instanceof RubyFloat
|
82
82
|
? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
|
83
|
-
double last2 =
|
83
|
+
double last2 = r2.last(context) instanceof RubyFloat
|
84
84
|
? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
|
85
85
|
double max = Math.max(first1, last1);
|
86
86
|
double min = Math.min(first1, last1);
|
@@ -102,11 +102,11 @@ public class MathToolModule {
|
|
102
102
|
*/
|
103
103
|
@JRubyMethod(name = "p5map", rest = true, module = true)
|
104
104
|
public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
105
|
-
double value =
|
106
|
-
double first1 =
|
107
|
-
double first2 =
|
108
|
-
double last1 =
|
109
|
-
double last2 =
|
105
|
+
double value = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
106
|
+
double first1 = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
107
|
+
double first2 = args[3] instanceof RubyFloat ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
|
108
|
+
double last1 = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
109
|
+
double last2 = args[4] instanceof RubyFloat ? ((RubyFloat) args[4]).getValue() : ((RubyFixnum) args[4]).getDoubleValue();
|
110
110
|
return mapMt(context, value, first1, last1, first2, last2);
|
111
111
|
}
|
112
112
|
|
@@ -121,16 +121,16 @@ public class MathToolModule {
|
|
121
121
|
*/
|
122
122
|
@JRubyMethod(name = "lerp", rest = true, module = true)
|
123
123
|
public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
124
|
-
double start =
|
125
|
-
double stop =
|
126
|
-
double amount =
|
124
|
+
double start = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
125
|
+
double stop = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
126
|
+
double amount = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
127
127
|
if (amount <= 0) {
|
128
128
|
return args[0];
|
129
129
|
}
|
130
130
|
if (amount >= 1.0) {
|
131
131
|
return args[1];
|
132
132
|
}
|
133
|
-
return context.runtime.newFloat((1 - amount) * start +
|
133
|
+
return context.runtime.newFloat((1 - amount) * start + stop * amount);
|
134
134
|
}
|
135
135
|
|
136
136
|
/**
|
@@ -145,9 +145,9 @@ public class MathToolModule {
|
|
145
145
|
*/
|
146
146
|
@JRubyMethod(name = "norm", rest = true, module = true)
|
147
147
|
public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
148
|
-
double value =
|
149
|
-
double start =
|
150
|
-
double stop =
|
148
|
+
double value = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
149
|
+
double start = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
150
|
+
double stop = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
151
151
|
return mapMt(context, value, start, stop, 0, 1.0);
|
152
152
|
}
|
153
153
|
|
@@ -163,9 +163,9 @@ public class MathToolModule {
|
|
163
163
|
@JRubyMethod(name = "norm_strict", rest = true, module = true)
|
164
164
|
public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
165
165
|
|
166
|
-
double value =
|
167
|
-
double start =
|
168
|
-
double stop =
|
166
|
+
double value = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
167
|
+
double start = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
168
|
+
double stop = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
169
169
|
double max = Math.max(start, stop);
|
170
170
|
double min = Math.min(start, stop);
|
171
171
|
if (value < min) {
|
@@ -266,14 +266,14 @@ public class MathToolModule {
|
|
266
266
|
int xDim = (int) args[0].toJava(Integer.class);
|
267
267
|
int yDim = (int) args[1].toJava(Integer.class);
|
268
268
|
int zDim = (int) args[2].toJava(Integer.class);
|
269
|
-
int xStep =
|
270
|
-
int yStep =
|
271
|
-
int zStep =
|
272
|
-
|
269
|
+
int xStep = args.length > 3 ? (int) args[3].toJava(Integer.class) : 1;
|
270
|
+
int yStep = args.length > 4 ? (int) args[4].toJava(Integer.class) : 1;
|
271
|
+
int zStep = args.length == 6 ? (int) args[5].toJava(Integer.class) : 1;
|
272
|
+
// int dimX = xDim / xStep;
|
273
273
|
int dimY = yDim / yStep;
|
274
274
|
int dimZ = zDim / zStep;
|
275
275
|
if (block.isGiven()) {
|
276
|
-
|
276
|
+
// int count = dimX * dimY * dimZ;
|
277
277
|
for (int x = 0; x < xDim; x += xStep){
|
278
278
|
for (int j = 0; j < (dimZ * dimY); j++){
|
279
279
|
int z = j % dimZ;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* The purpose of this class is to load the MathTool into ruby-processing runtime
|
3
|
-
* Copyright (C) 2015-
|
3
|
+
* Copyright (C) 2015-22 Martin Prout. This code is free software; you can
|
4
4
|
* redistribute it and/or modify it under the terms of the GNU Lesser General
|
5
5
|
* Public License as published by the Free Software Foundation; either version
|
6
6
|
* 2.1 of the License, or (at your option) any later version.
|
@@ -28,6 +28,8 @@ public class PropaneLibrary implements Library {
|
|
28
28
|
*/
|
29
29
|
public static void load(final Ruby runtime) {
|
30
30
|
MathToolModule.createMathToolModule(runtime);
|
31
|
+
FastNoiseModuleJava.createNoiseModule(runtime);
|
32
|
+
SmoothNoiseModuleJava.createNoiseModule(runtime);
|
31
33
|
Deglut.createDeglut(runtime);
|
32
34
|
Vec2.createVec2(runtime);
|
33
35
|
Vec3.createVec3(runtime);
|
@@ -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
|
+
}
|
@@ -1,18 +1,18 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2021 Martin Prout
|
3
|
-
*
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2021-22 Martin Prout
|
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
|
6
6
|
* License as published by the Free Software Foundation; either
|
7
7
|
* version 2.1 of the License, or (at your option) any later version.
|
8
|
-
*
|
8
|
+
*
|
9
9
|
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* This library is distributed in the hope that it will be useful,
|
12
12
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
13
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
14
|
* Lesser General Public License for more details.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* You should have received a copy of the GNU Lesser General Public
|
17
17
|
* License along with this library; if not, write to the Free Software
|
18
18
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
@@ -24,43 +24,43 @@ public final class DegLutTables {
|
|
24
24
|
/**
|
25
25
|
*
|
26
26
|
*/
|
27
|
-
|
27
|
+
static public float PI = 3.1415927f;
|
28
28
|
|
29
29
|
/**
|
30
30
|
*
|
31
31
|
*/
|
32
|
-
|
32
|
+
public static final float PI2 = PI * 2;
|
33
33
|
static private final int SIN_BITS = 15; // 16KB. Adjust for accuracy.
|
34
34
|
static private final int SIN_MASK = ~(-1 << SIN_BITS);
|
35
35
|
static private final int SIN_COUNT = SIN_MASK + 1;
|
36
36
|
|
37
|
-
static
|
38
|
-
static
|
39
|
-
static
|
40
|
-
static
|
37
|
+
private static final float RAD_FULL = PI * 2;
|
38
|
+
private static final float DEG_FULL = 360;
|
39
|
+
private static final float RAD_TO_INDEX = SIN_COUNT / RAD_FULL;
|
40
|
+
private static final float DEG_TO_INDEX = SIN_COUNT / DEG_FULL;
|
41
41
|
|
42
42
|
/**
|
43
43
|
* multiply by this to convert from radians to degrees
|
44
44
|
*/
|
45
|
-
|
45
|
+
public static final float RADIANS_TO_DEGREES = 180f / PI;
|
46
46
|
|
47
47
|
/**
|
48
48
|
*
|
49
49
|
*/
|
50
|
-
|
50
|
+
public static final float RAD_DEG = RADIANS_TO_DEGREES;
|
51
51
|
/**
|
52
52
|
* multiply by this to convert from degrees to radians
|
53
53
|
*/
|
54
|
-
|
54
|
+
public static final float DEGREES_TO_RADIANS = PI / 180;
|
55
55
|
|
56
56
|
/**
|
57
57
|
*
|
58
58
|
*/
|
59
|
-
|
59
|
+
public static final float DEG_RAD = DEGREES_TO_RADIANS;
|
60
60
|
|
61
61
|
static private class Sin {
|
62
62
|
|
63
|
-
static
|
63
|
+
static float[] table = new float[SIN_COUNT];
|
64
64
|
|
65
65
|
static {
|
66
66
|
for (int i = 0; i < SIN_COUNT; i++) {
|
@@ -75,37 +75,36 @@ public final class DegLutTables {
|
|
75
75
|
/**
|
76
76
|
* Returns the sine in radians from a lookup table.
|
77
77
|
* @param radians
|
78
|
-
* @return
|
78
|
+
* @return
|
79
79
|
*/
|
80
|
-
|
80
|
+
static public float sin(float radians) {
|
81
81
|
return Sin.table[(int) (radians * RAD_TO_INDEX) & SIN_MASK];
|
82
82
|
}
|
83
83
|
|
84
84
|
/**
|
85
85
|
* Returns the cosine in radians from a lookup table.
|
86
86
|
* @param radians
|
87
|
-
* @return
|
87
|
+
* @return
|
88
88
|
*/
|
89
|
-
|
89
|
+
static public float cos(float radians) {
|
90
90
|
return Sin.table[(int) ((radians + PI / 2) * RAD_TO_INDEX) & SIN_MASK];
|
91
91
|
}
|
92
92
|
|
93
93
|
/**
|
94
94
|
* Returns the sine in radians from a lookup table.
|
95
95
|
* @param degrees
|
96
|
-
* @return
|
96
|
+
* @return
|
97
97
|
*/
|
98
|
-
|
98
|
+
static public float sinDeg(float degrees) {
|
99
99
|
return Sin.table[(int) (degrees * DEG_TO_INDEX) & SIN_MASK];
|
100
100
|
}
|
101
101
|
|
102
102
|
/**
|
103
103
|
* Returns the cosine in radians from a lookup table.
|
104
104
|
* @param degrees
|
105
|
-
* @return
|
105
|
+
* @return
|
106
106
|
*/
|
107
|
-
|
107
|
+
static public float cosDeg(float degrees) {
|
108
108
|
return Sin.table[(int) ((degrees + 90) * DEG_TO_INDEX) & SIN_MASK];
|
109
109
|
}
|
110
110
|
}
|
111
|
-
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2015-
|
2
|
+
* Copyright (c) 2015-22 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
|
@@ -35,5 +35,5 @@ import java.io.File;
|
|
35
35
|
@FunctionalInterface
|
36
36
|
public interface Chooser {
|
37
37
|
|
38
|
-
|
38
|
+
void file_selected(File selection);
|
39
39
|
}
|