propane 3.9.0-java → 3.10.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +2 -2
- data/README.md +3 -3
- data/Rakefile +6 -6
- data/lib/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/lib/java/monkstone/ColorUtil.java +127 -0
- data/lib/java/monkstone/MathToolModule.java +287 -0
- data/lib/java/monkstone/PropaneLibrary.java +46 -0
- data/lib/java/monkstone/core/LibraryProxy.java +136 -0
- data/lib/java/monkstone/fastmath/DegLutTables.java +111 -0
- data/lib/java/monkstone/fastmath/Deglut.java +71 -0
- data/lib/java/monkstone/fastmath/package-info.java +6 -0
- data/lib/java/monkstone/filechooser/Chooser.java +39 -0
- data/{src/main → lib}/java/monkstone/noise/FastTerrain.java +0 -0
- data/{src/main → lib}/java/monkstone/noise/Noise.java +0 -0
- data/{src/main → lib}/java/monkstone/noise/NoiseGenerator.java +0 -0
- data/{src/main → lib}/java/monkstone/noise/NoiseMode.java +0 -0
- data/lib/java/monkstone/noise/OpenSimplex2F.java +881 -0
- data/lib/java/monkstone/noise/OpenSimplex2S.java +1106 -0
- data/{src/main → lib}/java/monkstone/noise/SmoothTerrain.java +0 -0
- data/lib/java/monkstone/slider/CustomHorizontalSlider.java +164 -0
- data/lib/java/monkstone/slider/CustomVerticalSlider.java +178 -0
- data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +145 -0
- data/lib/java/monkstone/slider/SimpleSlider.java +166 -0
- data/lib/java/monkstone/slider/SimpleVerticalSlider.java +157 -0
- data/lib/java/monkstone/slider/Slider.java +61 -0
- data/lib/java/monkstone/slider/SliderBar.java +245 -0
- data/lib/java/monkstone/slider/SliderGroup.java +56 -0
- data/lib/java/monkstone/slider/WheelHandler.java +35 -0
- data/lib/java/monkstone/vecmath/GfxRender.java +86 -0
- data/lib/java/monkstone/vecmath/JRender.java +56 -0
- data/lib/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/lib/java/monkstone/vecmath/package-info.java +20 -0
- data/lib/java/monkstone/vecmath/vec2/Vec2.java +802 -0
- data/lib/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/lib/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/lib/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/lib/java/monkstone/videoevent/CaptureEvent.java +27 -0
- data/lib/java/monkstone/videoevent/MovieEvent.java +32 -0
- data/lib/java/monkstone/videoevent/package-info.java +20 -0
- data/lib/java/processing/awt/PGraphicsJava2D.java +3040 -0
- data/lib/java/processing/awt/PImageAWT.java +377 -0
- data/lib/java/processing/awt/PShapeJava2D.java +387 -0
- data/lib/java/processing/awt/PSurfaceAWT.java +1581 -0
- data/lib/java/processing/awt/ShimAWT.java +581 -0
- data/lib/java/processing/core/PApplet.java +15156 -0
- data/lib/java/processing/core/PConstants.java +523 -0
- data/lib/java/processing/core/PFont.java +1126 -0
- data/lib/java/processing/core/PGraphics.java +8600 -0
- data/lib/java/processing/core/PImage.java +3377 -0
- data/lib/java/processing/core/PMatrix.java +208 -0
- data/lib/java/processing/core/PMatrix2D.java +562 -0
- data/lib/java/processing/core/PMatrix3D.java +890 -0
- data/lib/java/processing/core/PShape.java +3561 -0
- data/lib/java/processing/core/PShapeOBJ.java +483 -0
- data/lib/java/processing/core/PShapeSVG.java +2016 -0
- data/lib/java/processing/core/PStyle.java +63 -0
- data/lib/java/processing/core/PSurface.java +198 -0
- data/lib/java/processing/core/PSurfaceNone.java +431 -0
- data/lib/java/processing/core/PVector.java +1066 -0
- data/lib/java/processing/core/ThinkDifferent.java +115 -0
- data/lib/java/processing/data/DoubleDict.java +850 -0
- data/lib/java/processing/data/DoubleList.java +928 -0
- data/lib/java/processing/data/FloatDict.java +847 -0
- data/lib/java/processing/data/FloatList.java +936 -0
- data/lib/java/processing/data/IntDict.java +807 -0
- data/lib/java/processing/data/IntList.java +936 -0
- data/lib/java/processing/data/JSONArray.java +1260 -0
- data/lib/java/processing/data/JSONObject.java +2282 -0
- data/lib/java/processing/data/JSONTokener.java +435 -0
- data/lib/java/processing/data/LongDict.java +802 -0
- data/lib/java/processing/data/LongList.java +937 -0
- data/lib/java/processing/data/Sort.java +46 -0
- data/lib/java/processing/data/StringDict.java +613 -0
- data/lib/java/processing/data/StringList.java +800 -0
- data/lib/java/processing/data/Table.java +4936 -0
- data/lib/java/processing/data/TableRow.java +198 -0
- data/lib/java/processing/data/XML.java +1156 -0
- data/lib/java/processing/dxf/RawDXF.java +404 -0
- data/lib/java/processing/event/Event.java +125 -0
- data/lib/java/processing/event/KeyEvent.java +70 -0
- data/lib/java/processing/event/MouseEvent.java +114 -0
- data/lib/java/processing/event/TouchEvent.java +57 -0
- data/lib/java/processing/javafx/PGraphicsFX2D.java +32 -0
- data/lib/java/processing/javafx/PSurfaceFX.java +173 -0
- data/lib/java/processing/net/Client.java +744 -0
- data/lib/java/processing/net/Server.java +388 -0
- data/lib/java/processing/opengl/FontTexture.java +378 -0
- data/lib/java/processing/opengl/FrameBuffer.java +513 -0
- data/lib/java/processing/opengl/LinePath.java +627 -0
- data/lib/java/processing/opengl/LineStroker.java +681 -0
- data/lib/java/processing/opengl/PGL.java +3483 -0
- data/lib/java/processing/opengl/PGraphics2D.java +615 -0
- data/lib/java/processing/opengl/PGraphics3D.java +281 -0
- data/lib/java/processing/opengl/PGraphicsOpenGL.java +13753 -0
- data/lib/java/processing/opengl/PJOGL.java +2008 -0
- data/lib/java/processing/opengl/PShader.java +1484 -0
- data/lib/java/processing/opengl/PShapeOpenGL.java +5269 -0
- data/lib/java/processing/opengl/PSurfaceJOGL.java +1385 -0
- data/lib/java/processing/opengl/Texture.java +1696 -0
- data/lib/java/processing/opengl/VertexBuffer.java +88 -0
- data/lib/java/processing/opengl/cursors/arrow.png +0 -0
- data/lib/java/processing/opengl/cursors/cross.png +0 -0
- data/lib/java/processing/opengl/cursors/hand.png +0 -0
- data/lib/java/processing/opengl/cursors/license.txt +27 -0
- data/lib/java/processing/opengl/cursors/move.png +0 -0
- data/lib/java/processing/opengl/cursors/text.png +0 -0
- data/lib/java/processing/opengl/cursors/wait.png +0 -0
- data/lib/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/lib/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/lib/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/lib/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/lib/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/lib/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/lib/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/lib/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/lib/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/lib/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/lib/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/lib/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/lib/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/lib/java/processing/pdf/PGraphicsPDF.java +581 -0
- data/lib/java/processing/svg/PGraphicsSVG.java +378 -0
- data/lib/propane/app.rb +8 -13
- data/lib/propane/version.rb +1 -1
- data/mvnw +3 -3
- data/mvnw.cmd +2 -2
- data/pom.rb +7 -2
- data/pom.xml +14 -2
- data/propane.gemspec +2 -2
- data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/MathToolModule.java +30 -30
- data/src/main/java/monkstone/PropaneLibrary.java +2 -0
- data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/fastmath/DegLutTables.java +15 -15
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
- data/src/main/java/monkstone/noise/OpenSimplex2F.java +752 -820
- data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -1106
- data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
- data/src/main/java/monkstone/vecmath/JRender.java +6 -6
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +20 -19
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +12 -12
- data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -3
- data/src/main/java/processing/core/PApplet.java +89 -89
- data/src/main/java/processing/core/PConstants.java +155 -163
- data/src/main/java/processing/opengl/PJOGL.java +6 -5
- data/vendors/Rakefile +1 -1
- metadata +136 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 412793f807afe7defb88f5a8376cf15de48e65f79ff2758d8fa9c4c1a0eb0202
|
4
|
+
data.tar.gz: a6a387f0a7e4db3b6a7048f35f1f4d5006734fe6a37a021918bd81850c37eedc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e229c8b432547844db7d625fdfeff7551300fb8319bc485aa99a6bdcb723d364d0eb2bd20673a68dba5f8433e6f897d2e204f34f1028430b986b45967cdf48ec
|
7
|
+
data.tar.gz: 47864625dcf2cfd9cdfbce74cbd4ac2b470c97482e90f119dc235027557afe80b3302f150a097a2027a119a546ff29b0017bf6d4426178b2e966b4f21d360c6e
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
**v3.
|
1
|
+
**v3.10.0** Default to using FastNoise module, with alternative of SmoothNoise module.
|
2
2
|
|
3
3
|
**v3.8.0** Refactor noise to delegate pattern, improve default implementation and add simplex noise option
|
4
4
|
|
5
|
-
**v3.7.1** Recommend JRuby-9.2.
|
5
|
+
**v3.7.1** Recommend JRuby-9.2.16.0 use
|
6
6
|
|
7
7
|
**v3.5.0** Rebase processing core code around Sam Pottingers latest fixes for JOGL an image save, does mean breaking some of Diwis and Joshua Davis examples, but one hopes codeanticode knows what he's doing.
|
8
8
|
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ adjust above for your OS/distro setup.
|
|
11
11
|
Previously there has been linker issue with P2D or P3D sketches with stock openjdk with some linux distros, but that seems to have gone away. [Adopt open jdk binaries][adopt] have always worked.
|
12
12
|
|
13
13
|
- `jdk-11.0.7+`
|
14
|
-
- `jruby-9.2.
|
14
|
+
- `jruby-9.2.17.0`
|
15
15
|
|
16
16
|
## Building and testing
|
17
17
|
|
@@ -25,10 +25,10 @@ rake javadoc
|
|
25
25
|
|
26
26
|
```bash
|
27
27
|
jgem install propane # from rubygems
|
28
|
-
jgem install propane-3.
|
28
|
+
jgem install propane-3.10.0-java.gem # local install
|
29
29
|
# Alternative
|
30
30
|
jruby -S gem install propane # from rubygems
|
31
|
-
jruby -S gem install propane-3.
|
31
|
+
jruby -S gem install propane-3.10.0-java.gem # local install
|
32
32
|
```
|
33
33
|
|
34
34
|
## Check Install
|
data/Rakefile
CHANGED
@@ -17,8 +17,8 @@ end
|
|
17
17
|
|
18
18
|
desc 'Install'
|
19
19
|
task :install do
|
20
|
-
sh
|
21
|
-
|
20
|
+
sh 'mvn dependency:copy'
|
21
|
+
FileUtils.mv("target/propane-#{Propane::VERSION}.jar", 'lib')
|
22
22
|
end
|
23
23
|
|
24
24
|
desc 'Gem'
|
@@ -36,9 +36,9 @@ task :compile do
|
|
36
36
|
sh './mvnw package'
|
37
37
|
end
|
38
38
|
|
39
|
-
desc '
|
40
|
-
task :
|
41
|
-
sh '
|
39
|
+
desc 'pmd'
|
40
|
+
task :pmd do
|
41
|
+
sh './mvnw pmd:pmd'
|
42
42
|
end
|
43
43
|
|
44
44
|
desc 'Test'
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
desc 'clean'
|
55
55
|
task :clean do
|
56
56
|
Dir['./**/*.{jar,gem}'].each do |path|
|
57
|
-
puts
|
57
|
+
puts 'Deleting #{path} ...'
|
58
58
|
File.delete(path)
|
59
59
|
end
|
60
60
|
FileUtils.rm_rf('./target')
|
@@ -0,0 +1,88 @@
|
|
1
|
+
/*
|
2
|
+
Part of the Processing project - http://processing.org
|
3
|
+
|
4
|
+
Copyright (c) 2011-12 hansi raber, released under LGPL under agreement
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation, version 2.1.
|
9
|
+
|
10
|
+
This library is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General
|
16
|
+
Public License along with this library; if not, write to the
|
17
|
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
18
|
+
Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
package japplemenubar;
|
21
|
+
|
22
|
+
import java.io.*;
|
23
|
+
|
24
|
+
import processing.core.PApplet;
|
25
|
+
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Starting point for the application. General initialization should be done
|
29
|
+
* inside the ApplicationController's init() method. If certain kinds of
|
30
|
+
* non-Swing initialization takes too long, it should happen in a new Thread
|
31
|
+
* and off the Swing event dispatch thread (EDT).
|
32
|
+
*
|
33
|
+
* @author hansi
|
34
|
+
*/
|
35
|
+
public class JAppleMenuBar {
|
36
|
+
static JAppleMenuBar instance;
|
37
|
+
static final String FILENAME = "libjAppleMenuBar.jnilib";
|
38
|
+
|
39
|
+
static {
|
40
|
+
try {
|
41
|
+
File temp = File.createTempFile("processing", "menubar");
|
42
|
+
temp.delete(); // remove the file itself
|
43
|
+
temp.mkdirs(); // create a directory out of it
|
44
|
+
temp.deleteOnExit();
|
45
|
+
|
46
|
+
File jnilibFile = new File(temp, FILENAME);
|
47
|
+
InputStream input = JAppleMenuBar.class.getResourceAsStream(FILENAME);
|
48
|
+
if (input != null) {
|
49
|
+
if (PApplet.saveStream(jnilibFile, input)) {
|
50
|
+
System.load(jnilibFile.getAbsolutePath());
|
51
|
+
instance = new JAppleMenuBar();
|
52
|
+
|
53
|
+
} else {
|
54
|
+
sadness("Problem saving " + FILENAME + " for full screen use.");
|
55
|
+
}
|
56
|
+
} else {
|
57
|
+
sadness("Could not load " + FILENAME + " from core.jar");
|
58
|
+
}
|
59
|
+
} catch (IOException e) {
|
60
|
+
sadness("Unknown error, here's the stack trace.");
|
61
|
+
e.printStackTrace();
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
static void sadness(String msg) {
|
67
|
+
System.err.println("Full screen mode disabled. " + msg);
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
// static public void show() {
|
72
|
+
// instance.setVisible(true);
|
73
|
+
// }
|
74
|
+
|
75
|
+
|
76
|
+
static public void hide() {
|
77
|
+
instance.setVisible(false, false);
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
public native void setVisible(boolean visibility, boolean kioskMode);
|
82
|
+
|
83
|
+
|
84
|
+
// public void setVisible(boolean visibility) {
|
85
|
+
// // Keep original API in-tact. Default kiosk-mode to off.
|
86
|
+
// setVisible(visibility, false);
|
87
|
+
// }
|
88
|
+
}
|
Binary file
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/**
|
2
|
+
* This utility allows JRubyArt users to use the processing.org color method
|
3
|
+
* in their sketches. Includes a method to efficiently convert an array of web
|
4
|
+
* strings to an array of color int, and another to convert an array of color
|
5
|
+
* int to a string that can be used in ruby code (to generate web color array).
|
6
|
+
* Copyright (c) 2015-20 Martin Prout.
|
7
|
+
* This utility is free software; you can redistribute it and/or modify
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
* the Free Software Foundation; either version 2.1 of the License, or (at
|
10
|
+
* your option) any later version.
|
11
|
+
*
|
12
|
+
* Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html
|
13
|
+
*/
|
14
|
+
package monkstone;
|
15
|
+
|
16
|
+
import java.util.Random;
|
17
|
+
/**
|
18
|
+
*
|
19
|
+
* @author Martin Prout
|
20
|
+
*/
|
21
|
+
public class ColorUtil {
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Returns hex long as a positive int unless greater than Integer.MAX_VALUE
|
25
|
+
* else return the complement as a negative integer or something like that
|
26
|
+
*
|
27
|
+
* @param hexlong long
|
28
|
+
* @return rgb int
|
29
|
+
*/
|
30
|
+
static final int hexLong(long hexlong) {
|
31
|
+
long SPLIT = Integer.MAX_VALUE + 1;
|
32
|
+
if (hexlong < SPLIT) {
|
33
|
+
return (int) hexlong;
|
34
|
+
} else {
|
35
|
+
return (int) (hexlong - SPLIT * 2L);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @param hexstring String
|
41
|
+
* @return rgb int
|
42
|
+
*/
|
43
|
+
static public int colorString(String hexstring) {
|
44
|
+
return java.awt.Color.decode(hexstring).getRGB();
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
*
|
49
|
+
* @param web Array of web (hex) String
|
50
|
+
* @return array of color int according to java
|
51
|
+
*/
|
52
|
+
static public int[] webArray(String[] web) {
|
53
|
+
int[] result = new int[web.length];
|
54
|
+
for (int i = 0; i < web.length; i++) {
|
55
|
+
result[i] = java.awt.Color.decode(web[i]).getRGB();
|
56
|
+
}
|
57
|
+
return result;
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Return a ruby string of the form "%w(a b c)" where a, b, c are raw web
|
62
|
+
* strings. This string can be used in ruby code.
|
63
|
+
*
|
64
|
+
* @param hex int array
|
65
|
+
* @return String for use in ruby
|
66
|
+
*/
|
67
|
+
static public String rubyString(int[] hex) {
|
68
|
+
StringBuilder result = new StringBuilder("%w(");
|
69
|
+
for (int i = 0; i < hex.length; i++) {
|
70
|
+
result.append(String.format("#%06X", (0xFFFFFF & hex[i])));
|
71
|
+
if (i < hex.length - 1) {
|
72
|
+
result.append(' ');
|
73
|
+
}
|
74
|
+
}
|
75
|
+
result.append(")\n");
|
76
|
+
return result.toString();
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
*
|
81
|
+
* @param hex double
|
82
|
+
* @return hex float
|
83
|
+
*/
|
84
|
+
static public float colorLong(double hex) {
|
85
|
+
return (float) hex;
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
*
|
90
|
+
* @param hexlong long
|
91
|
+
* @return hexlong int
|
92
|
+
*/
|
93
|
+
static public int colorLong(long hexlong) {
|
94
|
+
return hexLong(hexlong);
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
*
|
99
|
+
* @param hex double
|
100
|
+
* @return hex float
|
101
|
+
*/
|
102
|
+
static public float colorDouble(double hex) {
|
103
|
+
return (float) hex;
|
104
|
+
}
|
105
|
+
|
106
|
+
static public int[] shuffle(int[] cols) {
|
107
|
+
Random rgen = new Random(); // Random number generator
|
108
|
+
for (int i = 0; i < cols.length; i++) {
|
109
|
+
int randomPosition = rgen.nextInt(cols.length);
|
110
|
+
int temp = cols[i];
|
111
|
+
cols[i] = cols[randomPosition];
|
112
|
+
cols[randomPosition] = temp;
|
113
|
+
}
|
114
|
+
return cols;
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
*
|
119
|
+
* @param hue
|
120
|
+
* @param sat
|
121
|
+
* @param brightness
|
122
|
+
* @return
|
123
|
+
*/
|
124
|
+
static public int hsbToRgB(double hue, double sat, double brightness) {
|
125
|
+
return java.awt.Color.HSBtoRGB((float) hue, (float) sat, (float) brightness);
|
126
|
+
}
|
127
|
+
}
|
@@ -0,0 +1,287 @@
|
|
1
|
+
/**
|
2
|
+
* The purpose of this tool is to allow JRubyArt users to use an alternative
|
3
|
+
* to processing.org map, lerp and norm methods in their sketches and to implement
|
4
|
+
* JRubyArt convenenience method grid(width, height, stepW, stepH) { |x, y| do stuff }
|
5
|
+
* Copyright (c) 2015-20 Martin Prout. This tool is free software; you can
|
6
|
+
* redistribute it and/or modify it under the terms of the GNU Lesser General
|
7
|
+
* Public License as published by the Free Software Foundation; either version
|
8
|
+
* 2.1 of the License, or (at your option) any later version.
|
9
|
+
*
|
10
|
+
* Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html
|
11
|
+
*/
|
12
|
+
package monkstone;
|
13
|
+
|
14
|
+
import org.jruby.Ruby;
|
15
|
+
import org.jruby.RubyFixnum;
|
16
|
+
import org.jruby.RubyFloat;
|
17
|
+
import org.jruby.RubyModule;
|
18
|
+
import org.jruby.RubyRange;
|
19
|
+
import org.jruby.anno.JRubyMethod;
|
20
|
+
import org.jruby.anno.JRubyModule;
|
21
|
+
import org.jruby.runtime.Block;
|
22
|
+
import org.jruby.runtime.ThreadContext;
|
23
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
24
|
+
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
* @author Martin Prout
|
28
|
+
*/
|
29
|
+
@JRubyModule(name = "MathTool")
|
30
|
+
public class MathToolModule {
|
31
|
+
|
32
|
+
/**
|
33
|
+
*
|
34
|
+
* @param runtime Ruby
|
35
|
+
*/
|
36
|
+
public static void createMathToolModule(Ruby runtime) {
|
37
|
+
RubyModule mtModule = runtime.defineModule("MathTool");
|
38
|
+
mtModule.defineAnnotatedMethods(MathToolModule.class);
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
*
|
43
|
+
* @param context ThreadContext
|
44
|
+
* @param recv IRubyObject
|
45
|
+
* @param args array of RubyRange (must be be numeric)
|
46
|
+
* @return mapped value RubyFloat
|
47
|
+
*/
|
48
|
+
@JRubyMethod(name = "map1d", rest = true, module = true)
|
49
|
+
public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
50
|
+
double value = (args[0] instanceof RubyFloat)
|
51
|
+
? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
52
|
+
RubyRange r1 = (RubyRange) args[1];
|
53
|
+
RubyRange r2 = (RubyRange) args[2];
|
54
|
+
double first1 = (r1.first(context) instanceof RubyFloat)
|
55
|
+
? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
|
56
|
+
double first2 = (r2.first(context) instanceof RubyFloat)
|
57
|
+
? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
|
58
|
+
double last1 = (r1.last(context) instanceof RubyFloat)
|
59
|
+
? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
|
60
|
+
double last2 = (r2.last(context) instanceof RubyFloat)
|
61
|
+
? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
|
62
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
*
|
67
|
+
* @param context ThreadContext
|
68
|
+
* @param recv IRubyObject
|
69
|
+
* @param args array of RubyRange (must be be numeric)
|
70
|
+
* @return mapped value RubyFloat
|
71
|
+
*/
|
72
|
+
@JRubyMethod(name = "constrained_map", rest = true, module = true)
|
73
|
+
public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
74
|
+
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
75
|
+
RubyRange r1 = (RubyRange) args[1];
|
76
|
+
RubyRange r2 = (RubyRange) args[2];
|
77
|
+
double first1 = (r1.first(context) instanceof RubyFloat)
|
78
|
+
? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
|
79
|
+
double first2 = (r2.first(context) instanceof RubyFloat)
|
80
|
+
? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
|
81
|
+
double last1 = (r1.last(context) instanceof RubyFloat)
|
82
|
+
? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
|
83
|
+
double last2 = (r2.last(context) instanceof RubyFloat)
|
84
|
+
? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
|
85
|
+
double max = Math.max(first1, last1);
|
86
|
+
double min = Math.min(first1, last1);
|
87
|
+
if (value < min) {
|
88
|
+
return mapMt(context, min, first1, last1, first2, last2);
|
89
|
+
}
|
90
|
+
if (value > max) {
|
91
|
+
return mapMt(context, max, first1, last1, first2, last2);
|
92
|
+
}
|
93
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
*
|
98
|
+
* @param context ThreadContext
|
99
|
+
* @param recv self IRubyObject
|
100
|
+
* @param args floats as in processing map function
|
101
|
+
* @return mapped value RubyFloat
|
102
|
+
*/
|
103
|
+
@JRubyMethod(name = "p5map", rest = true, module = true)
|
104
|
+
public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
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
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* A more correct version than processing.org version
|
115
|
+
*
|
116
|
+
* @param context ThreadContext
|
117
|
+
* @param recv self IRubyObject
|
118
|
+
* @param args args[2] should be between 0 and 1.0 if not returns start or
|
119
|
+
* stop
|
120
|
+
* @return lerped value RubyFloat
|
121
|
+
*/
|
122
|
+
@JRubyMethod(name = "lerp", rest = true, module = true)
|
123
|
+
public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
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
|
+
if (amount <= 0) {
|
128
|
+
return args[0];
|
129
|
+
}
|
130
|
+
if (amount >= 1.0) {
|
131
|
+
return args[1];
|
132
|
+
}
|
133
|
+
return context.runtime.newFloat((1 - amount) * start + (stop * amount));
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Identical to p5map(value, low, high, 0, 1). Numbers outside of the range
|
138
|
+
* are not clamped to 0 and 1, because out-of-range values are often
|
139
|
+
* intentional and useful.
|
140
|
+
*
|
141
|
+
* @param context ThreadContext
|
142
|
+
* @param recv IRubyObject
|
143
|
+
* @param args array of args must be be numeric
|
144
|
+
* @return mapped value RubyFloat
|
145
|
+
*/
|
146
|
+
@JRubyMethod(name = "norm", rest = true, module = true)
|
147
|
+
public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
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
|
+
return mapMt(context, value, start, stop, 0, 1.0);
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Identical to p5map(value, low, high, 0, 1) but 'clamped'. Numbers outside
|
156
|
+
* of the range are clamped to 0 and 1,
|
157
|
+
*
|
158
|
+
* @param context ThreadContext
|
159
|
+
* @param recv IRubyObject
|
160
|
+
* @param args array of args must be be numeric
|
161
|
+
* @return mapped value RubyFloat
|
162
|
+
*/
|
163
|
+
@JRubyMethod(name = "norm_strict", rest = true, module = true)
|
164
|
+
public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
165
|
+
|
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
|
+
double max = Math.max(start, stop);
|
170
|
+
double min = Math.min(start, stop);
|
171
|
+
if (value < min) {
|
172
|
+
return mapMt(context, min, start, stop, 0, 1.0);
|
173
|
+
}
|
174
|
+
if (value > max) {
|
175
|
+
return mapMt(context, max, start, stop, 0, 1.0);
|
176
|
+
}
|
177
|
+
return mapMt(context, value, start, stop, 0, 1.0);
|
178
|
+
}
|
179
|
+
// start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
|
180
|
+
static final RubyFloat mapMt(ThreadContext context, double value, double first1, double last1, double first2, double last2) {
|
181
|
+
Ruby ruby = context.runtime;
|
182
|
+
double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
|
183
|
+
return ruby.newFloat(result);
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Provides processing constrain method as a ruby module method
|
188
|
+
*
|
189
|
+
* @param context ThreadContext
|
190
|
+
* @param recv IRubyObject
|
191
|
+
* @param args array of args must be be numeric
|
192
|
+
* @return original or limit values
|
193
|
+
*/
|
194
|
+
@JRubyMethod(name = "constrain", rest = true, module = true)
|
195
|
+
public static IRubyObject constrainValue(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
196
|
+
RubyFloat value = args[0].convertToFloat();
|
197
|
+
RubyFloat start = args[1].convertToFloat();
|
198
|
+
RubyFloat stop = args[2].convertToFloat();
|
199
|
+
if (value.op_ge(context, start).isTrue() && value.op_le(context, stop).isTrue()) {
|
200
|
+
return args[0];
|
201
|
+
} else if (value.op_ge(context, start).isTrue()) {
|
202
|
+
return args[2];
|
203
|
+
} else {
|
204
|
+
return args[1];
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Provides JRubyArt grid method as a ruby module method behaves like:-
|
210
|
+
* def grid(dx, dy, sx = 1, sy = 1)
|
211
|
+
* (0...dx).step(sx) do |x|
|
212
|
+
* (0...dy).step(sy) do |y|
|
213
|
+
* yield(x, y)
|
214
|
+
* end
|
215
|
+
* end
|
216
|
+
* end
|
217
|
+
* @param context ThreadContext
|
218
|
+
* @param recv IRubyObject
|
219
|
+
* @param args array of args should be Fixnum
|
220
|
+
* @param block { |x, y| `do something` }
|
221
|
+
* @return nil
|
222
|
+
*/
|
223
|
+
@JRubyMethod(name = "grid", rest = true, module = true)
|
224
|
+
public static IRubyObject createGrid(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
|
225
|
+
Ruby ruby = context.runtime;
|
226
|
+
int row = (int) args[0].toJava(Integer.class);
|
227
|
+
int column = (int) args[1].toJava(Integer.class);
|
228
|
+
int rowStep = 1;
|
229
|
+
int colStep = 1;
|
230
|
+
if (args.length == 4){
|
231
|
+
rowStep = (int) args[2].toJava(Integer.class);
|
232
|
+
colStep = (int) args[3].toJava(Integer.class);
|
233
|
+
}
|
234
|
+
if (block.isGiven()) {
|
235
|
+
int tempRow = row / rowStep;
|
236
|
+
int tempColumn = column /colStep;
|
237
|
+
for (int z = 0; z < (tempRow * tempColumn); z++){
|
238
|
+
int y = z % tempColumn;
|
239
|
+
int x = z / tempColumn;
|
240
|
+
block.yieldSpecific(context, ruby.newFixnum(x * rowStep), ruby.newFixnum(y * colStep));
|
241
|
+
}
|
242
|
+
}
|
243
|
+
return context.nil;
|
244
|
+
}
|
245
|
+
/**
|
246
|
+
* Provides JRubyArt mesh_grid method as a ruby module method
|
247
|
+
* def grid(dx, dy, dz, sx = 1, sy = 1, sz = 1)
|
248
|
+
* (0...dx).step(sx) do |x|
|
249
|
+
* (0...dy).step(sy) do |y|
|
250
|
+
* (0...dz).step(sy) do |z|
|
251
|
+
* yield(x, y, z)
|
252
|
+
* end
|
253
|
+
* end
|
254
|
+
* end
|
255
|
+
* end
|
256
|
+
*
|
257
|
+
* @param context ThreadContext
|
258
|
+
* @param recv IRubyObject
|
259
|
+
* @param args array of args should be Fixnum
|
260
|
+
* @param block { |x, y, z| `do something` }
|
261
|
+
* @return nil
|
262
|
+
*/
|
263
|
+
@JRubyMethod(name = "mesh_grid", rest = true, module = true)
|
264
|
+
public static IRubyObject createGrid3D(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
|
265
|
+
Ruby ruby = context.runtime;
|
266
|
+
int xDim = (int) args[0].toJava(Integer.class);
|
267
|
+
int yDim = (int) args[1].toJava(Integer.class);
|
268
|
+
int zDim = (int) args[2].toJava(Integer.class);
|
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
|
+
int dimY = yDim / yStep;
|
274
|
+
int dimZ = zDim / zStep;
|
275
|
+
if (block.isGiven()) {
|
276
|
+
int count = dimX * dimY * dimZ;
|
277
|
+
for (int x = 0; x < xDim; x += xStep){
|
278
|
+
for (int j = 0; j < (dimZ * dimY); j++){
|
279
|
+
int z = j % dimZ;
|
280
|
+
int y = j / dimZ;
|
281
|
+
block.yieldSpecific(context, ruby.newFixnum(x), ruby.newFixnum(y * yStep), ruby.newFixnum(z * zStep));
|
282
|
+
}
|
283
|
+
}
|
284
|
+
}
|
285
|
+
return context.nil;
|
286
|
+
}
|
287
|
+
}
|