picrate 2.1.0-java → 2.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/CHANGELOG.md +10 -0
  6. data/README.md +6 -3
  7. data/Rakefile +2 -1
  8. data/docs/_includes/footer.html +1 -1
  9. data/docs/_layouts/post.html +1 -1
  10. data/docs/_methods/alternative_methods.md +2 -1
  11. data/docs/_methods/noise_mode.md +88 -0
  12. data/docs/_posts/2018-05-06-install_jruby.md +3 -3
  13. data/docs/_posts/2018-11-18-building-gem.md +3 -1
  14. data/docs/_posts/2020-03-09-auto_install_picrate.md +2 -3
  15. data/docs/_posts/2020-05-11-getting_started_manjaro.md +19 -7
  16. data/docs/classes.md +2 -2
  17. data/docs/editors.md +2 -2
  18. data/docs/gems.md +3 -3
  19. data/docs/index.html +1 -1
  20. data/docs/libraries.md +2 -2
  21. data/docs/live.md +2 -2
  22. data/docs/magic.md +2 -2
  23. data/docs/methods.md +2 -2
  24. data/docs/modules.md +3 -3
  25. data/docs/objects.md +2 -2
  26. data/lib/picrate.rb +2 -1
  27. data/lib/picrate/app.rb +3 -2
  28. data/lib/picrate/helper_methods.rb +1 -1
  29. data/lib/picrate/native_folder.rb +1 -3
  30. data/lib/picrate/runner.rb +4 -4
  31. data/lib/picrate/version.rb +1 -1
  32. data/library/jcomplex/jcomplex.rb +1 -0
  33. data/library/pdf/pdf.rb +7 -0
  34. data/library/svg/svg.rb +7 -0
  35. data/mvnw +2 -2
  36. data/mvnw.cmd +2 -2
  37. data/picrate.gemspec +5 -3
  38. data/pom.rb +31 -9
  39. data/pom.xml +41 -6
  40. data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
  41. data/src/main/java/monkstone/PicrateLibrary.java +3 -1
  42. data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
  43. data/src/main/java/monkstone/complex/JComplex.java +252 -0
  44. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  45. data/src/main/java/monkstone/fastmath/Deglut.java +41 -93
  46. data/src/main/java/monkstone/noise/OpenSimplex2F.java +813 -0
  47. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
  48. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  49. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  50. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  51. data/src/main/java/processing/awt/ShimAWT.java +260 -94
  52. data/src/main/java/processing/core/PApplet.java +14664 -13450
  53. data/src/main/java/processing/core/PConstants.java +5 -5
  54. data/src/main/java/processing/core/PFont.java +1 -1
  55. data/src/main/java/processing/core/PGraphics.java +200 -201
  56. data/src/main/java/processing/core/PImage.java +539 -549
  57. data/src/main/java/processing/core/PShape.java +18 -18
  58. data/src/main/java/processing/core/PVector.java +23 -23
  59. data/src/main/java/processing/data/Table.java +4 -4
  60. data/src/main/java/processing/net/Client.java +13 -13
  61. data/src/main/java/processing/net/Server.java +5 -5
  62. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +4 -4
  63. data/src/main/java/processing/pdf/PGraphicsPDF.java +529 -0
  64. data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
  65. data/test/deglut_spec_test.rb +2 -2
  66. data/test/respond_to_test.rb +0 -2
  67. data/vendors/Rakefile +31 -22
  68. data/vendors/geany.rb +3 -3
  69. metadata +26 -13
  70. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -465
data/lib/picrate.rb CHANGED
@@ -9,4 +9,5 @@ end
9
9
  Dir["#{PICRATE_ROOT}/lib/*.jar"].sort.each do |jar|
10
10
  require jar
11
11
  end
12
- require_relative 'picrate/app'
12
+ require "#{PICRATE_ROOT}/lib/picrate/app"
13
+ require "#{PICRATE_ROOT}/lib/picrate/helpers/numeric"
data/lib/picrate/app.rb CHANGED
@@ -5,7 +5,7 @@ require_relative 'helper_methods'
5
5
  require_relative 'library_loader'
6
6
  # A wrapper module for the processing App
7
7
  module Processing
8
- include_package 'processing.core' # imports the processing jar.
8
+ include_package 'processing.core' # imports the processing classes.
9
9
  # Load vecmath, fastmath and mathtool modules
10
10
  Java::Monkstone::PicrateLibrary.load(JRuby.runtime)
11
11
  SKETCH_ROOT = File.absolute_path('.')
@@ -55,6 +55,7 @@ module Processing
55
55
  include HelperMethods
56
56
  include MathTool
57
57
  include Math
58
+ include FastNoise
58
59
  # Alias some methods for familiarity for Shoes coders.
59
60
  alias oval ellipse
60
61
  alias stroke_width stroke_weight
@@ -144,7 +145,7 @@ module Processing
144
145
  def data_path(dat)
145
146
  dat_root = File.join(SKETCH_ROOT, 'data')
146
147
  Dir.mkdir(dat_root) unless File.exist?(dat_root)
147
- File.join(dat_root, dat)
148
+ File.join(dat_root, dat).to_java(:string)
148
149
  end
149
150
 
150
151
  private
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  # processing module wrapper
4
- require_relative 'helpers/numeric'
4
+
5
5
  module Processing
6
6
  # Provides some convenience methods
7
7
  module HelperMethods
@@ -1,5 +1,3 @@
1
- require 'rbconfig'
2
-
3
1
  # Utility to load native binaries on Java CLASSPATH
4
2
  #HACK until jruby returns a more specific 'host_os' than 'linux'
5
3
  class NativeFolder
@@ -10,7 +8,7 @@ class NativeFolder
10
8
  ARM64 = '-aarch64'.freeze
11
9
 
12
10
  def initialize
13
- @os = RbConfig::CONFIG['host_os'].downcase
11
+ @os = java.lang.System.get_property('os.name')
14
12
  @bit = java.lang.System.get_property('os.arch')
15
13
  end
16
14
 
@@ -32,7 +32,7 @@ module Processing
32
32
  opt_parser = OptionParser.new do |opts|
33
33
  # Set a banner, displayed at the top
34
34
  # of the help screen.
35
- opts.banner = 'Usage: picrate [options] [<sketch.rb>]'
35
+ opts.banner = 'Usage: picrate [options] [<name>]'
36
36
 
37
37
  # Define the options, and what they do
38
38
  options[:version] = false
@@ -55,6 +55,8 @@ module Processing
55
55
  # assumed to have this option.
56
56
  opts.on_tail('-h', '--help', 'Display this screen') do
57
57
  puts opts
58
+ puts ''
59
+ puts 'Run a sketch: jruby [--dev] [<sketch.rb>]'
58
60
  exit
59
61
  end
60
62
  end
@@ -81,9 +83,7 @@ module Processing
81
83
  library ||= 'new'
82
84
  choice = library.downcase
83
85
  case choice
84
- when /sound/
85
- warn 'The sound library is broken, try minim instead'
86
- when /samples|video/
86
+ when /samples|sound|video/
87
87
  system "cd #{PICRATE_ROOT}/vendors && rake install_#{choice}"
88
88
  when /new/
89
89
  # install samples and config geany
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PiCrate
4
- VERSION = '2.1.0'
4
+ VERSION = '2.4.0'
5
5
  end
@@ -0,0 +1 @@
1
+ java_import Java::MonkstoneComplex::JComplex
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @TODO usage
4
+ class Processing::App
5
+ require_relative 'itextpdf-5.5.13.2.jar'
6
+ java_import Java::ProcessingPdf::PGraphicsPDF
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @TODO usage
4
+ class Processing::App
5
+ require_relative 'batik-all-1.14.jar'
6
+ java_import Java::ProcessingSvg::PGraphicsSVG
7
+ end
data/mvnw CHANGED
@@ -212,9 +212,9 @@ else
212
212
  echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
213
213
  fi
214
214
  if [ -n "$MVNW_REPOURL" ]; then
215
- jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
215
+ jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
216
216
  else
217
- jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
217
+ jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
218
218
  fi
219
219
  while IFS="=" read key value; do
220
220
  case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
data/mvnw.cmd CHANGED
@@ -120,7 +120,7 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120
120
  set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121
121
  set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122
122
 
123
- set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
123
+ set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
124
124
 
125
125
  FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126
126
  IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
@@ -134,7 +134,7 @@ if exist %WRAPPER_JAR% (
134
134
  )
135
135
  ) else (
136
136
  if not "%MVNW_REPOURL%" == "" (
137
- SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
137
+ SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
138
138
  )
139
139
  if "%MVNW_VERBOSE%" == "true" (
140
140
  echo Couldn't find %WRAPPER_JAR%, downloading it ...
data/picrate.gemspec CHANGED
@@ -27,12 +27,14 @@ Gem::Specification.new do |gem|
27
27
  gem.files << 'lib/jogl-all-natives-linux-amd64.jar'
28
28
  gem.files << 'lib/jogl-all-natives-linux-armv6hf.jar'
29
29
  gem.files << 'lib/jogl-all-natives-linux-aarch64.jar'
30
+ gem.files << 'library/pdf/itextpdf-5.5.13.2.jar'
31
+ gem.files << 'library/svg/batik-all-1.14.jar'
30
32
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
31
33
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
32
- gem.add_development_dependency 'minitest', '~> 5.10'
33
- gem.add_development_dependency 'rake', '~> 12.3'
34
+ gem.add_development_dependency 'minitest', '~> 5.14'
35
+ gem.add_runtime_dependency 'rake', '~> 13.0'
34
36
  gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.1'
35
37
  gem.require_paths = ['lib']
36
38
  gem.platform = 'java'
37
- gem.requirements << 'java runtime == 11'
39
+ gem.requirements << 'java runtime == 11+'
38
40
  end
data/pom.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  project 'picrate', 'http://maven.apache.org' do
4
4
  model_version '4.0.0'
5
- id 'ruby-processing:picrate:2.1.0'
5
+ id 'ruby-processing:picrate:2.4.0'
6
6
  packaging 'jar'
7
7
 
8
8
  description 'An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.'
@@ -24,22 +24,43 @@ project 'picrate', 'http://maven.apache.org' do
24
24
  issue_management 'https://github.com/ruby-processing/PiCrate/issues', 'Github'
25
25
  # Need to update to jogl 2.4.1 as soon as available, then make a dependency
26
26
  properties('jogl.version' => '2.3.2',
27
+ 'batik.version' => '1.14',
28
+ 'itextpdf.version' => '5.5.13.2',
27
29
  'jruby.api' => 'http://jruby.org/apidocs/',
28
30
  'source.directory' => 'src',
29
31
  'processing.api' => 'http://processing.github.io/processing-javadocs/core/',
30
32
  'picrate.basedir' => '${project.basedir}',
31
- 'project.build.sourceEncoding' => 'utf-8',
33
+ 'project.build.sourceEncoding' => 'UTF-8',
32
34
  'polyglot.dump.pom' => 'pom.xml')
33
35
 
34
- pom 'org.jruby:jruby:9.2.12.0'
36
+ pom 'org.jruby:jruby:9.2.16.0'
35
37
  jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
36
38
  jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
37
39
  jar 'org.processing:video:3.0.2'
40
+ jar 'org.apache.xmlgraphics:batik-all:${batik.version}'
41
+ jar 'com.itextpdf:itextpdf:${itextpdf.version}'
38
42
  end
39
43
 
40
44
  overrides do
41
45
  plugin :resources, '3.1.0'
42
- plugin :dependency, '3.1.2'
46
+ plugin :dependency, '3.1.2' do
47
+ execute_goals( id: 'default-cli',
48
+ artifactItems:[
49
+ { groupId: 'com.itextpdf',
50
+ artifactId: 'itextpdf',
51
+ version: '${itextpdf.version}',
52
+ type: 'jar',
53
+ outputDirectory: '${picrate.basedir}/library/pdf'
54
+ },
55
+ { groupId: 'org.apache.xmlgraphics',
56
+ artifactId: 'batik-all',
57
+ version: '${batik.version}',
58
+ type: 'jar',
59
+ outputDirectory: '${picrate.basedir}/library/svg'
60
+ }
61
+ ]
62
+ )
63
+ end
43
64
  plugin(:compiler, '3.8.1',
44
65
  'release' => '11')
45
66
  plugin(:javadoc, '2.10.4',
@@ -47,11 +68,12 @@ overrides do
47
68
  'links' => ['${processing.api}',
48
69
  '${jruby.api}'])
49
70
  plugin(:jar, '3.2.0',
50
- 'archive' => {
51
- 'manifestEntries' => {
52
- 'Class-Path' => 'gluegen-rt.jar jog-all.jar'
53
- }
54
- })
71
+ 'archive' => {
72
+ 'manifestEntries' => {
73
+ 'Automatic-Module-Name' => 'processing.core'
74
+ }
75
+ }
76
+ )
55
77
  plugin :jdeps, '3.1.2' do
56
78
  execute_goals 'jdkinternals', 'test-jdkinternals'
57
79
  end
data/pom.xml CHANGED
@@ -2,16 +2,16 @@
2
2
  <!--
3
3
 
4
4
 
5
- DO NOT MODIFIY - GENERATED CODE
5
+ DO NOT MODIFY - GENERATED CODE
6
6
 
7
7
 
8
8
  -->
9
- <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
9
+ <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
10
10
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
11
11
  <modelVersion>4.0.0</modelVersion>
12
12
  <groupId>ruby-processing</groupId>
13
13
  <artifactId>picrate</artifactId>
14
- <version>2.1.0</version>
14
+ <version>2.4.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>
@@ -64,19 +64,21 @@ DO NOT MODIFIY - GENERATED CODE
64
64
  <url>https://github.com/ruby-processing/PiCrate/issues</url>
65
65
  </issueManagement>
66
66
  <properties>
67
+ <batik.version>1.14</batik.version>
68
+ <itextpdf.version>5.5.13.2</itextpdf.version>
67
69
  <jogl.version>2.3.2</jogl.version>
68
70
  <jruby.api>http://jruby.org/apidocs/</jruby.api>
69
71
  <picrate.basedir>${project.basedir}</picrate.basedir>
70
72
  <polyglot.dump.pom>pom.xml</polyglot.dump.pom>
71
73
  <processing.api>http://processing.github.io/processing-javadocs/core/</processing.api>
72
- <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
74
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
73
75
  <source.directory>src</source.directory>
74
76
  </properties>
75
77
  <dependencies>
76
78
  <dependency>
77
79
  <groupId>org.jruby</groupId>
78
80
  <artifactId>jruby</artifactId>
79
- <version>9.2.12.0</version>
81
+ <version>9.2.16.0</version>
80
82
  <type>pom</type>
81
83
  </dependency>
82
84
  <dependency>
@@ -94,6 +96,16 @@ DO NOT MODIFIY - GENERATED CODE
94
96
  <artifactId>video</artifactId>
95
97
  <version>3.0.2</version>
96
98
  </dependency>
99
+ <dependency>
100
+ <groupId>org.apache.xmlgraphics</groupId>
101
+ <artifactId>batik-all</artifactId>
102
+ <version>${batik.version}</version>
103
+ </dependency>
104
+ <dependency>
105
+ <groupId>com.itextpdf</groupId>
106
+ <artifactId>itextpdf</artifactId>
107
+ <version>${itextpdf.version}</version>
108
+ </dependency>
97
109
  </dependencies>
98
110
  <build>
99
111
  <resources>
@@ -124,6 +136,29 @@ DO NOT MODIFIY - GENERATED CODE
124
136
  <plugin>
125
137
  <artifactId>maven-dependency-plugin</artifactId>
126
138
  <version>3.1.2</version>
139
+ <executions>
140
+ <execution>
141
+ <id>default-cli</id>
142
+ <configuration>
143
+ <artifactItems>
144
+ <artifactItem>
145
+ <groupId>com.itextpdf</groupId>
146
+ <artifactId>itextpdf</artifactId>
147
+ <version>${itextpdf.version}</version>
148
+ <type>jar</type>
149
+ <outputDirectory>${picrate.basedir}/library/pdf</outputDirectory>
150
+ </artifactItem>
151
+ <artifactItem>
152
+ <groupId>org.apache.xmlgraphics</groupId>
153
+ <artifactId>batik-all</artifactId>
154
+ <version>${batik.version}</version>
155
+ <type>jar</type>
156
+ <outputDirectory>${picrate.basedir}/library/svg</outputDirectory>
157
+ </artifactItem>
158
+ </artifactItems>
159
+ </configuration>
160
+ </execution>
161
+ </executions>
127
162
  </plugin>
128
163
  <plugin>
129
164
  <artifactId>maven-compiler-plugin</artifactId>
@@ -149,7 +184,7 @@ DO NOT MODIFIY - GENERATED CODE
149
184
  <configuration>
150
185
  <archive>
151
186
  <manifestEntries>
152
- <Class-Path>gluegen-rt.jar jog-all.jar</Class-Path>
187
+ <Automatic-Module-Name>processing.core</Automatic-Module-Name>
153
188
  </manifestEntries>
154
189
  </archive>
155
190
  </configuration>
@@ -0,0 +1,127 @@
1
+ /*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+ package monkstone;
7
+
8
+ import monkstone.noise.OpenSimplex2F;
9
+ import org.jruby.Ruby;
10
+ import org.jruby.RubyFixnum;
11
+ import org.jruby.RubyFloat;
12
+ import org.jruby.RubyModule;
13
+ import org.jruby.anno.JRubyMethod;
14
+ import org.jruby.anno.JRubyModule;
15
+ import org.jruby.runtime.ThreadContext;
16
+ import org.jruby.runtime.builtin.IRubyObject;
17
+
18
+ /**
19
+ *
20
+ * @author Martin Prout
21
+ */
22
+ @JRubyModule(name = "FastNoise")
23
+ public class FastNoiseModuleJava {
24
+
25
+ static OpenSimplex2F ng = new OpenSimplex2F(System.currentTimeMillis());
26
+
27
+ /**
28
+ *
29
+ * @param runtime Ruby
30
+ */
31
+ public static void createNoiseModule(Ruby runtime) {
32
+ RubyModule noiseModule = runtime.defineModule("FastNoise");
33
+ noiseModule.defineAnnotatedMethods(FastNoiseModuleJava.class);
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @param context ThreadContext
39
+ * @param recv IRubyObject
40
+ * @param args array of numeric values
41
+ * @return mapped value RubyFloat
42
+ */
43
+ @JRubyMethod(name = "tnoise", rest = true, module = true)
44
+ public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
45
+ double result = 0;
46
+ double one;
47
+ double two;
48
+ double three;
49
+ double four;
50
+ switch (args.length) {
51
+ case 2:
52
+ two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
53
+ one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
54
+ result = ng.noise2_XBeforeY(one, two);
55
+ break;
56
+ case 3:
57
+ three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
58
+ two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
59
+ one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
60
+ result = ng.noise3_XYBeforeZ(one, two, three);
61
+ break;
62
+ case 4:
63
+ four = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
64
+ three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
65
+ two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
66
+ one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
67
+ result = ng.noise4_XYBeforeZW(one, two, three, four);
68
+ break;
69
+ default:
70
+ throw new RuntimeException("Min 2D Max 4D Noise");
71
+ }
72
+ return RubyFloat.newFloat(context.runtime, result);
73
+ }
74
+
75
+ /**
76
+ *
77
+ * @param context ThreadContext
78
+ * @param recv IRubyObject
79
+ * @param args array of numeric values
80
+ * @return mapped value RubyFloat
81
+ */
82
+ @JRubyMethod(name = "noise", rest = true, module = true)
83
+ public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
84
+ double result = 0;
85
+ double one;
86
+ double two;
87
+ double three;
88
+ double four;
89
+ switch (args.length) {
90
+ case 1:
91
+ one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
92
+ result = ng.noise2(one, 0);
93
+ break;
94
+ case 2:
95
+ two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
96
+ one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
97
+ result = ng.noise2(one, two);
98
+ break;
99
+ case 3:
100
+ three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
101
+ two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
102
+ one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
103
+ result = ng.noise3_Classic(one, two, three);
104
+ break;
105
+ case 4:
106
+ four = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
107
+ three = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
108
+ two = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
109
+ one = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
110
+ result = ng.noise4_Classic(one, two, three, four);
111
+ break;
112
+ default:
113
+ throw new RuntimeException("Maximum of 4D Noise");
114
+ }
115
+ return RubyFloat.newFloat(context.runtime, result);
116
+ }
117
+ // @JRubyMethod(name = "noise_seed", rest = true, module = true)
118
+ // public static IRubyObject noiseSeedImpl(ThreadContext context, IRubyObject recv, IRubyObject arg) {
119
+ // long seed;
120
+ // if (arg instanceof RubyNumeric) {
121
+ // seed = ((RubyNumeric) arg).getLongValue();
122
+ // ng = new OpenSimplex2F(seed);
123
+ // return RubyBoolean.newBoolean(context.runtime, true);
124
+ // }
125
+ // return RubyBoolean.newBoolean(context.runtime, false);
126
+ // }
127
+ }