picrate 0.0.2-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.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.mvn/extensions.xml +9 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +165 -0
- data/README.md +51 -0
- data/Rakefile +59 -0
- data/bin/picrate +8 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +30 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +16 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2018-05-06-getting_started.md +8 -0
- data/docs/_posts/2018-05-06-install_jruby.md +35 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +10 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/lib/picrate.rb +10 -0
- data/lib/picrate/app.rb +187 -0
- data/lib/picrate/creators/sketch_class.rb +57 -0
- data/lib/picrate/creators/sketch_factory.rb +12 -0
- data/lib/picrate/creators/sketch_writer.rb +21 -0
- data/lib/picrate/helper_methods.rb +214 -0
- data/lib/picrate/helpers/numeric.rb +9 -0
- data/lib/picrate/library.rb +69 -0
- data/lib/picrate/library_loader.rb +53 -0
- data/lib/picrate/native_folder.rb +35 -0
- data/lib/picrate/native_loader.rb +27 -0
- data/lib/picrate/runner.rb +81 -0
- data/lib/picrate/version.rb +4 -0
- data/library/boids/boids.rb +209 -0
- data/library/chooser/chooser.rb +19 -0
- data/library/control_panel/control_panel.rb +182 -0
- data/library/library_proxy/README.md +99 -0
- data/library/library_proxy/library_proxy.rb +14 -0
- data/library/slider/slider.rb +42 -0
- data/library/vector_utils/vector_utils.rb +69 -0
- data/library/video_event/video_event.rb +3 -0
- data/license.txt +508 -0
- data/picrate.gemspec +35 -0
- data/pom.rb +122 -0
- data/pom.xml +214 -0
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/ColorUtil.java +115 -0
- data/src/main/java/monkstone/MathToolModule.java +236 -0
- data/src/main/java/monkstone/PicrateLibrary.java +47 -0
- data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
- data/src/main/java/monkstone/fastmath/package-info.java +6 -0
- data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
- data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
- data/src/main/java/monkstone/slider/Slider.java +67 -0
- data/src/main/java/monkstone/slider/SliderBar.java +277 -0
- data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
- data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
- data/src/main/java/monkstone/vecmath/JRender.java +56 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/src/main/java/monkstone/vecmath/package-info.java +20 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/main/java/monkstone/videoevent/package-info.java +20 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
- data/src/main/java/processing/core/PApplet.java +17647 -0
- data/src/main/java/processing/core/PConstants.java +1033 -0
- data/src/main/java/processing/core/PFont.java +1250 -0
- data/src/main/java/processing/core/PGraphics.java +9614 -0
- data/src/main/java/processing/core/PImage.java +3608 -0
- data/src/main/java/processing/core/PMatrix.java +347 -0
- data/src/main/java/processing/core/PMatrix2D.java +694 -0
- data/src/main/java/processing/core/PMatrix3D.java +1153 -0
- data/src/main/java/processing/core/PShape.java +4332 -0
- data/src/main/java/processing/core/PShapeOBJ.java +544 -0
- data/src/main/java/processing/core/PShapeSVG.java +1987 -0
- data/src/main/java/processing/core/PStyle.java +208 -0
- data/src/main/java/processing/core/PSurface.java +242 -0
- data/src/main/java/processing/core/PSurfaceNone.java +479 -0
- data/src/main/java/processing/core/PVector.java +1140 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +108 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/test/create_test.rb +68 -0
- data/test/deglut_spec_test.rb +24 -0
- data/test/helper_methods_test.rb +58 -0
- data/test/math_tool_test.rb +75 -0
- data/test/respond_to_test.rb +215 -0
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/test/test_helper.rb +3 -0
- data/test/vecmath_spec_test.rb +522 -0
- data/vendors/Rakefile +127 -0
- metadata +289 -0
|
Binary file
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This utility allows PiCrate 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) 2018 Martin Prout.
|
|
7
|
+
* This utility is free software; you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation; either version 3.0 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/gpl-3.0-standalone.html
|
|
13
|
+
*/
|
|
14
|
+
package monkstone;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
public class ColorUtil {
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns hex long as a positive int unless greater than Integer.MAX_VALUE
|
|
24
|
+
* else return the complement as a negative integer or something like that
|
|
25
|
+
*
|
|
26
|
+
* @param hexlong long
|
|
27
|
+
* @return rgb int
|
|
28
|
+
*/
|
|
29
|
+
static final int hexLong(long hexlong) {
|
|
30
|
+
long SPLIT = Integer.MAX_VALUE + 1;
|
|
31
|
+
if (hexlong < SPLIT) {
|
|
32
|
+
return (int) hexlong;
|
|
33
|
+
} else {
|
|
34
|
+
return (int) (hexlong - SPLIT * 2L);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param hexstring String
|
|
40
|
+
* @return rgb int
|
|
41
|
+
*/
|
|
42
|
+
static public int colorString(String hexstring) {
|
|
43
|
+
return java.awt.Color.decode(hexstring).getRGB();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @param web Array of web (hex) String
|
|
49
|
+
* @return array of color int according to java
|
|
50
|
+
*/
|
|
51
|
+
static public int[] webArray(String[] web) {
|
|
52
|
+
int[] result = new int[web.length];
|
|
53
|
+
for (int i = 0; i < web.length; i++) {
|
|
54
|
+
result[i] = java.awt.Color.decode(web[i]).getRGB();
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Return a ruby string of the form "%w(a b c)" where a, b, c are raw web
|
|
61
|
+
* strings. This string can be used in ruby code.
|
|
62
|
+
*
|
|
63
|
+
* @param hex int array
|
|
64
|
+
* @return String for use in ruby
|
|
65
|
+
*/
|
|
66
|
+
static public String rubyString(int[] hex) {
|
|
67
|
+
StringBuilder result = new StringBuilder("%w(");
|
|
68
|
+
for (int i = 0; i < hex.length; i++) {
|
|
69
|
+
result.append(String.format("#%06X", (0xFFFFFF & hex[i])));
|
|
70
|
+
if (i < hex.length - 1) {
|
|
71
|
+
result.append(' ');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
result.append(")\n");
|
|
75
|
+
return result.toString();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param hex double
|
|
81
|
+
* @return hex float
|
|
82
|
+
*/
|
|
83
|
+
static public float colorLong(double hex) {
|
|
84
|
+
return (float) hex;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
*
|
|
89
|
+
* @param hexlong long
|
|
90
|
+
* @return hexlong int
|
|
91
|
+
*/
|
|
92
|
+
static public int colorLong(long hexlong) {
|
|
93
|
+
return hexLong(hexlong);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @param hex double
|
|
99
|
+
* @return hex float
|
|
100
|
+
*/
|
|
101
|
+
static public float colorDouble(double hex) {
|
|
102
|
+
return (float) hex;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param hue
|
|
108
|
+
* @param sat
|
|
109
|
+
* @param brightness
|
|
110
|
+
* @return
|
|
111
|
+
*/
|
|
112
|
+
static public int hsbToRgB(double hue, double sat, double brightness) {
|
|
113
|
+
return java.awt.Color.HSBtoRGB((float) hue, (float) sat, (float) brightness);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The purpose of this tool is to allow propane users to use an alternative
|
|
3
|
+
* to processing.org map, lerp and norm methods in their sketches
|
|
4
|
+
* Copyright (c) 2018 Martin Prout. This tool is free software; you can
|
|
5
|
+
* redistribute it and/or modify it under the terms of the GNU Lesser General
|
|
6
|
+
* Public License as published by the Free Software Foundation; either version
|
|
7
|
+
* 2.1 of the License, or (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* Obtain a copy of the license at http://www.gnu.org/licenses/gpl-3.0-standalone.html
|
|
10
|
+
*/
|
|
11
|
+
package monkstone;
|
|
12
|
+
|
|
13
|
+
import org.jruby.Ruby;
|
|
14
|
+
import org.jruby.RubyFixnum;
|
|
15
|
+
import org.jruby.RubyFloat;
|
|
16
|
+
import org.jruby.RubyModule;
|
|
17
|
+
import org.jruby.RubyRange;
|
|
18
|
+
import org.jruby.anno.JRubyMethod;
|
|
19
|
+
import org.jruby.anno.JRubyModule;
|
|
20
|
+
import org.jruby.runtime.Block;
|
|
21
|
+
import org.jruby.runtime.ThreadContext;
|
|
22
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
@JRubyModule(name = "MathTool")
|
|
29
|
+
public class MathToolModule {
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param runtime Ruby
|
|
34
|
+
*/
|
|
35
|
+
public static void createMathToolModule(Ruby runtime) {
|
|
36
|
+
RubyModule mtModule = runtime.defineModule("MathTool");
|
|
37
|
+
mtModule.defineAnnotatedMethods(MathToolModule.class);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param context ThreadContext
|
|
43
|
+
* @param recv IRubyObject
|
|
44
|
+
* @param args array of RubyRange (must be be numeric)
|
|
45
|
+
* @return mapped value RubyFloat
|
|
46
|
+
*/
|
|
47
|
+
@JRubyMethod(name = "map1d", rest = true, module = true)
|
|
48
|
+
public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
|
49
|
+
double value = (args[0] instanceof RubyFloat)
|
|
50
|
+
? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
|
51
|
+
RubyRange r1 = (RubyRange) args[1];
|
|
52
|
+
RubyRange r2 = (RubyRange) args[2];
|
|
53
|
+
double first1 = (r1.first(context) instanceof RubyFloat)
|
|
54
|
+
? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
|
|
55
|
+
double first2 = (r2.first(context) instanceof RubyFloat)
|
|
56
|
+
? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
|
|
57
|
+
double last1 = (r1.last(context) instanceof RubyFloat)
|
|
58
|
+
? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
|
|
59
|
+
double last2 = (r2.last(context) instanceof RubyFloat)
|
|
60
|
+
? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
|
|
61
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param context ThreadContext
|
|
67
|
+
* @param recv IRubyObject
|
|
68
|
+
* @param args array of RubyRange (must be be numeric)
|
|
69
|
+
* @return mapped value RubyFloat
|
|
70
|
+
*/
|
|
71
|
+
@JRubyMethod(name = "constrained_map", rest = true, module = true)
|
|
72
|
+
public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
|
73
|
+
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
|
74
|
+
RubyRange r1 = (RubyRange) args[1];
|
|
75
|
+
RubyRange r2 = (RubyRange) args[2];
|
|
76
|
+
double first1 = (r1.first(context) instanceof RubyFloat)
|
|
77
|
+
? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
|
|
78
|
+
double first2 = (r2.first(context) instanceof RubyFloat)
|
|
79
|
+
? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
|
|
80
|
+
double last1 = (r1.last(context) instanceof RubyFloat)
|
|
81
|
+
? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
|
|
82
|
+
double last2 = (r2.last(context) instanceof RubyFloat)
|
|
83
|
+
? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
|
|
84
|
+
double max = Math.max(first1, last1);
|
|
85
|
+
double min = Math.min(first1, last1);
|
|
86
|
+
if (value < min) {
|
|
87
|
+
return mapMt(context, min, first1, last1, first2, last2);
|
|
88
|
+
}
|
|
89
|
+
if (value > max) {
|
|
90
|
+
return mapMt(context, max, first1, last1, first2, last2);
|
|
91
|
+
}
|
|
92
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param context ThreadContext
|
|
98
|
+
* @param recv self IRubyObject
|
|
99
|
+
* @param args floats as in processing map function
|
|
100
|
+
* @return mapped value RubyFloat
|
|
101
|
+
*/
|
|
102
|
+
@JRubyMethod(name = "p5map", rest = true, module = true)
|
|
103
|
+
public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
|
104
|
+
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
|
105
|
+
double first1 = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
|
106
|
+
double first2 = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
|
|
107
|
+
double last1 = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
|
108
|
+
double last2 = (args[4] instanceof RubyFloat) ? ((RubyFloat) args[4]).getValue() : ((RubyFixnum) args[4]).getDoubleValue();
|
|
109
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A more correct version than processing.org version
|
|
114
|
+
*
|
|
115
|
+
* @param context ThreadContext
|
|
116
|
+
* @param recv self IRubyObject
|
|
117
|
+
* @param args args[2] should be between 0 and 1.0 if not returns start or
|
|
118
|
+
* stop
|
|
119
|
+
* @return lerped value RubyFloat
|
|
120
|
+
*/
|
|
121
|
+
@JRubyMethod(name = "lerp", rest = true, module = true)
|
|
122
|
+
public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
|
123
|
+
double start = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
|
124
|
+
double stop = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
|
125
|
+
double amount = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
|
126
|
+
if (amount <= 0) {
|
|
127
|
+
return args[0];
|
|
128
|
+
}
|
|
129
|
+
if (amount >= 1.0) {
|
|
130
|
+
return args[1];
|
|
131
|
+
}
|
|
132
|
+
return context.runtime.newFloat((1 - amount) * start + (stop * amount));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Identical to p5map(value, low, high, 0, 1). Numbers outside of the range
|
|
137
|
+
* are not clamped to 0 and 1, because out-of-range values are often
|
|
138
|
+
* intentional and useful.
|
|
139
|
+
*
|
|
140
|
+
* @param context ThreadContext
|
|
141
|
+
* @param recv IRubyObject
|
|
142
|
+
* @param args array of args must be be numeric
|
|
143
|
+
* @return mapped value RubyFloat
|
|
144
|
+
*/
|
|
145
|
+
@JRubyMethod(name = "norm", rest = true, module = true)
|
|
146
|
+
public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
|
147
|
+
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
|
148
|
+
double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
|
149
|
+
double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
|
150
|
+
return mapMt(context, value, start, stop, 0, 1.0);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Identical to p5map(value, low, high, 0, 1) but 'clamped'. Numbers outside
|
|
155
|
+
* of the range are clamped to 0 and 1,
|
|
156
|
+
*
|
|
157
|
+
* @param context ThreadContext
|
|
158
|
+
* @param recv IRubyObject
|
|
159
|
+
* @param args array of args must be be numeric
|
|
160
|
+
* @return mapped value RubyFloat
|
|
161
|
+
*/
|
|
162
|
+
@JRubyMethod(name = "norm_strict", rest = true, module = true)
|
|
163
|
+
public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
|
164
|
+
Ruby ruby = context.runtime;
|
|
165
|
+
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
|
166
|
+
double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
|
167
|
+
double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
|
168
|
+
double max = Math.max(start, stop);
|
|
169
|
+
double min = Math.min(start, stop);
|
|
170
|
+
if (value < min) {
|
|
171
|
+
return mapMt(context, min, start, stop, 0, 1.0);
|
|
172
|
+
}
|
|
173
|
+
if (value > max) {
|
|
174
|
+
return mapMt(context, max, start, stop, 0, 1.0);
|
|
175
|
+
}
|
|
176
|
+
return mapMt(context, value, start, stop, 0, 1.0);
|
|
177
|
+
}
|
|
178
|
+
// start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
|
|
179
|
+
static final RubyFloat mapMt(ThreadContext context, double value, double first1, double last1, double first2, double last2) {
|
|
180
|
+
double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
|
|
181
|
+
return context.runtime.newFloat(result);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Provides processing constrain method as a ruby module method
|
|
186
|
+
*
|
|
187
|
+
* @param context ThreadContext
|
|
188
|
+
* @param recv IRubyObject
|
|
189
|
+
* @param args array of args must be be numeric
|
|
190
|
+
* @return original or limit values
|
|
191
|
+
*/
|
|
192
|
+
@JRubyMethod(name = "constrain", rest = true, module = true)
|
|
193
|
+
public static IRubyObject constrainValue(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
|
194
|
+
RubyFloat value = args[0].convertToFloat();
|
|
195
|
+
RubyFloat start = args[1].convertToFloat();
|
|
196
|
+
RubyFloat stop = args[2].convertToFloat();
|
|
197
|
+
if (value.op_ge(context, start).isTrue() && value.op_le(context, stop).isTrue()) {
|
|
198
|
+
return args[0];
|
|
199
|
+
} else if (value.op_ge(context, start).isTrue()) {
|
|
200
|
+
return args[2];
|
|
201
|
+
} else {
|
|
202
|
+
return args[1];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Provides propane grid method as a ruby module method
|
|
208
|
+
*
|
|
209
|
+
* @param context ThreadContext
|
|
210
|
+
* @param recv IRubyObject
|
|
211
|
+
* @param args array of args should be Fixnum
|
|
212
|
+
* @param block { |x, y| `do something` }
|
|
213
|
+
* @return nil
|
|
214
|
+
*/
|
|
215
|
+
@JRubyMethod(name = "grid", rest = true, module = true)
|
|
216
|
+
public static IRubyObject createGrid(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
|
|
217
|
+
int row = (int) args[0].toJava(Integer.class);
|
|
218
|
+
int column = (int) args[1].toJava(Integer.class);
|
|
219
|
+
int rowStep = 1;
|
|
220
|
+
int colStep = 1;
|
|
221
|
+
if (args.length == 4){
|
|
222
|
+
rowStep = (int) args[2].toJava(Integer.class);
|
|
223
|
+
colStep = (int) args[3].toJava(Integer.class);
|
|
224
|
+
}
|
|
225
|
+
if (block.isGiven()) {
|
|
226
|
+
int tempRow = row / rowStep;
|
|
227
|
+
for (int z = 0; z < (tempRow * (column / colStep)); z++){
|
|
228
|
+
int x = z % tempRow;
|
|
229
|
+
int y = z / tempRow;
|
|
230
|
+
block.yieldSpecific(context, context.runtime.newFixnum(x * rowStep), context.runtime.newFixnum(y * colStep));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return context.nil;
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The purpose of this class is to load the MathTool into PiCrate runtime
|
|
3
|
+
* Copyright (C) 18 Martin Prout. This code is free software; you can
|
|
4
|
+
* redistribute it and/or modify it under the terms of the GNU Lesser General
|
|
5
|
+
* Public License as published by the Free Software Foundation; either version
|
|
6
|
+
* 2.1 of the License, or (at your option) any later version.
|
|
7
|
+
*
|
|
8
|
+
* Obtain a copy of the license at http://www.gnu.org/licenses/gpl-3.0-standalone.html
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
package monkstone;
|
|
12
|
+
|
|
13
|
+
import java.io.IOException;
|
|
14
|
+
import monkstone.fastmath.Deglut;
|
|
15
|
+
import monkstone.vecmath.vec2.Vec2;
|
|
16
|
+
import monkstone.vecmath.vec3.Vec3;
|
|
17
|
+
import org.jruby.Ruby;
|
|
18
|
+
import org.jruby.runtime.load.Library;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
public class PicrateLibrary implements Library{
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param runtime
|
|
29
|
+
*/
|
|
30
|
+
public static void load(final Ruby runtime) {
|
|
31
|
+
MathToolModule.createMathToolModule(runtime);
|
|
32
|
+
Deglut.createDeglut(runtime);
|
|
33
|
+
Vec2.createVec2(runtime);
|
|
34
|
+
Vec3.createVec3(runtime);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param runtime
|
|
40
|
+
* @param wrap
|
|
41
|
+
* @throws java.io.IOException
|
|
42
|
+
*/
|
|
43
|
+
@Override
|
|
44
|
+
public void load(final Ruby runtime, boolean wrap) throws IOException {
|
|
45
|
+
load(runtime);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
package monkstone.core;
|
|
2
|
+
|
|
3
|
+
import processing.core.PApplet;
|
|
4
|
+
import static processing.core.PConstants.*;
|
|
5
|
+
import processing.event.MouseEvent;
|
|
6
|
+
import processing.event.KeyEvent;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The purpose of this class is to enable
|
|
10
|
+
* access to processing pre, draw and post loops in
|
|
11
|
+
* ruby-processing as a regular java library class.
|
|
12
|
+
* Also included background, fill and stroke methods.
|
|
13
|
+
* PConstants should also be available from static import
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
public abstract class LibraryProxy {
|
|
17
|
+
|
|
18
|
+
private final PApplet app;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Useful accessors
|
|
22
|
+
*/
|
|
23
|
+
public int width, height;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param app PApplet
|
|
28
|
+
*/
|
|
29
|
+
public LibraryProxy(PApplet app) {
|
|
30
|
+
this.app = app;
|
|
31
|
+
this.width = app.width;
|
|
32
|
+
this.height = app.height;
|
|
33
|
+
setActive(true);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Extending classes can override this, gives access to, by reflection,
|
|
38
|
+
* processing PApplet pre loop (called before draw)
|
|
39
|
+
*/
|
|
40
|
+
public void pre(){}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Extending classes must implement this gives access to processing PApplet
|
|
44
|
+
* draw loop
|
|
45
|
+
*/
|
|
46
|
+
public abstract void draw();
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Extending classes can override this, gives access to, by reflection,
|
|
50
|
+
* processing PApplet post loop (called after draw)
|
|
51
|
+
*/
|
|
52
|
+
public void post(){}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Extending classes can override this, gives access to, by reflection,
|
|
56
|
+
* processing PApplet post loop (called after draw)
|
|
57
|
+
* @param e
|
|
58
|
+
*/
|
|
59
|
+
public void keyEvent(KeyEvent e){}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Extending classes can override this, gives access to, by reflection,
|
|
63
|
+
* processing PApplet post loop (called after draw)
|
|
64
|
+
* @param e
|
|
65
|
+
*/
|
|
66
|
+
public void mouseEvent(MouseEvent e){}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Register or unregister reflection methods
|
|
70
|
+
* @param active
|
|
71
|
+
*/
|
|
72
|
+
final void setActive(boolean active) {
|
|
73
|
+
if (active) {
|
|
74
|
+
this.app.registerMethod("pre", this);
|
|
75
|
+
this.app.registerMethod("draw", this);
|
|
76
|
+
this.app.registerMethod("post", this);
|
|
77
|
+
this.app.registerMethod("mouseEvent", this);
|
|
78
|
+
this.app.registerMethod("keyEvent", this);
|
|
79
|
+
this.app.registerMethod("dispose", this);
|
|
80
|
+
} else {
|
|
81
|
+
this.app.unregisterMethod("pre", this);
|
|
82
|
+
this.app.unregisterMethod("draw", this);
|
|
83
|
+
this.app.unregisterMethod("post", this);
|
|
84
|
+
this.app.unregisterMethod("mouseEvent", this);
|
|
85
|
+
this.app.unregisterMethod("keyEvent", this);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Simple signature for background hides need to call app
|
|
91
|
+
* @param col int
|
|
92
|
+
*/
|
|
93
|
+
public void background(int col) {
|
|
94
|
+
this.app.background(col);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Simple signature for fill hides need to call app
|
|
99
|
+
* @param col int
|
|
100
|
+
*/
|
|
101
|
+
public void fill(int col) {
|
|
102
|
+
this.app.fill(col);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Simple signature for stroke hides need to call app
|
|
107
|
+
* @param col int
|
|
108
|
+
*/
|
|
109
|
+
public void stroke(int col) {
|
|
110
|
+
this.app.stroke(col);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Access applet if we must
|
|
115
|
+
* @return applet PApplet
|
|
116
|
+
*/
|
|
117
|
+
public PApplet app() {
|
|
118
|
+
return this.app;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* required for processing
|
|
123
|
+
*/
|
|
124
|
+
public void dispose() {
|
|
125
|
+
setActive(false);
|
|
126
|
+
}
|
|
127
|
+
}
|