picrate 0.9.0-java → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 680ef5f5fe41c9808066576455031746276898a79aadf199a46a24d6daf813c6
4
- data.tar.gz: fa9ece7f5dc8d370e401f2cd8dcf76556ffbc465d3b08fbec67a4634a3a35d49
3
+ metadata.gz: 99548788c7788ff8a0550737e02a19010d26d570109b8fbaf043eb8add67e9a3
4
+ data.tar.gz: 1a96e8972d111cca1ed267c0f95759365356c882884589d7c334bdc0db004a95
5
5
  SHA512:
6
- metadata.gz: e6fb430247715c5011aca32954b3d8dee2b7163de49f599ddf607328f1a5b289ab5a4437aed3ac847cf0e5c3332a528fb15f1060319e6fdd4f49fd4fc67c869d
7
- data.tar.gz: 1179878370c0d2a6537814304ed237bd54ff35aec3c5d9d0b201cee3b332229e81760a14f32c3673d6a8ee0ec7dff2bae419ea50acb6d1d4de515aa1d4ed91f4
6
+ metadata.gz: 666d79345ce22d918b93c63fdbc7bb0d798cdd53066fc1e463a99b89c234516f372a435892699fa1ecae5d79b886348428cc6bbc7f9767d393988da0ac33717c
7
+ data.tar.gz: 0bd3cde4c9bea8bb121a72fe2b0364a9651e1be2d4a5a69f421803a1720fc5c79d5b131ed323d6eac2d59a86eb45eb4d7a37d570f95393eafd849efb68a4c59d
@@ -3,7 +3,7 @@
3
3
  <extension>
4
4
  <groupId>io.takari.polyglot</groupId>
5
5
  <artifactId>polyglot-ruby</artifactId>
6
- <version>0.4.0
6
+ <version>0.4.3
7
7
  </version>
8
8
  </extension>
9
9
  </extensions>
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.8.0-java.gem
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
- # processing_root = File.join(HOME_DIR, 'processing-3.5.3')
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 'mvn javadoc:javadoc'
34
+ system './mvnw javadoc:javadoc'
35
35
  end
36
36
 
37
37
  desc 'Compile'
38
38
  task :compile do
39
- system 'mvn package'
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'
@@ -17,7 +17,7 @@ twitter_username: monkstoneT
17
17
  github_username: monkstone
18
18
  # Build settings
19
19
  markdown: kramdown
20
- gems:
20
+ plugins:
21
21
  - jekyll-sitemap
22
22
  - jekyll-feed
23
23
  - jekyll-seo-tag
@@ -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/c7d7741f800eb2327253635ee283c7eb). To keep your system clean put the file in a folder say
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 ~/install_picrate
14
- rake # to run default task
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 (checks against sha256)
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.
@@ -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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'java'
3
4
  unless defined? PICRATE_ROOT
4
5
  $LOAD_PATH << File.dirname(__dir__)
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: false
2
2
  require_relative 'helper_methods'
3
3
  require_relative 'library_loader'
4
- require 'jruby'
5
4
  # A wrapper module for the processing App
6
5
  module Processing
7
6
  include_package 'processing.core' # imports the processing jar.
@@ -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
- show_help if options.empty?
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.on('-h', '--help', 'Display this screen') do
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
- valid = Regexp.union('samples', 'sound', 'video', 'glvideo')
82
- return warn format('No installer for %s', choice) unless valid =~ choice
83
- system "cd #{PICRATE_ROOT}/vendors && rake download_and_copy_#{choice}"
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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module PiCrate
3
- VERSION = '0.9.0'
4
+ VERSION = '1.0.0'
4
5
  end
@@ -17,7 +17,7 @@ class ColorGroup
17
17
  @colors = ColorUtil.shuffle(colors)
18
18
  end
19
19
 
20
- def ruby_code
20
+ def ruby_string
21
21
  ColorUtil.rubyString(colors)
22
22
  end
23
23
 
@@ -1,3 +1,4 @@
1
1
  class Processing::App
2
- include Java::MonkstoneVideoevent::VideoInterface
2
+ include Java::MonkstoneVideoevent::MovieEvent
3
+ include Java::MonkstoneVideoevent::CaptureEvent
3
4
  end
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.9.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.7.0'
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.0', 'release' => '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.9.0</version>
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.7.0</version>
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.0</version>
130
+ <version>3.8.1</version>
131
131
  <configuration>
132
132
  <release>8</release>
133
133
  </configuration>
@@ -1,13 +1,14 @@
1
1
  /**
2
- * The purpose of this tool is to allow picrate users to use an alternative
3
- * to processing.org map, lerp and norm methods in their sketches
4
- * Copyright (c) 2018-19 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
- */
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
- * @author Martin Prout
28
- */
26
+ *
27
+ * @author Martin Prout
28
+ */
29
29
  @JRubyModule(name = "MathTool")
30
30
  public class MathToolModule {
31
31
 
32
- /**
33
- *
34
- * @param runtime Ruby
35
- */
36
- public static void createMathToolModule(Ruby runtime) {
37
- RubyModule mtModule = runtime.defineModule("MathTool");
38
- mtModule.defineAnnotatedMethods(MathToolModule.class);
39
- }
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
- * @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
- }
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
- * @param context ThreadContext
68
- * @param recv IRubyObject
69
- * @param args array of RubyRange (must be be numeric)
70
- * @return mapped value RubyFloat
71
- */
72
- @JRubyMethod(name = "constrained_map", rest = true, module = true)
73
- public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
74
- double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
75
- RubyRange r1 = (RubyRange) args[1];
76
- RubyRange r2 = (RubyRange) args[2];
77
- double first1 = (r1.first(context) instanceof RubyFloat)
78
- ? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
79
- double first2 = (r2.first(context) instanceof RubyFloat)
80
- ? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
81
- double last1 = (r1.last(context) instanceof RubyFloat)
82
- ? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
83
- double last2 = (r2.last(context) instanceof RubyFloat)
84
- ? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
85
- double max = Math.max(first1, last1);
86
- double min = Math.min(first1, last1);
87
- if (value < min) {
88
- return mapMt(context, min, first1, last1, first2, last2);
89
- }
90
- if (value > max) {
91
- return mapMt(context, max, first1, last1, first2, last2);
92
- }
93
- return mapMt(context, value, first1, last1, first2, last2);
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
- * A more correct version than processing.org version
115
- *
116
- * @param context ThreadContext
117
- * @param recv self IRubyObject
118
- * @param args args[2] should be between 0 and 1.0 if not returns start or
119
- * stop
120
- * @return lerped value RubyFloat
121
- */
122
- @JRubyMethod(name = "lerp", rest = true, module = true)
123
- public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
124
- double start = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
125
- double stop = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
126
- double amount = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
127
- if (amount <= 0) {
128
- return args[0];
129
- }
130
- if (amount >= 1.0) {
131
- return args[1];
132
- }
133
- return context.runtime.newFloat((1 - amount) * start + (stop * amount));
134
- }
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
- * 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);
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
- * 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
- Ruby ruby = context.runtime;
166
- double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
167
- double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
168
- double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
169
- double max = Math.max(start, stop);
170
- double min = Math.min(start, stop);
171
- if (value < min) {
172
- return mapMt(context, min, start, stop, 0, 1.0);
173
- }
174
- if (value > max) {
175
- return mapMt(context, max, start, stop, 0, 1.0);
176
- }
177
- return mapMt(context, value, start, stop, 0, 1.0);
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
- // 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
- 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
- * 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];
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
- * Provides picrate grid method as a ruby module method
209
- *
210
- * @param context ThreadContext
211
- * @param recv IRubyObject
212
- * @param args array of args should be Fixnum
213
- * @param block { |x, y| `do something` }
214
- * @return nil
215
- */
216
- @JRubyMethod(name = "grid", rest = true, module = true)
217
- public static IRubyObject createGrid(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
218
- int row = (int) args[0].toJava(Integer.class);
219
- int column = (int) args[1].toJava(Integer.class);
220
- int rowStep = 1;
221
- int colStep = 1;
222
- if (args.length == 4){
223
- rowStep = (int) args[2].toJava(Integer.class);
224
- colStep = (int) args[3].toJava(Integer.class);
225
- }
226
- if (block.isGiven()) {
227
- int tempRow = row / rowStep;
228
- for (int z = 0; z < (tempRow * (column / colStep)); z++){
229
- int x = z % tempRow;
230
- int y = z / tempRow;
231
- block.yieldSpecific(context, context.runtime.newFixnum(x * rowStep), context.runtime.newFixnum(y * colStep));
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
- return context.nil;
235
-
283
+ }
236
284
  }
285
+ return context.nil;
286
+ }
237
287
  }