propane 3.6.0-java → 3.10.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +5 -1
  5. data/README.md +6 -13
  6. data/Rakefile +7 -6
  7. data/lib/java/japplemenubar/JAppleMenuBar.java +88 -0
  8. data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  9. data/lib/java/monkstone/ColorUtil.java +127 -0
  10. data/lib/java/monkstone/MathToolModule.java +287 -0
  11. data/lib/java/monkstone/PropaneLibrary.java +46 -0
  12. data/lib/java/monkstone/core/LibraryProxy.java +136 -0
  13. data/lib/java/monkstone/fastmath/DegLutTables.java +111 -0
  14. data/lib/java/monkstone/fastmath/Deglut.java +71 -0
  15. data/lib/java/monkstone/fastmath/package-info.java +6 -0
  16. data/lib/java/monkstone/filechooser/Chooser.java +39 -0
  17. data/lib/java/monkstone/noise/FastTerrain.java +874 -0
  18. data/lib/java/monkstone/noise/Noise.java +90 -0
  19. data/lib/java/monkstone/noise/NoiseGenerator.java +75 -0
  20. data/lib/java/monkstone/noise/NoiseMode.java +28 -0
  21. data/lib/java/monkstone/noise/OpenSimplex2F.java +881 -0
  22. data/lib/java/monkstone/noise/OpenSimplex2S.java +1106 -0
  23. data/lib/java/monkstone/noise/SmoothTerrain.java +1099 -0
  24. data/lib/java/monkstone/slider/CustomHorizontalSlider.java +164 -0
  25. data/lib/java/monkstone/slider/CustomVerticalSlider.java +178 -0
  26. data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +145 -0
  27. data/lib/java/monkstone/slider/SimpleSlider.java +166 -0
  28. data/lib/java/monkstone/slider/SimpleVerticalSlider.java +157 -0
  29. data/lib/java/monkstone/slider/Slider.java +61 -0
  30. data/lib/java/monkstone/slider/SliderBar.java +245 -0
  31. data/lib/java/monkstone/slider/SliderGroup.java +56 -0
  32. data/lib/java/monkstone/slider/WheelHandler.java +35 -0
  33. data/lib/java/monkstone/vecmath/GfxRender.java +86 -0
  34. data/lib/java/monkstone/vecmath/JRender.java +56 -0
  35. data/lib/java/monkstone/vecmath/ShapeRender.java +87 -0
  36. data/lib/java/monkstone/vecmath/package-info.java +20 -0
  37. data/lib/java/monkstone/vecmath/vec2/Vec2.java +802 -0
  38. data/lib/java/monkstone/vecmath/vec2/package-info.java +6 -0
  39. data/lib/java/monkstone/vecmath/vec3/Vec3.java +727 -0
  40. data/lib/java/monkstone/vecmath/vec3/package-info.java +6 -0
  41. data/lib/java/monkstone/videoevent/CaptureEvent.java +27 -0
  42. data/lib/java/monkstone/videoevent/MovieEvent.java +32 -0
  43. data/lib/java/monkstone/videoevent/package-info.java +20 -0
  44. data/lib/java/processing/awt/PGraphicsJava2D.java +3040 -0
  45. data/lib/java/processing/awt/PImageAWT.java +377 -0
  46. data/lib/java/processing/awt/PShapeJava2D.java +387 -0
  47. data/lib/java/processing/awt/PSurfaceAWT.java +1581 -0
  48. data/lib/java/processing/awt/ShimAWT.java +581 -0
  49. data/lib/java/processing/core/PApplet.java +15156 -0
  50. data/lib/java/processing/core/PConstants.java +523 -0
  51. data/lib/java/processing/core/PFont.java +1126 -0
  52. data/lib/java/processing/core/PGraphics.java +8600 -0
  53. data/lib/java/processing/core/PImage.java +3377 -0
  54. data/lib/java/processing/core/PMatrix.java +208 -0
  55. data/lib/java/processing/core/PMatrix2D.java +562 -0
  56. data/lib/java/processing/core/PMatrix3D.java +890 -0
  57. data/lib/java/processing/core/PShape.java +3561 -0
  58. data/lib/java/processing/core/PShapeOBJ.java +483 -0
  59. data/lib/java/processing/core/PShapeSVG.java +2016 -0
  60. data/lib/java/processing/core/PStyle.java +63 -0
  61. data/lib/java/processing/core/PSurface.java +198 -0
  62. data/lib/java/processing/core/PSurfaceNone.java +431 -0
  63. data/lib/java/processing/core/PVector.java +1066 -0
  64. data/lib/java/processing/core/ThinkDifferent.java +115 -0
  65. data/lib/java/processing/data/DoubleDict.java +850 -0
  66. data/lib/java/processing/data/DoubleList.java +928 -0
  67. data/lib/java/processing/data/FloatDict.java +847 -0
  68. data/lib/java/processing/data/FloatList.java +936 -0
  69. data/lib/java/processing/data/IntDict.java +807 -0
  70. data/lib/java/processing/data/IntList.java +936 -0
  71. data/lib/java/processing/data/JSONArray.java +1260 -0
  72. data/lib/java/processing/data/JSONObject.java +2282 -0
  73. data/lib/java/processing/data/JSONTokener.java +435 -0
  74. data/lib/java/processing/data/LongDict.java +802 -0
  75. data/lib/java/processing/data/LongList.java +937 -0
  76. data/lib/java/processing/data/Sort.java +46 -0
  77. data/lib/java/processing/data/StringDict.java +613 -0
  78. data/lib/java/processing/data/StringList.java +800 -0
  79. data/lib/java/processing/data/Table.java +4936 -0
  80. data/lib/java/processing/data/TableRow.java +198 -0
  81. data/lib/java/processing/data/XML.java +1156 -0
  82. data/lib/java/processing/dxf/RawDXF.java +404 -0
  83. data/lib/java/processing/event/Event.java +125 -0
  84. data/lib/java/processing/event/KeyEvent.java +70 -0
  85. data/lib/java/processing/event/MouseEvent.java +114 -0
  86. data/lib/java/processing/event/TouchEvent.java +57 -0
  87. data/lib/java/processing/javafx/PGraphicsFX2D.java +32 -0
  88. data/lib/java/processing/javafx/PSurfaceFX.java +173 -0
  89. data/lib/java/processing/net/Client.java +744 -0
  90. data/lib/java/processing/net/Server.java +388 -0
  91. data/lib/java/processing/opengl/FontTexture.java +378 -0
  92. data/lib/java/processing/opengl/FrameBuffer.java +513 -0
  93. data/lib/java/processing/opengl/LinePath.java +627 -0
  94. data/lib/java/processing/opengl/LineStroker.java +681 -0
  95. data/lib/java/processing/opengl/PGL.java +3483 -0
  96. data/lib/java/processing/opengl/PGraphics2D.java +615 -0
  97. data/lib/java/processing/opengl/PGraphics3D.java +281 -0
  98. data/lib/java/processing/opengl/PGraphicsOpenGL.java +13753 -0
  99. data/lib/java/processing/opengl/PJOGL.java +2008 -0
  100. data/lib/java/processing/opengl/PShader.java +1484 -0
  101. data/lib/java/processing/opengl/PShapeOpenGL.java +5269 -0
  102. data/lib/java/processing/opengl/PSurfaceJOGL.java +1385 -0
  103. data/lib/java/processing/opengl/Texture.java +1696 -0
  104. data/lib/java/processing/opengl/VertexBuffer.java +88 -0
  105. data/lib/java/processing/opengl/cursors/arrow.png +0 -0
  106. data/lib/java/processing/opengl/cursors/cross.png +0 -0
  107. data/lib/java/processing/opengl/cursors/hand.png +0 -0
  108. data/lib/java/processing/opengl/cursors/license.txt +27 -0
  109. data/lib/java/processing/opengl/cursors/move.png +0 -0
  110. data/lib/java/processing/opengl/cursors/text.png +0 -0
  111. data/lib/java/processing/opengl/cursors/wait.png +0 -0
  112. data/lib/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  113. data/lib/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  114. data/lib/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  115. data/lib/java/processing/opengl/shaders/LightVert.glsl +151 -0
  116. data/lib/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  117. data/lib/java/processing/opengl/shaders/LineVert.glsl +100 -0
  118. data/lib/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  119. data/lib/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  120. data/lib/java/processing/opengl/shaders/PointVert.glsl +56 -0
  121. data/lib/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  122. data/lib/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  123. data/lib/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  124. data/lib/java/processing/opengl/shaders/TexVert.glsl +38 -0
  125. data/lib/java/processing/pdf/PGraphicsPDF.java +581 -0
  126. data/lib/java/processing/svg/PGraphicsSVG.java +378 -0
  127. data/lib/propane/app.rb +9 -10
  128. data/lib/propane/runner.rb +10 -12
  129. data/lib/propane/version.rb +1 -1
  130. data/library/pdf/pdf.rb +7 -0
  131. data/library/svg/svg.rb +7 -0
  132. data/mvnw +3 -3
  133. data/mvnw.cmd +2 -2
  134. data/pom.rb +30 -3
  135. data/pom.xml +54 -3
  136. data/propane.gemspec +7 -3
  137. data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
  138. data/src/main/java/monkstone/MathToolModule.java +30 -30
  139. data/src/main/java/monkstone/PropaneLibrary.java +2 -0
  140. data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
  141. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  142. data/src/main/java/monkstone/fastmath/Deglut.java +6 -56
  143. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  144. data/src/main/java/monkstone/noise/OpenSimplex2F.java +813 -0
  145. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
  146. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  147. data/src/main/java/monkstone/vecmath/JRender.java +6 -6
  148. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +20 -19
  149. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +12 -12
  150. data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -3
  151. data/src/main/java/processing/core/PApplet.java +13242 -13374
  152. data/src/main/java/processing/core/PConstants.java +155 -163
  153. data/src/main/java/processing/core/PGraphics.java +118 -111
  154. data/src/main/java/processing/opengl/PJOGL.java +6 -5
  155. data/src/main/java/processing/pdf/PGraphicsPDF.java +581 -0
  156. data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
  157. data/test/deglut_spec_test.rb +2 -2
  158. data/vendors/Rakefile +1 -1
  159. metadata +146 -17
  160. data/library/simplex_noise/simplex_noise.rb +0 -5
  161. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -436
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8e0f1b907888514e27260110225621d9fa5f7792d319ddae436540bd98be75a
4
- data.tar.gz: f26c694203a50b98df365b2b003d2c258c11c87e550618a146158a69dfa7954e
3
+ metadata.gz: 412793f807afe7defb88f5a8376cf15de48e65f79ff2758d8fa9c4c1a0eb0202
4
+ data.tar.gz: a6a387f0a7e4db3b6a7048f35f1f4d5006734fe6a37a021918bd81850c37eedc
5
5
  SHA512:
6
- metadata.gz: 1263af382d8cec20f5d16d760d0afe542802955ee42bb398e4ca28e8e5583ca04a04fd619529567b5df78cadd3f824c17de8d860a8ba1c3f003b2453a87fa16a
7
- data.tar.gz: 90b9e87ca02ee5dde1bfd71dc51efc91574ee2855fddfea113793d2e3d8434b07f090d2170c0a4df798fd6b200846cb9645415c09158d684f3a757ef8ee0682f
6
+ metadata.gz: e229c8b432547844db7d625fdfeff7551300fb8319bc485aa99a6bdcb723d364d0eb2bd20673a68dba5f8433e6f897d2e204f34f1028430b986b45967cdf48ec
7
+ data.tar.gz: 47864625dcf2cfd9cdfbce74cbd4ac2b470c97482e90f119dc235027557afe80b3302f150a097a2027a119a546ff29b0017bf6d4426178b2e966b4f21d360c6e
data/.mvn/extensions.xml CHANGED
@@ -3,6 +3,6 @@
3
3
  <extension>
4
4
  <groupId>io.takari.polyglot</groupId>
5
5
  <artifactId>polyglot-ruby</artifactId>
6
- <version>0.4.5</version>
6
+ <version>0.4.6</version>
7
7
  </extension>
8
8
  </extensions>
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: java
2
2
  dist: bionic
3
3
 
4
4
  rvm:
5
- - jruby-9.2.12.0
5
+ - jruby-9.2.17.0
6
6
  jdk:
7
7
  - openjdk11
8
8
  os:
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- **v3.6.0** Recommend JRuby-9.2.14.0 use video-2.0 release
1
+ **v3.10.0** Default to using FastNoise module, with alternative of SmoothNoise module.
2
+
3
+ **v3.8.0** Refactor noise to delegate pattern, improve default implementation and add simplex noise option
4
+
5
+ **v3.7.1** Recommend JRuby-9.2.16.0 use
2
6
 
3
7
  **v3.5.0** Rebase processing core code around Sam Pottingers latest fixes for JOGL an image save, does mean breaking some of Diwis and Joshua Davis examples, but one hopes codeanticode knows what he's doing.
4
8
 
data/README.md CHANGED
@@ -8,12 +8,10 @@ adjust above for your OS/distro setup.
8
8
 
9
9
  ## Requirements
10
10
 
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.
11
+ Previously there has been linker issue with P2D or P3D sketches with stock openjdk with some linux distros, but that seems to have gone away. [Adopt open jdk binaries][adopt] have always worked.
12
12
 
13
- - `jdk-11.0.3+`
14
- - `jruby-9.2.12.0`
15
-
16
- Currently you can ignore `illegal reflective access` warnings, see [here how to suppress them][warning].
13
+ - `jdk-11.0.7+`
14
+ - `jruby-9.2.17.0`
17
15
 
18
16
  ## Building and testing
19
17
 
@@ -27,10 +25,10 @@ rake javadoc
27
25
 
28
26
  ```bash
29
27
  jgem install propane # from rubygems
30
- jgem install propane-3.6.0-java.gem # local install
28
+ jgem install propane-3.10.0-java.gem # local install
31
29
  # Alternative
32
30
  jruby -S gem install propane # from rubygems
33
- jruby -S gem install propane-3.6.0-java.gem # local install
31
+ jruby -S gem install propane-3.10.0-java.gem # local install
34
32
  ```
35
33
 
36
34
  ## Check Install
@@ -39,11 +37,6 @@ To check version and confirm gem bin files are on your path (also checks JDK ver
39
37
  ```bash
40
38
  propane --version
41
39
  ```
42
-
43
- ## Suppressing Reflective Access warnings
44
-
45
- Since propane-3.5.0 it is possible to suppress reflective access warnings by setting JAVA_HOME environmental variable jruby does the rest.
46
-
47
40
  ## Usage
48
41
 
49
42
  A propane sketch:-
@@ -100,7 +93,7 @@ See [gh-pages][gh-pages] for more detailed instructions and much more.
100
93
  ```bash
101
94
  propane --install samples
102
95
  ```
103
- 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.
96
+ please move existing `propane_samples` if you wish to keep them. The current release features some noise sketches that exploit the new choice of noise implementation.
104
97
 
105
98
  [adopt]: https://adoptopenjdk.net/
106
99
  [building]:http://ruby-processing.github.io/building/building/
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ task default: %i[init compile install test gem]
8
8
  desc 'Copy Jars'
9
9
  task :init do
10
10
  jogl24 = File.join(ENV['HOME'], 'jogl24')
11
- opengl = Dir.entries(jogl24).grep(/amd64|universal/).select { |jar| jar =~ /linux|windows|macosx/ }
11
+ opengl = Dir.entries(jogl24).grep(/amd64|universal|arm64/).select { |jar| jar =~ /linux|windows|macosx|ios|/ }
12
12
  opengl.concat %w[jogl-all.jar gluegen-rt.jar]
13
13
  opengl.each do |gl|
14
14
  FileUtils.cp(File.join(jogl24, gl), File.join('.', 'lib'))
@@ -17,7 +17,8 @@ end
17
17
 
18
18
  desc 'Install'
19
19
  task :install do
20
- sh "mv target/propane-#{Propane::VERSION}.jar lib"
20
+ sh 'mvn dependency:copy'
21
+ FileUtils.mv("target/propane-#{Propane::VERSION}.jar", 'lib')
21
22
  end
22
23
 
23
24
  desc 'Gem'
@@ -35,9 +36,9 @@ task :compile do
35
36
  sh './mvnw package'
36
37
  end
37
38
 
38
- desc 'JRuby-Complete'
39
- task :install_complete do
40
- sh 'cd vendors && rake'
39
+ desc 'pmd'
40
+ task :pmd do
41
+ sh './mvnw pmd:pmd'
41
42
  end
42
43
 
43
44
  desc 'Test'
@@ -53,7 +54,7 @@ end
53
54
  desc 'clean'
54
55
  task :clean do
55
56
  Dir['./**/*.{jar,gem}'].each do |path|
56
- puts "Deleting #{path} ..."
57
+ puts 'Deleting #{path} ...'
57
58
  File.delete(path)
58
59
  end
59
60
  FileUtils.rm_rf('./target')
@@ -0,0 +1,88 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2011-12 hansi raber, released under LGPL under agreement
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation, version 2.1.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General
16
+ Public License along with this library; if not, write to the
17
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
+ Boston, MA 02111-1307 USA
19
+ */
20
+ package japplemenubar;
21
+
22
+ import java.io.*;
23
+
24
+ import processing.core.PApplet;
25
+
26
+
27
+ /**
28
+ * Starting point for the application. General initialization should be done
29
+ * inside the ApplicationController's init() method. If certain kinds of
30
+ * non-Swing initialization takes too long, it should happen in a new Thread
31
+ * and off the Swing event dispatch thread (EDT).
32
+ *
33
+ * @author hansi
34
+ */
35
+ public class JAppleMenuBar {
36
+ static JAppleMenuBar instance;
37
+ static final String FILENAME = "libjAppleMenuBar.jnilib";
38
+
39
+ static {
40
+ try {
41
+ File temp = File.createTempFile("processing", "menubar");
42
+ temp.delete(); // remove the file itself
43
+ temp.mkdirs(); // create a directory out of it
44
+ temp.deleteOnExit();
45
+
46
+ File jnilibFile = new File(temp, FILENAME);
47
+ InputStream input = JAppleMenuBar.class.getResourceAsStream(FILENAME);
48
+ if (input != null) {
49
+ if (PApplet.saveStream(jnilibFile, input)) {
50
+ System.load(jnilibFile.getAbsolutePath());
51
+ instance = new JAppleMenuBar();
52
+
53
+ } else {
54
+ sadness("Problem saving " + FILENAME + " for full screen use.");
55
+ }
56
+ } else {
57
+ sadness("Could not load " + FILENAME + " from core.jar");
58
+ }
59
+ } catch (IOException e) {
60
+ sadness("Unknown error, here's the stack trace.");
61
+ e.printStackTrace();
62
+ }
63
+ }
64
+
65
+
66
+ static void sadness(String msg) {
67
+ System.err.println("Full screen mode disabled. " + msg);
68
+ }
69
+
70
+
71
+ // static public void show() {
72
+ // instance.setVisible(true);
73
+ // }
74
+
75
+
76
+ static public void hide() {
77
+ instance.setVisible(false, false);
78
+ }
79
+
80
+
81
+ public native void setVisible(boolean visibility, boolean kioskMode);
82
+
83
+
84
+ // public void setVisible(boolean visibility) {
85
+ // // Keep original API in-tact. Default kiosk-mode to off.
86
+ // setVisible(visibility, false);
87
+ // }
88
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * This utility allows JRubyArt users to use the processing.org color method
3
+ * in their sketches. Includes a method to efficiently convert an array of web
4
+ * strings to an array of color int, and another to convert an array of color
5
+ * int to a string that can be used in ruby code (to generate web color array).
6
+ * Copyright (c) 2015-20 Martin Prout.
7
+ * This utility is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation; either version 2.1 of the License, or (at
10
+ * your option) any later version.
11
+ *
12
+ * Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html
13
+ */
14
+ package monkstone;
15
+
16
+ import java.util.Random;
17
+ /**
18
+ *
19
+ * @author Martin Prout
20
+ */
21
+ public class ColorUtil {
22
+
23
+ /**
24
+ * Returns hex long as a positive int unless greater than Integer.MAX_VALUE
25
+ * else return the complement as a negative integer or something like that
26
+ *
27
+ * @param hexlong long
28
+ * @return rgb int
29
+ */
30
+ static final int hexLong(long hexlong) {
31
+ long SPLIT = Integer.MAX_VALUE + 1;
32
+ if (hexlong < SPLIT) {
33
+ return (int) hexlong;
34
+ } else {
35
+ return (int) (hexlong - SPLIT * 2L);
36
+ }
37
+ }
38
+
39
+ /**
40
+ * @param hexstring String
41
+ * @return rgb int
42
+ */
43
+ static public int colorString(String hexstring) {
44
+ return java.awt.Color.decode(hexstring).getRGB();
45
+ }
46
+
47
+ /**
48
+ *
49
+ * @param web Array of web (hex) String
50
+ * @return array of color int according to java
51
+ */
52
+ static public int[] webArray(String[] web) {
53
+ int[] result = new int[web.length];
54
+ for (int i = 0; i < web.length; i++) {
55
+ result[i] = java.awt.Color.decode(web[i]).getRGB();
56
+ }
57
+ return result;
58
+ }
59
+
60
+ /**
61
+ * Return a ruby string of the form "%w(a b c)" where a, b, c are raw web
62
+ * strings. This string can be used in ruby code.
63
+ *
64
+ * @param hex int array
65
+ * @return String for use in ruby
66
+ */
67
+ static public String rubyString(int[] hex) {
68
+ StringBuilder result = new StringBuilder("%w(");
69
+ for (int i = 0; i < hex.length; i++) {
70
+ result.append(String.format("#%06X", (0xFFFFFF & hex[i])));
71
+ if (i < hex.length - 1) {
72
+ result.append(' ');
73
+ }
74
+ }
75
+ result.append(")\n");
76
+ return result.toString();
77
+ }
78
+
79
+ /**
80
+ *
81
+ * @param hex double
82
+ * @return hex float
83
+ */
84
+ static public float colorLong(double hex) {
85
+ return (float) hex;
86
+ }
87
+
88
+ /**
89
+ *
90
+ * @param hexlong long
91
+ * @return hexlong int
92
+ */
93
+ static public int colorLong(long hexlong) {
94
+ return hexLong(hexlong);
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @param hex double
100
+ * @return hex float
101
+ */
102
+ static public float colorDouble(double hex) {
103
+ return (float) hex;
104
+ }
105
+
106
+ static public int[] shuffle(int[] cols) {
107
+ Random rgen = new Random(); // Random number generator
108
+ for (int i = 0; i < cols.length; i++) {
109
+ int randomPosition = rgen.nextInt(cols.length);
110
+ int temp = cols[i];
111
+ cols[i] = cols[randomPosition];
112
+ cols[randomPosition] = temp;
113
+ }
114
+ return cols;
115
+ }
116
+
117
+ /**
118
+ *
119
+ * @param hue
120
+ * @param sat
121
+ * @param brightness
122
+ * @return
123
+ */
124
+ static public int hsbToRgB(double hue, double sat, double brightness) {
125
+ return java.awt.Color.HSBtoRGB((float) hue, (float) sat, (float) brightness);
126
+ }
127
+ }
@@ -0,0 +1,287 @@
1
+ /**
2
+ * The purpose of this tool is to allow JRubyArt users to use an alternative
3
+ * to processing.org map, lerp and norm methods in their sketches and to implement
4
+ * JRubyArt convenenience method grid(width, height, stepW, stepH) { |x, y| do stuff }
5
+ * Copyright (c) 2015-20 Martin Prout. This tool is free software; you can
6
+ * redistribute it and/or modify it under the terms of the GNU Lesser General
7
+ * Public License as published by the Free Software Foundation; either version
8
+ * 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html
11
+ */
12
+ package monkstone;
13
+
14
+ import org.jruby.Ruby;
15
+ import org.jruby.RubyFixnum;
16
+ import org.jruby.RubyFloat;
17
+ import org.jruby.RubyModule;
18
+ import org.jruby.RubyRange;
19
+ import org.jruby.anno.JRubyMethod;
20
+ import org.jruby.anno.JRubyModule;
21
+ import org.jruby.runtime.Block;
22
+ import org.jruby.runtime.ThreadContext;
23
+ import org.jruby.runtime.builtin.IRubyObject;
24
+
25
+ /**
26
+ *
27
+ * @author Martin Prout
28
+ */
29
+ @JRubyModule(name = "MathTool")
30
+ public class MathToolModule {
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
+ }
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
+ }
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);
94
+ }
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);
111
+ }
112
+
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
+ }
135
+
136
+ /**
137
+ * Identical to p5map(value, low, high, 0, 1). Numbers outside of the range
138
+ * are not clamped to 0 and 1, because out-of-range values are often
139
+ * intentional and useful.
140
+ *
141
+ * @param context ThreadContext
142
+ * @param recv IRubyObject
143
+ * @param args array of args must be be numeric
144
+ * @return mapped value RubyFloat
145
+ */
146
+ @JRubyMethod(name = "norm", rest = true, module = true)
147
+ public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
148
+ double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
149
+ double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
150
+ double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
151
+ return mapMt(context, value, start, stop, 0, 1.0);
152
+ }
153
+
154
+ /**
155
+ * Identical to p5map(value, low, high, 0, 1) but 'clamped'. Numbers outside
156
+ * of the range are clamped to 0 and 1,
157
+ *
158
+ * @param context ThreadContext
159
+ * @param recv IRubyObject
160
+ * @param args array of args must be be numeric
161
+ * @return mapped value RubyFloat
162
+ */
163
+ @JRubyMethod(name = "norm_strict", rest = true, module = true)
164
+ public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
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);
173
+ }
174
+ if (value > max) {
175
+ return mapMt(context, max, start, stop, 0, 1.0);
176
+ }
177
+ return mapMt(context, value, start, stop, 0, 1.0);
178
+ }
179
+ // start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
180
+ static final RubyFloat mapMt(ThreadContext context, double value, double first1, double last1, double first2, double last2) {
181
+ Ruby ruby = context.runtime;
182
+ double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
183
+ return ruby.newFloat(result);
184
+ }
185
+
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
+ }
206
+ }
207
+
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));
282
+ }
283
+ }
284
+ }
285
+ return context.nil;
286
+ }
287
+ }