picrate 0.9.0-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/README.md +2 -2
- data/Rakefile +9 -9
- data/docs/_config.yml +1 -1
- data/docs/_posts/2018-06-26-auto_install_picrate.md +4 -4
- data/docs/index.html +0 -4
- data/lib/picrate.rb +1 -0
- data/lib/picrate/app.rb +0 -1
- data/lib/picrate/runner.rb +15 -8
- data/lib/picrate/version.rb +2 -1
- data/library/color_group/color_group.rb +1 -1
- data/library/video_event/video_event.rb +2 -1
- data/pom.rb +3 -3
- data/pom.xml +3 -3
- data/src/main/java/monkstone/MathToolModule.java +253 -203
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
- data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +14 -24
- data/src/main/java/processing/net/Client.java +673 -685
- data/src/main/java/processing/net/Server.java +329 -326
- data/test/color_group_test.rb +1 -2
- data/test/deglut_spec_test.rb +0 -2
- data/test/helper_methods_test.rb +1 -2
- data/test/math_tool_test.rb +0 -2
- data/test/respond_to_test.rb +1 -2
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +0 -2
- data/vendors/Rakefile +4 -5
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99548788c7788ff8a0550737e02a19010d26d570109b8fbaf043eb8add67e9a3
|
4
|
+
data.tar.gz: 1a96e8972d111cca1ed267c0f95759365356c882884589d7c334bdc0db004a95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 666d79345ce22d918b93c63fdbc7bb0d798cdd53066fc1e463a99b89c234516f372a435892699fa1ecae5d79b886348428cc6bbc7f9767d393988da0ac33717c
|
7
|
+
data.tar.gz: 0bd3cde4c9bea8bb121a72fe2b0364a9651e1be2d4a5a69f421803a1720fc5c79d5b131ed323d6eac2d59a86eb45eb4d7a37d570f95393eafd849efb68a4c59d
|
data/.mvn/extensions.xml
CHANGED
data/README.md
CHANGED
@@ -13,12 +13,12 @@ jgem install picrate
|
|
13
13
|
|
14
14
|
Clone this repo:-
|
15
15
|
|
16
|
-
Requires maven, openjdk11 (to build, uses `release` flag), and a jdk8 and jruby to install.
|
16
|
+
Requires maven, openjdk11+ (to build, uses `release` flag), and a jdk8 and jruby to install.
|
17
17
|
|
18
18
|
```bash
|
19
19
|
cd PiCrate
|
20
20
|
rake # assumes an installed version of vanilla processing
|
21
|
-
jgem install picrate-0.
|
21
|
+
jgem install picrate-0.9.0-java.gem
|
22
22
|
```
|
23
23
|
To create a template sketch:-
|
24
24
|
```bash
|
data/Rakefile
CHANGED
@@ -8,9 +8,9 @@ task default: %i[init compile install test gem]
|
|
8
8
|
desc 'Copy Jars'
|
9
9
|
task :init do
|
10
10
|
# for Archlinux etc
|
11
|
-
processing_root = File.dirname(`readlink -f $(which processing)`)
|
11
|
+
# processing_root = File.dirname(`readlink -f $(which processing)`)
|
12
12
|
# alternative for debian linux etc
|
13
|
-
|
13
|
+
processing_root = File.join(HOME_DIR, 'processing-3.5.3')
|
14
14
|
jar_dir = File.join(processing_root, 'core', 'library')
|
15
15
|
opengl = Dir.entries(jar_dir).grep(/amd64|armv6hf/).select { |jar| jar =~ /linux/ }
|
16
16
|
opengl.concat %w[jogl-all.jar gluegen-rt.jar]
|
@@ -31,21 +31,21 @@ end
|
|
31
31
|
|
32
32
|
desc 'Document'
|
33
33
|
task :javadoc do
|
34
|
-
system '
|
34
|
+
system './mvnw javadoc:javadoc'
|
35
35
|
end
|
36
36
|
|
37
37
|
desc 'Compile'
|
38
38
|
task :compile do
|
39
|
-
system '
|
39
|
+
system './mvnw package'
|
40
40
|
end
|
41
41
|
|
42
42
|
desc 'Test'
|
43
43
|
task :test do
|
44
|
-
system 'jruby test/helper_methods_test.rb'
|
45
|
-
system 'jruby test/respond_to_test.rb' # Skip this test on Travis etc
|
46
|
-
system 'jruby test/math_tool_test.rb'
|
47
|
-
system 'jruby test/deglut_spec_test.rb'
|
48
|
-
system 'jruby test/vecmath_spec_test.rb'
|
44
|
+
system 'jruby --dev test/helper_methods_test.rb'
|
45
|
+
system 'jruby --dev test/respond_to_test.rb' # Skip this test on Travis etc
|
46
|
+
system 'jruby --dev test/math_tool_test.rb'
|
47
|
+
system 'jruby --dev test/deglut_spec_test.rb'
|
48
|
+
system 'jruby --dev test/vecmath_spec_test.rb'
|
49
49
|
end
|
50
50
|
|
51
51
|
desc 'clean'
|
data/docs/_config.yml
CHANGED
@@ -6,15 +6,15 @@ categories: PiCrate update
|
|
6
6
|
permalink: /install_picrate/
|
7
7
|
---
|
8
8
|
|
9
|
-
For a semi-automated setup and install, download and extract [this gist](https://gist.github.com/monkstone/
|
9
|
+
For a semi-automated setup and install, download and extract [this gist](https://gist.github.com/monkstone/e9df8ea776aed58ce1c4de8e12982aad). To keep your system clean put the file in a folder say
|
10
10
|
`~/install_picrate`
|
11
11
|
|
12
12
|
```bash
|
13
|
-
cd ~/
|
14
|
-
|
13
|
+
cd ~/picrate_install
|
14
|
+
bash picrate_install.sh # to run default task
|
15
15
|
```
|
16
16
|
#### What the script does ###
|
17
|
-
1. Downloads JRuby
|
17
|
+
1. Downloads JRuby
|
18
18
|
2. Installs JRuby to `/opt`
|
19
19
|
3. Uses `update-alternatives` to configure `jruby`, `jgem` and `jirb`
|
20
20
|
4. The script checks for `GEM_HOME`, if undefined it modifies `~/.profile` to define `GEM_HOME` and puts gem binaries on your path, at logon.
|
data/docs/index.html
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
---
|
2
2
|
layout: default
|
3
3
|
---
|
4
|
-
<head>
|
5
|
-
<link rel="icon" href="{{"assets/favicon.ico" | prepend: site.baseurl | prepend: site.url }}" type="image/x-icon" />
|
6
|
-
</head>
|
7
|
-
|
8
4
|
<section role="banner">
|
9
5
|
<object type="image/svg+xml" width="200" data="assets/picrate.svg">
|
10
6
|
Your browser does not support SVG
|
data/lib/picrate.rb
CHANGED
data/lib/picrate/app.rb
CHANGED
data/lib/picrate/runner.rb
CHANGED
@@ -15,12 +15,12 @@ module Processing
|
|
15
15
|
def self.execute
|
16
16
|
runner = new
|
17
17
|
runner.parse_options(ARGV)
|
18
|
-
runner.execute
|
18
|
+
runner.execute
|
19
19
|
end
|
20
20
|
|
21
21
|
# Dispatch central.
|
22
|
-
def execute
|
23
|
-
|
22
|
+
def execute
|
23
|
+
parse_options('-h') if options.empty?
|
24
24
|
show_version if options[:version]
|
25
25
|
create if options[:create]
|
26
26
|
install(filename) if options[:install]
|
@@ -52,7 +52,7 @@ module Processing
|
|
52
52
|
|
53
53
|
# This displays the help screen, all programs are
|
54
54
|
# assumed to have this option.
|
55
|
-
opts.
|
55
|
+
opts.on_tail('-h', '--help', 'Display this screen') do
|
56
56
|
puts opts
|
57
57
|
exit
|
58
58
|
end
|
@@ -76,11 +76,18 @@ module Processing
|
|
76
76
|
puts template.result(binding)
|
77
77
|
end
|
78
78
|
|
79
|
-
def install(library)
|
79
|
+
def install(library = nil)
|
80
|
+
library ||= 'new'
|
80
81
|
choice = library.downcase
|
81
|
-
|
82
|
-
|
83
|
-
|
82
|
+
case choice
|
83
|
+
when /samples|sound|video/
|
84
|
+
system "cd #{PICRATE_ROOT}/vendors && rake download_and_copy_#{choice}"
|
85
|
+
when /new/
|
86
|
+
# install samples and config geany
|
87
|
+
system "cd #{PICRATE_ROOT}/vendors && rake"
|
88
|
+
else
|
89
|
+
warn format('No installer for %s', library)
|
90
|
+
end
|
84
91
|
end
|
85
92
|
end # class Runner
|
86
93
|
end # module Processing
|
data/lib/picrate/version.rb
CHANGED
data/pom.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
project 'picrate', 'http://maven.apache.org' do
|
2
2
|
|
3
3
|
model_version '4.0.0'
|
4
|
-
id 'ruby-processing:picrate:0.
|
4
|
+
id 'ruby-processing:picrate:1.0.0'
|
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.'
|
@@ -31,7 +31,7 @@ project 'picrate', 'http://maven.apache.org' do
|
|
31
31
|
'polyglot.dump.pom' => 'pom.xml'
|
32
32
|
)
|
33
33
|
|
34
|
-
pom 'org.jruby:jruby:9.2.
|
34
|
+
pom 'org.jruby:jruby:9.2.8.0'
|
35
35
|
jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
|
36
36
|
jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
|
37
37
|
jar 'org.processing:video:3.0.2'
|
@@ -40,7 +40,7 @@ end
|
|
40
40
|
overrides do
|
41
41
|
plugin :resources, '2.7'
|
42
42
|
plugin :dependency, '2.8'
|
43
|
-
plugin( :compiler, '3.8.
|
43
|
+
plugin( :compiler, '3.8.1', 'release' => '8' )
|
44
44
|
plugin(
|
45
45
|
:javadoc,
|
46
46
|
'2.10.4',
|
data/pom.xml
CHANGED
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
|
|
11
11
|
<modelVersion>4.0.0</modelVersion>
|
12
12
|
<groupId>ruby-processing</groupId>
|
13
13
|
<artifactId>picrate</artifactId>
|
14
|
-
<version>0.
|
14
|
+
<version>1.0.0</version>
|
15
15
|
<name>picrate</name>
|
16
16
|
<description>An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.</description>
|
17
17
|
<url>http://maven.apache.org</url>
|
@@ -76,7 +76,7 @@ DO NOT MODIFIY - GENERATED CODE
|
|
76
76
|
<dependency>
|
77
77
|
<groupId>org.jruby</groupId>
|
78
78
|
<artifactId>jruby</artifactId>
|
79
|
-
<version>9.2.
|
79
|
+
<version>9.2.8.0</version>
|
80
80
|
<type>pom</type>
|
81
81
|
</dependency>
|
82
82
|
<dependency>
|
@@ -127,7 +127,7 @@ DO NOT MODIFIY - GENERATED CODE
|
|
127
127
|
</plugin>
|
128
128
|
<plugin>
|
129
129
|
<artifactId>maven-compiler-plugin</artifactId>
|
130
|
-
<version>3.8.
|
130
|
+
<version>3.8.1</version>
|
131
131
|
<configuration>
|
132
132
|
<release>8</release>
|
133
133
|
</configuration>
|
@@ -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-19 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
|
-
|
28
|
-
*/
|
26
|
+
*
|
27
|
+
* @author Martin Prout
|
28
|
+
*/
|
29
29
|
@JRubyModule(name = "MathTool")
|
30
30
|
public class MathToolModule {
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
/**
|
33
|
+
*
|
34
|
+
* @param runtime Ruby
|
35
|
+
*/
|
36
|
+
public static void createMathToolModule(Ruby runtime) {
|
37
|
+
RubyModule mtModule = runtime.defineModule("MathTool");
|
38
|
+
mtModule.defineAnnotatedMethods(MathToolModule.class);
|
39
|
+
}
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
41
|
+
/**
|
42
|
+
*
|
43
|
+
* @param context ThreadContext
|
44
|
+
* @param recv IRubyObject
|
45
|
+
* @param args array of RubyRange (must be be numeric)
|
46
|
+
* @return mapped value RubyFloat
|
47
|
+
*/
|
48
|
+
@JRubyMethod(name = "map1d", rest = true, module = true)
|
49
|
+
public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
50
|
+
double value = (args[0] instanceof RubyFloat)
|
51
|
+
? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
52
|
+
RubyRange r1 = (RubyRange) args[1];
|
53
|
+
RubyRange r2 = (RubyRange) args[2];
|
54
|
+
double first1 = (r1.first(context) instanceof RubyFloat)
|
55
|
+
? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
|
56
|
+
double first2 = (r2.first(context) instanceof RubyFloat)
|
57
|
+
? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
|
58
|
+
double last1 = (r1.last(context) instanceof RubyFloat)
|
59
|
+
? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
|
60
|
+
double last2 = (r2.last(context) instanceof RubyFloat)
|
61
|
+
? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
|
62
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
63
|
+
}
|
64
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
|
-
}
|
90
|
-
if (value > max) {
|
91
|
-
return mapMt(context, max, first1, last1, first2, last2);
|
92
|
-
}
|
93
|
-
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);
|
94
89
|
}
|
95
|
-
|
96
|
-
|
97
|
-
*
|
98
|
-
* @param context ThreadContext
|
99
|
-
* @param recv self IRubyObject
|
100
|
-
* @param args floats as in processing map function
|
101
|
-
* @return mapped value RubyFloat
|
102
|
-
*/
|
103
|
-
@JRubyMethod(name = "p5map", rest = true, module = true)
|
104
|
-
public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
105
|
-
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
106
|
-
double first1 = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
107
|
-
double first2 = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
|
108
|
-
double last1 = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
109
|
-
double last2 = (args[4] instanceof RubyFloat) ? ((RubyFloat) args[4]).getValue() : ((RubyFixnum) args[4]).getDoubleValue();
|
110
|
-
return mapMt(context, value, first1, last1, first2, last2);
|
90
|
+
if (value > max) {
|
91
|
+
return mapMt(context, max, first1, last1, first2, last2);
|
111
92
|
}
|
93
|
+
return mapMt(context, value, first1, last1, first2, last2);
|
94
|
+
}
|
112
95
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
}
|
130
|
-
if (amount >= 1.0) {
|
131
|
-
return args[1];
|
132
|
-
}
|
133
|
-
return context.runtime.newFloat((1 - amount) * start + (stop * amount));
|
134
|
-
}
|
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
|
+
}
|
135
112
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
113
|
+
/**
|
114
|
+
* A more correct version than processing.org version
|
115
|
+
*
|
116
|
+
* @param context ThreadContext
|
117
|
+
* @param recv self IRubyObject
|
118
|
+
* @param args args[2] should be between 0 and 1.0 if not returns start or
|
119
|
+
* stop
|
120
|
+
* @return lerped value RubyFloat
|
121
|
+
*/
|
122
|
+
@JRubyMethod(name = "lerp", rest = true, module = true)
|
123
|
+
public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
124
|
+
double start = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
125
|
+
double stop = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
126
|
+
double amount = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
127
|
+
if (amount <= 0) {
|
128
|
+
return args[0];
|
129
|
+
}
|
130
|
+
if (amount >= 1.0) {
|
131
|
+
return args[1];
|
152
132
|
}
|
133
|
+
return context.runtime.newFloat((1 - amount) * start + (stop * amount));
|
134
|
+
}
|
153
135
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
136
|
+
/**
|
137
|
+
* Identical to p5map(value, low, high, 0, 1). Numbers outside of the range
|
138
|
+
* are not clamped to 0 and 1, because out-of-range values are often
|
139
|
+
* intentional and useful.
|
140
|
+
*
|
141
|
+
* @param context ThreadContext
|
142
|
+
* @param recv IRubyObject
|
143
|
+
* @param args array of args must be be numeric
|
144
|
+
* @return mapped value RubyFloat
|
145
|
+
*/
|
146
|
+
@JRubyMethod(name = "norm", rest = true, module = true)
|
147
|
+
public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
148
|
+
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
149
|
+
double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
150
|
+
double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
151
|
+
return mapMt(context, value, start, stop, 0, 1.0);
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Identical to p5map(value, low, high, 0, 1) but 'clamped'. Numbers outside
|
156
|
+
* of the range are clamped to 0 and 1,
|
157
|
+
*
|
158
|
+
* @param context ThreadContext
|
159
|
+
* @param recv IRubyObject
|
160
|
+
* @param args array of args must be be numeric
|
161
|
+
* @return mapped value RubyFloat
|
162
|
+
*/
|
163
|
+
@JRubyMethod(name = "norm_strict", rest = true, module = true)
|
164
|
+
public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
165
|
+
|
166
|
+
double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
167
|
+
double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
168
|
+
double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
169
|
+
double max = Math.max(start, stop);
|
170
|
+
double min = Math.min(start, stop);
|
171
|
+
if (value < min) {
|
172
|
+
return mapMt(context, min, start, stop, 0, 1.0);
|
178
173
|
}
|
179
|
-
|
180
|
-
|
181
|
-
double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
|
182
|
-
return context.runtime.newFloat(result);
|
174
|
+
if (value > max) {
|
175
|
+
return mapMt(context, max, start, stop, 0, 1.0);
|
183
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
|
}
|