propane 3.3.1-java → 3.6.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -2
- data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
- data/.mvn/wrapper/maven-wrapper.properties +2 -3
- data/.travis.yml +9 -0
- data/CHANGELOG.md +17 -5
- data/Gemfile +2 -0
- data/README.md +17 -8
- data/Rakefile +16 -30
- data/bin/propane +3 -1
- data/lib/propane.rb +6 -4
- data/lib/propane/app.rb +20 -10
- data/lib/propane/creators/sketch_class.rb +7 -1
- data/lib/propane/creators/sketch_factory.rb +4 -2
- data/lib/propane/creators/sketch_writer.rb +1 -0
- data/lib/propane/helper_methods.rb +23 -24
- data/lib/propane/helpers/numeric.rb +2 -0
- data/lib/propane/helpers/version_error.rb +1 -0
- data/lib/propane/library.rb +5 -1
- data/lib/propane/library_loader.rb +2 -0
- data/lib/propane/native_folder.rb +21 -15
- data/lib/propane/native_loader.rb +3 -0
- data/lib/propane/runner.rb +14 -6
- data/lib/propane/version.rb +2 -1
- data/library/boids/boids.rb +21 -11
- data/library/color_group/color_group.rb +28 -0
- data/library/control_panel/control_panel.rb +8 -5
- data/library/dxf/dxf.rb +6 -0
- data/library/file_chooser/chooser.rb +10 -9
- data/library/file_chooser/file_chooser.rb +10 -9
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +7 -0
- data/library/simplex_noise/simplex_noise.rb +2 -0
- data/library/slider/slider.rb +23 -22
- data/library/vector_utils/vector_utils.rb +4 -0
- data/library/video_event/video_event.rb +4 -1
- data/mvnw +127 -51
- data/mvnw.cmd +182 -145
- data/pom.rb +53 -50
- data/pom.xml +17 -8
- data/propane.gemspec +13 -11
- data/src/main/java/monkstone/ColorUtil.java +13 -1
- data/src/main/java/monkstone/MathToolModule.java +253 -203
- data/src/main/java/monkstone/PropaneLibrary.java +2 -2
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
- 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 +7 -6
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
- data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +2164 -1661
- data/src/main/java/processing/awt/PImageAWT.java +377 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +280 -268
- data/src/main/java/processing/awt/PSurfaceAWT.java +942 -829
- data/src/main/java/processing/awt/ShimAWT.java +581 -0
- data/src/main/java/processing/core/PApplet.java +831 -824
- data/src/main/java/processing/core/PConstants.java +477 -447
- data/src/main/java/processing/core/PFont.java +914 -880
- data/src/main/java/processing/core/PGraphics.java +229 -213
- data/src/main/java/processing/core/PImage.java +620 -318
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +478 -409
- data/src/main/java/processing/core/PMatrix3D.java +762 -735
- data/src/main/java/processing/core/PShape.java +2888 -2652
- data/src/main/java/processing/core/PShapeOBJ.java +436 -415
- data/src/main/java/processing/core/PShapeSVG.java +1702 -1479
- data/src/main/java/processing/core/PStyle.java +40 -37
- data/src/main/java/processing/core/PSurface.java +139 -97
- data/src/main/java/processing/core/PSurfaceNone.java +296 -208
- data/src/main/java/processing/core/PVector.java +997 -965
- data/src/main/java/processing/core/ThinkDifferent.java +12 -17
- data/src/main/java/processing/data/DoubleDict.java +756 -710
- data/src/main/java/processing/data/DoubleList.java +749 -696
- data/src/main/java/processing/data/FloatDict.java +748 -702
- data/src/main/java/processing/data/FloatList.java +751 -697
- data/src/main/java/processing/data/IntDict.java +720 -673
- data/src/main/java/processing/data/IntList.java +699 -633
- data/src/main/java/processing/data/JSONArray.java +931 -873
- data/src/main/java/processing/data/JSONObject.java +1262 -1165
- data/src/main/java/processing/data/JSONTokener.java +351 -341
- data/src/main/java/processing/data/LongDict.java +710 -663
- data/src/main/java/processing/data/LongList.java +701 -635
- data/src/main/java/processing/data/Sort.java +37 -41
- data/src/main/java/processing/data/StringDict.java +525 -486
- data/src/main/java/processing/data/StringList.java +626 -580
- data/src/main/java/processing/data/Table.java +3690 -3510
- data/src/main/java/processing/data/TableRow.java +182 -183
- data/src/main/java/processing/data/XML.java +957 -883
- data/src/main/java/processing/dxf/RawDXF.java +404 -0
- data/src/main/java/processing/event/Event.java +87 -66
- data/src/main/java/processing/event/KeyEvent.java +48 -41
- data/src/main/java/processing/event/MouseEvent.java +88 -113
- data/src/main/java/processing/event/TouchEvent.java +10 -6
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
- data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
- data/src/main/java/processing/net/Client.java +744 -0
- data/src/main/java/processing/net/Server.java +388 -0
- data/src/main/java/processing/opengl/FontTexture.java +289 -270
- data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
- data/src/main/java/processing/opengl/LinePath.java +547 -500
- data/src/main/java/processing/opengl/LineStroker.java +588 -581
- data/src/main/java/processing/opengl/PGL.java +3047 -2914
- data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
- data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
- data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
- data/src/main/java/processing/opengl/PShader.java +1266 -1257
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
- data/src/main/java/processing/opengl/Texture.java +1492 -1401
- data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
- data/test/create_test.rb +21 -20
- data/test/deglut_spec_test.rb +4 -2
- data/test/helper_methods_test.rb +49 -20
- data/test/math_tool_test.rb +39 -32
- data/test/native_folder.rb +47 -0
- data/test/respond_to_test.rb +3 -2
- data/test/sketches/key_event.rb +2 -2
- data/test/sketches/library/my_library/my_library.rb +3 -0
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +35 -22
- data/vendors/Rakefile +33 -62
- metadata +54 -45
- data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
- data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
- data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
- data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
- data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
- data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
- data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
- data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
- data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
- data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
- data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
- data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
- data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
- data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
- data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
- data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
- data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
- data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
- data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
- data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
- data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
data/propane.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'propane/version'
|
5
6
|
|
@@ -8,14 +9,14 @@ Gem::Specification.new do |gem|
|
|
8
9
|
gem.version = Propane::VERSION
|
9
10
|
gem.authors = ['monkstone']
|
10
11
|
gem.email = ['mamba2928@yahoo.co.uk']
|
11
|
-
gem.licenses = %w
|
12
|
+
gem.licenses = %w[GPL-3.0 LGPL-2.0]
|
12
13
|
gem.description = <<-EOS
|
13
14
|
A batteries included version of processing in ruby targetting jdk11.
|
14
15
|
EOS
|
15
|
-
gem.summary =
|
16
|
+
gem.summary = 'ruby implementation of processing-4.0 on MacOS, linux and windows (64bit only)'
|
16
17
|
gem.homepage = 'https://ruby-processing.github.io/propane/'
|
17
|
-
gem.files = `git ls-files`.split(
|
18
|
-
gem.files <<
|
18
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
19
|
+
gem.files << "lib/propane-#{Propane::VERSION}.jar"
|
19
20
|
gem.files << 'lib/gluegen-rt.jar'
|
20
21
|
gem.files << 'lib/jogl-all.jar'
|
21
22
|
gem.files << 'lib/gluegen-rt-natives-linux-amd64.jar'
|
@@ -24,12 +25,13 @@ Gem::Specification.new do |gem|
|
|
24
25
|
gem.files << 'lib/jogl-all-natives-linux-amd64.jar'
|
25
26
|
gem.files << 'lib/jogl-all-natives-macosx-universal.jar'
|
26
27
|
gem.files << 'lib/jogl-all-natives-windows-amd64.jar'
|
27
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
28
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
28
29
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
29
|
-
gem.add_development_dependency '
|
30
|
-
gem.add_development_dependency 'minitest', '~> 5.
|
31
|
-
gem.add_runtime_dependency '
|
30
|
+
gem.add_development_dependency 'jruby-openssl', '~> 0.1.0', '>=0.1.3'
|
31
|
+
gem.add_development_dependency 'minitest', '~> 5.14'
|
32
|
+
gem.add_runtime_dependency 'rake', '~> 12.3'
|
33
|
+
gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.2'
|
32
34
|
gem.require_paths = ['lib']
|
33
35
|
gem.platform = 'java'
|
34
|
-
gem.requirements << 'java runtime >= 11.0.
|
36
|
+
gem.requirements << 'java runtime >= 11.0.2+'
|
35
37
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
* in their sketches. Includes a method to efficiently convert an array of web
|
4
4
|
* strings to an array of color int, and another to convert an array of color
|
5
5
|
* int to a string that can be used in ruby code (to generate web color array).
|
6
|
-
* Copyright (c) 2015-
|
6
|
+
* Copyright (c) 2015-20 Martin Prout.
|
7
7
|
* This utility is free software; you can redistribute it and/or modify
|
8
8
|
* it under the terms of the GNU Lesser General Public License as published by
|
9
9
|
* the Free Software Foundation; either version 2.1 of the License, or (at
|
@@ -13,6 +13,7 @@
|
|
13
13
|
*/
|
14
14
|
package monkstone;
|
15
15
|
|
16
|
+
import java.util.Random;
|
16
17
|
/**
|
17
18
|
*
|
18
19
|
* @author Martin Prout
|
@@ -102,6 +103,17 @@ public class ColorUtil {
|
|
102
103
|
return (float) hex;
|
103
104
|
}
|
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
|
+
|
105
117
|
/**
|
106
118
|
*
|
107
119
|
* @param hue
|
@@ -1,13 +1,14 @@
|
|
1
1
|
/**
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
+
*/
|
11
12
|
package monkstone;
|
12
13
|
|
13
14
|
import org.jruby.Ruby;
|
@@ -22,216 +23,265 @@ import org.jruby.runtime.ThreadContext;
|
|
22
23
|
import org.jruby.runtime.builtin.IRubyObject;
|
23
24
|
|
24
25
|
/**
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
*
|
27
|
+
* @author Martin Prout
|
28
|
+
*/
|
28
29
|
@JRubyModule(name = "MathTool")
|
29
30
|
public class MathToolModule {
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
+
}
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
+
}
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
if (value > max) {
|
90
|
-
return mapMt(context, max, first1, last1, first2, last2);
|
91
|
-
}
|
92
|
-
return mapMt(context, value, first1, last1, first2, last2);
|
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);
|
93
89
|
}
|
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);
|
90
|
+
if (value > max) {
|
91
|
+
return mapMt(context, max, first1, last1, first2, last2);
|
110
92
|
}
|
93
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
94
|
+
}
|
111
95
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
}
|
129
|
-
if (amount >= 1.0) {
|
130
|
-
return args[1];
|
131
|
-
}
|
132
|
-
return context.runtime.newFloat((1 - amount) * start + (stop * amount));
|
133
|
-
}
|
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
|
+
}
|
134
112
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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];
|
151
129
|
}
|
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);
|
130
|
+
if (amount >= 1.0) {
|
131
|
+
return args[1];
|
177
132
|
}
|
178
|
-
|
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) {
|
179
165
|
|
180
|
-
|
181
|
-
|
182
|
-
|
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);
|
183
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
|
+
}
|
184
185
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
}
|
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
205
|
}
|
206
|
+
}
|
206
207
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
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));
|
233
282
|
}
|
234
|
-
|
235
|
-
|
283
|
+
}
|
236
284
|
}
|
285
|
+
return context.nil;
|
286
|
+
}
|
237
287
|
}
|