propane 3.4.0-java → 3.4.1-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/.travis.yml +2 -2
- data/CHANGELOG.md +2 -0
- data/README.md +12 -7
- data/Rakefile +2 -2
- data/lib/propane.rb +2 -2
- data/lib/propane/app.rb +18 -9
- data/lib/propane/helper_methods.rb +1 -1
- data/lib/propane/runner.rb +1 -1
- data/lib/propane/version.rb +1 -1
- data/library/color_group/color_group.rb +26 -0
- data/library/dxf/dxf.rb +4 -0
- data/library/net/net.rb +5 -0
- data/library/video_event/video_event.rb +2 -1
- data/pom.rb +3 -3
- data/pom.xml +3 -3
- data/propane.gemspec +1 -1
- data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
- data/src/main/java/monkstone/ColorUtil.java +14 -0
- data/src/main/java/monkstone/MathToolModule.java +243 -194
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +6 -5
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -2
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
- data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +10 -26
- data/src/main/java/processing/awt/PSurfaceAWT.java +1 -1
- data/src/main/java/processing/core/PApplet.java +1236 -599
- data/src/main/java/processing/core/PGraphics.java +59 -59
- data/src/main/java/processing/core/PImage.java +528 -129
- data/src/main/java/processing/core/PShape.java +10 -10
- data/src/main/java/processing/core/PVector.java +2 -2
- data/src/main/java/processing/core/ThinkDifferent.java +5 -7
- data/src/main/java/processing/dxf/RawDXF.java +404 -0
- 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 +19 -20
- data/src/main/java/processing/opengl/FrameBuffer.java +27 -17
- data/src/main/java/processing/opengl/LinePath.java +512 -508
- data/src/main/java/processing/opengl/PGL.java +3106 -3066
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +4 -4
- data/src/main/java/processing/opengl/PShader.java +1442 -1341
- data/vendors/Rakefile +3 -27
- metadata +12 -25
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f88b5c1c3e6afb699ccabb96cd98d9b60aa9d8ec0614d59a601a3e8df074946b
|
4
|
+
data.tar.gz: 6943a2c007f56b01faf2ce1e3636f407d53dbf80c36458c27598e4365da46b48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0162ff22dcdda3764363e5fc2c1c07c9619a3f97e209837faa125a8d4fd6412e6077cd3ba3a436efbd33db7371a68adcbb166e46d324846aecff155ef4690c44
|
7
|
+
data.tar.gz: c4fad0d7f20ca7b4b9fb5f840caf63da4d8f9f21805029e46fa024ce6c2b5d8cb7263df9ddba95932d2825d9510bd6bbd47884a478ce55aa135bcee2df4ab06d
|
data/.mvn/extensions.xml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Propane 
|
1
|
+
# Propane [](https://badge.fury.io/rb/propane) 
|
2
2
|
|
3
|
-
This version is intended to work with openjdk11+, @sampottinger is currently working on [vanilla processing][vanilla] which will enable JRubyArt to catch up.
|
3
|
+
This version is intended to work with openjdk11+, @sampottinger is currently working on [vanilla processing][vanilla] which will enable JRubyArt to catch up.
|
4
4
|
|
5
5
|
A slim layer to communicate with Processing from JRuby, features maven build. We have created a configuration free version of ruby processing, for processing-4.0+, where we include a modified processing core (`public runPropane()` to replace `protected runSketch()`. These jars are small enough to include in a gem distribution, and hence we do not require configuration. This has created a scriptable version, ie files get run direct from jruby. Currently JavaFX is unsupported again @sampottinger is currently working on [vanilla processing][vanilla] to use OpenJFX. It would be nice make use of java modules, but I think we should let jruby project do that first (unless processing.org beat them to it).
|
6
6
|
|
@@ -8,9 +8,12 @@ adjust above for your OS/distro setup.
|
|
8
8
|
|
9
9
|
## Requirements
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
- `
|
11
|
+
There may be a linker issue with P2D or P3D sketches with stock openjdk with some linux distros, in which case you might find [Adopt open jdk binaries][adopt] will work for you.
|
12
|
+
|
13
|
+
- `jdk-11.0.3+`
|
14
|
+
- `jruby-9.2.9.0`
|
15
|
+
|
16
|
+
Currently you can ignore `illegal reflective access` warnings, see [here how to suppress them][warning].
|
14
17
|
|
15
18
|
## Building and testing
|
16
19
|
|
@@ -24,10 +27,10 @@ rake javadoc
|
|
24
27
|
|
25
28
|
```bash
|
26
29
|
jgem install propane # from rubygems
|
27
|
-
jgem install propane-3.
|
30
|
+
jgem install propane-3.4.1-java.gem # local install
|
28
31
|
# Alternative
|
29
32
|
jruby -S gem install propane # from rubygems
|
30
|
-
jruby -S gem install propane-3.
|
33
|
+
jruby -S gem install propane-3.4.1-java.gem # local install
|
31
34
|
```
|
32
35
|
|
33
36
|
## Check Install
|
@@ -95,6 +98,8 @@ propane --install samples
|
|
95
98
|
```
|
96
99
|
please move existing `propane_samples` if you wish to keep them. The current release features several PixelFlow glsl library examples, including a few shadertoy demos as sketches.
|
97
100
|
|
101
|
+
[adopt]: https://adoptopenjdk.net/
|
98
102
|
[building]:http://ruby-processing.github.io/building/building/
|
99
103
|
[gh-pages]:https://ruby-processing.github.io/propane/
|
100
104
|
[vanilla]:https://github.com/processing/processing/pull/5753
|
105
|
+
[warning]: https://monkstone.github.io/jruby_art/update/2019/09/10/Reflective_Access.html
|
data/Rakefile
CHANGED
data/lib/propane.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'java'
|
3
3
|
unless defined? PROPANE_ROOT
|
4
|
-
$LOAD_PATH << File.
|
5
|
-
PROPANE_ROOT = File.
|
4
|
+
$LOAD_PATH << File.dirname(__dir__)
|
5
|
+
PROPANE_ROOT = File.dirname(__dir__)
|
6
6
|
end
|
7
7
|
Dir["#{PROPANE_ROOT}/lib/*.jar"].each do |jar|
|
8
8
|
require jar
|
data/lib/propane/app.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
|
+
|
2
3
|
require_relative 'helper_methods'
|
3
4
|
require_relative 'library_loader'
|
4
5
|
|
@@ -8,7 +9,7 @@ module Propane
|
|
8
9
|
# Load vecmath, fastmath and mathtool modules
|
9
10
|
Java::Monkstone::PropaneLibrary.load(JRuby.runtime)
|
10
11
|
SKETCH_ROOT = File.absolute_path('.')
|
11
|
-
|
12
|
+
# import custom Vecmath renderers
|
12
13
|
module Render
|
13
14
|
java_import 'monkstone.vecmath.GfxRender'
|
14
15
|
java_import 'monkstone.vecmath.ShapeRender'
|
@@ -49,13 +50,15 @@ module Propane
|
|
49
50
|
|
50
51
|
# All sketches extend this class
|
51
52
|
class App < PApplet
|
52
|
-
include
|
53
|
+
include HelperMethods
|
54
|
+
include Math
|
55
|
+
include MathTool
|
56
|
+
include Render
|
53
57
|
# Alias some methods for familiarity for Shoes coders.
|
54
58
|
alias oval ellipse
|
55
59
|
alias stroke_width stroke_weight
|
56
60
|
alias rgb color
|
57
61
|
alias gray color
|
58
|
-
field_reader :surface
|
59
62
|
|
60
63
|
def sketch_class
|
61
64
|
self.class.sketch_class
|
@@ -75,8 +78,8 @@ module Propane
|
|
75
78
|
#
|
76
79
|
class << self
|
77
80
|
# Handy getters and setters on the class go here:
|
78
|
-
attr_accessor :sketch_class, :library_loader, :
|
79
|
-
|
81
|
+
attr_accessor :sketch_class, :library_loader, :arguments, :options
|
82
|
+
attr_reader :surface
|
80
83
|
def load_libraries(*args)
|
81
84
|
library_loader ||= LibraryLoader.new
|
82
85
|
library_loader.load_library(*args)
|
@@ -99,6 +102,7 @@ module Propane
|
|
99
102
|
# Processing call them by their expected Java names.
|
100
103
|
def method_added(method_name) #:nodoc:
|
101
104
|
return unless METHODS_TO_ALIAS.key?(method_name)
|
105
|
+
|
102
106
|
alias_method METHODS_TO_ALIAS[method_name], method_name
|
103
107
|
end
|
104
108
|
end
|
@@ -112,12 +116,14 @@ module Propane
|
|
112
116
|
proxy_java_fields
|
113
117
|
raise TypeError unless options.is_a? Hash
|
114
118
|
raise TypeError unless arguments.is_a? Array
|
119
|
+
|
115
120
|
# Set up the sketch.
|
116
121
|
super()
|
117
122
|
post_initialize(options)
|
118
123
|
Propane.app = self
|
119
124
|
@arguments = arguments
|
120
125
|
@options = options
|
126
|
+
@surface = get_surface
|
121
127
|
run_propane
|
122
128
|
end
|
123
129
|
|
@@ -130,8 +136,7 @@ module Propane
|
|
130
136
|
super(*args)
|
131
137
|
end
|
132
138
|
|
133
|
-
def post_initialize(_args)
|
134
|
-
end
|
139
|
+
def post_initialize(_args); end
|
135
140
|
|
136
141
|
def sketch_title(title)
|
137
142
|
surface.set_title(title)
|
@@ -164,6 +169,7 @@ module Propane
|
|
164
169
|
# Processing call them by their expected Java names.
|
165
170
|
def method_added(method_name) #:nodoc:
|
166
171
|
return unless METHODS_TO_ALIAS.key?(method_name)
|
172
|
+
|
167
173
|
alias_method METHODS_TO_ALIAS[method_name], method_name
|
168
174
|
end
|
169
175
|
end
|
@@ -181,7 +187,10 @@ module Propane
|
|
181
187
|
|
182
188
|
def method_missing(name, *args, &block)
|
183
189
|
return Propane.app.send(name, *args) if Propane.app.respond_to? name
|
190
|
+
|
184
191
|
super
|
185
192
|
end
|
186
|
-
end
|
187
|
-
end
|
193
|
+
end
|
194
|
+
# end Processing::Proxy
|
195
|
+
end
|
196
|
+
# end Propane
|
data/lib/propane/runner.rb
CHANGED
@@ -40,7 +40,7 @@ module Propane
|
|
40
40
|
end
|
41
41
|
|
42
42
|
options[:install] = false
|
43
|
-
message = '<Samples><
|
43
|
+
message = '<Samples><Video><Sound> Install samples or library'
|
44
44
|
opts.on('-i', '--install', message) do
|
45
45
|
options[:install] = true
|
46
46
|
end
|
data/lib/propane/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
java_import Java::Monkstone::ColorUtil
|
2
|
+
|
3
|
+
# class wraps a java color array, supports shuffle!, last and ruby_string
|
4
|
+
# as well as ability to initialize with an array of "web" color string
|
5
|
+
class ColorGroup
|
6
|
+
attr_reader :colors
|
7
|
+
def initialize(p5cols)
|
8
|
+
@colors = p5cols
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.from_web_array(web)
|
12
|
+
ColorGroup.new(ColorUtil.web_array(web.to_java(:string)))
|
13
|
+
end
|
14
|
+
|
15
|
+
def shuffle!
|
16
|
+
@colors = ColorUtil.shuffle(colors)
|
17
|
+
end
|
18
|
+
|
19
|
+
def ruby_string
|
20
|
+
ColorUtil.rubyString(colors)
|
21
|
+
end
|
22
|
+
|
23
|
+
def last
|
24
|
+
colors[0]
|
25
|
+
end
|
26
|
+
end
|
data/library/dxf/dxf.rb
ADDED
data/library/net/net.rb
ADDED
data/pom.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
project 'propane', 'https://github.com/monkstone/propane' do
|
2
2
|
|
3
3
|
model_version '4.0.0'
|
4
|
-
id 'propane:propane:3.4.
|
4
|
+
id 'propane:propane:3.4.1'
|
5
5
|
packaging 'jar'
|
6
6
|
|
7
7
|
description 'An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.'
|
@@ -45,8 +45,8 @@ project 'propane', 'https://github.com/monkstone/propane' do
|
|
45
45
|
'jogl.version' => '2.3.2',
|
46
46
|
'jruby.api' => 'http://jruby.org/apidocs/' )
|
47
47
|
|
48
|
-
pom 'org.jruby:jruby:9.2.
|
49
|
-
jar 'org.processing:video:3.
|
48
|
+
pom 'org.jruby:jruby:9.2.9.0'
|
49
|
+
jar 'org.processing:video:3.3.7'
|
50
50
|
jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
|
51
51
|
jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
|
52
52
|
|
data/pom.xml
CHANGED
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
|
|
11
11
|
<modelVersion>4.0.0</modelVersion>
|
12
12
|
<groupId>propane</groupId>
|
13
13
|
<artifactId>propane</artifactId>
|
14
|
-
<version>3.4.
|
14
|
+
<version>3.4.1</version>
|
15
15
|
<name>propane</name>
|
16
16
|
<description>An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.</description>
|
17
17
|
<url>https://github.com/monkstone/propane</url>
|
@@ -74,13 +74,13 @@ DO NOT MODIFIY - GENERATED CODE
|
|
74
74
|
<dependency>
|
75
75
|
<groupId>org.jruby</groupId>
|
76
76
|
<artifactId>jruby</artifactId>
|
77
|
-
<version>9.2.
|
77
|
+
<version>9.2.9.0</version>
|
78
78
|
<type>pom</type>
|
79
79
|
</dependency>
|
80
80
|
<dependency>
|
81
81
|
<groupId>org.processing</groupId>
|
82
82
|
<artifactId>video</artifactId>
|
83
|
-
<version>3.
|
83
|
+
<version>3.3.7</version>
|
84
84
|
</dependency>
|
85
85
|
<dependency>
|
86
86
|
<groupId>org.jogamp.jogl</groupId>
|
data/propane.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.summary = %q{ruby implementation of processing-4.0 on MacOS, linux and windows (64bit only)}
|
16
16
|
gem.homepage = 'https://ruby-processing.github.io/propane/'
|
17
17
|
gem.files = `git ls-files`.split($/)
|
18
|
-
gem.files << 'lib/propane-3.4.
|
18
|
+
gem.files << 'lib/propane-3.4.1.jar'
|
19
19
|
gem.files << 'lib/gluegen-rt.jar'
|
20
20
|
gem.files << 'lib/jogl-all.jar'
|
21
21
|
gem.files << 'lib/gluegen-rt-natives-linux-amd64.jar'
|
@@ -19,8 +19,9 @@
|
|
19
19
|
*/
|
20
20
|
package japplemenubar;
|
21
21
|
|
22
|
-
import java.io
|
23
|
-
|
22
|
+
import java.io.File;
|
23
|
+
import java.io.IOException;
|
24
|
+
import java.io.InputStream;
|
24
25
|
import processing.core.PApplet;
|
25
26
|
|
26
27
|
|
@@ -58,7 +59,6 @@ public class JAppleMenuBar {
|
|
58
59
|
}
|
59
60
|
} catch (IOException e) {
|
60
61
|
sadness("Unknown error, here's the stack trace.");
|
61
|
-
e.printStackTrace();
|
62
62
|
}
|
63
63
|
}
|
64
64
|
|
@@ -13,6 +13,9 @@
|
|
13
13
|
*/
|
14
14
|
package monkstone;
|
15
15
|
|
16
|
+
import java.util.ArrayList;
|
17
|
+
import java.util.List;
|
18
|
+
import java.util.Random;
|
16
19
|
/**
|
17
20
|
*
|
18
21
|
* @author Martin Prout
|
@@ -102,6 +105,17 @@ public class ColorUtil {
|
|
102
105
|
return (float) hex;
|
103
106
|
}
|
104
107
|
|
108
|
+
static public int[] shuffle(int[] cols) {
|
109
|
+
Random rgen = new Random(); // Random number generator
|
110
|
+
for (int i = 0; i < cols.length; i++) {
|
111
|
+
int randomPosition = rgen.nextInt(cols.length);
|
112
|
+
int temp = cols[i];
|
113
|
+
cols[i] = cols[randomPosition];
|
114
|
+
cols[randomPosition] = temp;
|
115
|
+
}
|
116
|
+
return cols;
|
117
|
+
}
|
118
|
+
|
105
119
|
/**
|
106
120
|
*
|
107
121
|
* @param hue
|
@@ -22,216 +22,265 @@ import org.jruby.runtime.ThreadContext;
|
|
22
22
|
import org.jruby.runtime.builtin.IRubyObject;
|
23
23
|
|
24
24
|
/**
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
*
|
26
|
+
* @author Martin Prout
|
27
|
+
*/
|
28
28
|
@JRubyModule(name = "MathTool")
|
29
29
|
public class MathToolModule {
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
63
|
|
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);
|
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);
|
93
88
|
}
|
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);
|
89
|
+
if (value > max) {
|
90
|
+
return mapMt(context, max, first1, last1, first2, last2);
|
110
91
|
}
|
92
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
93
|
+
}
|
111
94
|
|
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
|
-
}
|
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
|
+
}
|
134
111
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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];
|
151
128
|
}
|
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);
|
129
|
+
if (amount >= 1.0) {
|
130
|
+
return args[1];
|
177
131
|
}
|
178
|
-
|
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
|
+
}
|
179
152
|
|
180
|
-
|
181
|
-
|
182
|
-
|
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
|
+
|
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);
|
183
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
|
+
Ruby ruby = context.runtime;
|
181
|
+
double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
|
182
|
+
return ruby.newFloat(result);
|
183
|
+
}
|
184
184
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
}
|
185
|
+
/**
|
186
|
+
* Provides processing constrain method as a ruby module method
|
187
|
+
*
|
188
|
+
* @param context ThreadContext
|
189
|
+
* @param recv IRubyObject
|
190
|
+
* @param args array of args must be be numeric
|
191
|
+
* @return original or limit values
|
192
|
+
*/
|
193
|
+
@JRubyMethod(name = "constrain", rest = true, module = true)
|
194
|
+
public static IRubyObject constrainValue(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
195
|
+
RubyFloat value = args[0].convertToFloat();
|
196
|
+
RubyFloat start = args[1].convertToFloat();
|
197
|
+
RubyFloat stop = args[2].convertToFloat();
|
198
|
+
if (value.op_ge(context, start).isTrue() && value.op_le(context, stop).isTrue()) {
|
199
|
+
return args[0];
|
200
|
+
} else if (value.op_ge(context, start).isTrue()) {
|
201
|
+
return args[2];
|
202
|
+
} else {
|
203
|
+
return args[1];
|
205
204
|
}
|
205
|
+
}
|
206
206
|
|
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
|
-
|
207
|
+
/**
|
208
|
+
* Provides JRubyArt grid method as a ruby module method behaves like:-
|
209
|
+
* def grid(dx, dy, sx = 1, sy = 1)
|
210
|
+
* (0...dx).step(sx) do |x|
|
211
|
+
* (0...dy).step(sy) do |y|
|
212
|
+
* yield(x, y)
|
213
|
+
* end
|
214
|
+
* end
|
215
|
+
* end
|
216
|
+
* @param context ThreadContext
|
217
|
+
* @param recv IRubyObject
|
218
|
+
* @param args array of args should be Fixnum
|
219
|
+
* @param block { |x, y| `do something` }
|
220
|
+
* @return nil
|
221
|
+
*/
|
222
|
+
@JRubyMethod(name = "grid", rest = true, module = true)
|
223
|
+
public static IRubyObject createGrid(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
|
224
|
+
Ruby ruby = context.runtime;
|
225
|
+
int row = (int) args[0].toJava(Integer.class);
|
226
|
+
int column = (int) args[1].toJava(Integer.class);
|
227
|
+
int rowStep = 1;
|
228
|
+
int colStep = 1;
|
229
|
+
if (args.length == 4){
|
230
|
+
rowStep = (int) args[2].toJava(Integer.class);
|
231
|
+
colStep = (int) args[3].toJava(Integer.class);
|
232
|
+
}
|
233
|
+
if (block.isGiven()) {
|
234
|
+
int tempRow = row / rowStep;
|
235
|
+
int tempColumn = column /colStep;
|
236
|
+
for (int z = 0; z < (tempRow * tempColumn); z++){
|
237
|
+
int y = z % tempColumn;
|
238
|
+
int x = z / tempColumn;
|
239
|
+
block.yieldSpecific(context, ruby.newFixnum(x * rowStep), ruby.newFixnum(y * colStep));
|
240
|
+
}
|
241
|
+
}
|
242
|
+
return context.nil;
|
243
|
+
}
|
244
|
+
/**
|
245
|
+
* Provides JRubyArt mesh_grid method as a ruby module method
|
246
|
+
* def grid(dx, dy, dz, sx = 1, sy = 1, sz = 1)
|
247
|
+
* (0...dx).step(sx) do |x|
|
248
|
+
* (0...dy).step(sy) do |y|
|
249
|
+
* (0...dz).step(sy) do |z|
|
250
|
+
* yield(x, y, z)
|
251
|
+
* end
|
252
|
+
* end
|
253
|
+
* end
|
254
|
+
* end
|
255
|
+
*
|
256
|
+
* @param context ThreadContext
|
257
|
+
* @param recv IRubyObject
|
258
|
+
* @param args array of args should be Fixnum
|
259
|
+
* @param block { |x, y, z| `do something` }
|
260
|
+
* @return nil
|
261
|
+
*/
|
262
|
+
@JRubyMethod(name = "mesh_grid", rest = true, module = true)
|
263
|
+
public static IRubyObject createGrid3D(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
|
264
|
+
Ruby ruby = context.runtime;
|
265
|
+
int xDim = (int) args[0].toJava(Integer.class);
|
266
|
+
int yDim = (int) args[1].toJava(Integer.class);
|
267
|
+
int zDim = (int) args[2].toJava(Integer.class);
|
268
|
+
int xStep = (args.length > 3) ? (int) args[3].toJava(Integer.class) : 1;
|
269
|
+
int yStep = (args.length > 4) ? (int) args[4].toJava(Integer.class) : 1;
|
270
|
+
int zStep = (args.length == 6) ? (int) args[5].toJava(Integer.class) : 1;
|
271
|
+
int dimX = xDim / xStep;
|
272
|
+
int dimY = yDim / yStep;
|
273
|
+
int dimZ = zDim / zStep;
|
274
|
+
if (block.isGiven()) {
|
275
|
+
int count = dimX * dimY * dimZ;
|
276
|
+
for (int x = 0; x < xDim; x += xStep){
|
277
|
+
for (int j = 0; j < (dimZ * dimY); j++){
|
278
|
+
int z = j % dimZ;
|
279
|
+
int y = j / dimZ;
|
280
|
+
block.yieldSpecific(context, ruby.newFixnum(x), ruby.newFixnum(y * yStep), ruby.newFixnum(z * zStep));
|
233
281
|
}
|
234
|
-
|
235
|
-
|
282
|
+
}
|
236
283
|
}
|
284
|
+
return context.nil;
|
285
|
+
}
|
237
286
|
}
|