propane 2.0.3-java → 2.0.4-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f3c6dc86329bbde3a56d284d72b1c6a3fe5775e
4
- data.tar.gz: 0ad232d5e8538db5e81c43cec89afc4e340ce14c
3
+ metadata.gz: b8a56b1bfc4c73b83741bc7e847298d4b3d0e35c
4
+ data.tar.gz: fa2f47690147a25f9f23b229924969011e618d3c
5
5
  SHA512:
6
- metadata.gz: 34c22b6d7512b91f33161501723f65f3409ab204b1ab5c6148740d8b83e4bb99e069d0ba5977ab3a74c4c6e1e4e2164b6b049af749452cea8f1a69058bb5adc5
7
- data.tar.gz: daf9fe02b0423fae841cf8e05abfdd8453e30f6a390b0d7feebcf1f3a830bacaa8c81d0e23f73a6919d287b415aa21bb3d1a1757a6d1d99f2e211ac27dd0f84c
6
+ metadata.gz: ff02e67b5b2eb154820b51f2271e12a3f8af13c18e2f82fd8ee4f09b5dfd379c3884e8f5ac4c561e5f2068334ec4fb3497471f0bf6e5682aeade7fc6dc874662
7
+ data.tar.gz: 43e964fe32d9870740fef91680cc9e785f364aa227ec1916ce699f453955cb465a7662476f198979f9a3689d454af17120424072deb643dfdb9410b036fdfa02
@@ -1,5 +1,5 @@
1
+ **v2.0.4** Correct `norm_strict`, add `math_tool_test` add `simplex_noise` expand samples
1
2
  **v2.0.3** Suggest use of jruby-9.1.4.0, more about loading vanilla libraries
2
-
3
3
  **v2.0.2** Refactor install to either install `samples\sound\video` or warn (update to use a local processing-3.2.1 core, this is why travis fails), fix some examples, hence `0.3`
4
4
 
5
5
  **v2.0.1** Support processing-3.2.0
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Propane
2
2
  [![Gem Version](https://badge.fury.io/rb/propane.svg)](https://badge.fury.io/rb/propane)
3
3
 
4
- A slim layer to communicate with Processing from JRuby, features a polyglot maven build, this started out as a non serious project by Phillip Cunningam called ribiprocessing. It has now morphed into an experimental project for ruby-processing so we can now "Cook with Gas". We have created a configuration free version of ruby processing, for processing-3.2.1+, where we get processing core from maven central (and opengl currently testing on linux64/mac). These jars are small enough to include in the gem distribution, and hence we should not require configuration. This has created a scriptable version, ie files get run direct from jruby, but you could use jruby-complete if you used the propane script (avoids need to give the absolute data path for the data folder, but would also be needed for a watch mode).
4
+ A slim layer to communicate with Processing from JRuby, features a polyglot maven build. We have created a configuration free version of ruby processing, for processing-3.2.1+, where we include processing core (from a local maven repository and opengl etc from maven central). These jars are small enough to include in a gem distribution, and hence we do not require configuration. This has created a scriptable version, ie files get run direct from jruby, but you could use jruby-complete if you used the propane script (avoids need to give the absolute data path for the data folder, but would also be needed for a watch mode). NB: currently we only include linux64 and macOS opengl binaries, please fork this repository to include binaries for your OS if not included. See guide to [building ruby-processing projects][building].
5
+
5
6
  ## Requirements
6
7
 
7
8
  - jdk8+ since version 0.6.0
8
- - jruby-9.1.4.0+
9
+ - jruby-9.1.5.0+
9
10
  - mvn-3.3.1+ (development only)
11
+ - core.jar processing-3.2.1 (development only until processing.org is available at maven central)
10
12
 
11
13
  ## Building and testing
12
14
 
@@ -67,3 +69,5 @@ propane --install sound
67
69
  propane --install video
68
70
  ```
69
71
  Other java libraries can be manually installed to the same folder (no need for processing ide)
72
+
73
+ [building]:http://ruby-processing.github.io/building/building/
data/Rakefile CHANGED
@@ -48,6 +48,8 @@ desc 'Test'
48
48
  task :test do
49
49
  sh 'jruby test/respond_to_test.rb'
50
50
  sh 'jruby test/create_test.rb'
51
+ sh 'jruby test/math_tool_test.rb'
52
+ sh 'jruby test/deglut_spec_test.rb'
51
53
  end
52
54
 
53
55
  desc 'clean'
@@ -7,12 +7,6 @@ module Propane
7
7
  include_package 'processing.core' # imports the processing jar.
8
8
  # Load vecmath, fastmath and mathtool modules
9
9
  Java::Monkstone::PropaneLibrary.load(JRuby.runtime)
10
- # We may change this
11
- module Render
12
- java_import 'monkstone.vecmath.AppRender'
13
- java_import 'monkstone.vecmath.ShapeRender'
14
- end
15
-
16
10
  SKETCH_ROOT = File.absolute_path('.')
17
11
 
18
12
  # This class is the base class the user should inherit from when making
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
  module Propane
4
- VERSION = '2.0.3'.freeze
4
+ VERSION = '2.0.4'.freeze
5
5
  end
@@ -0,0 +1,3 @@
1
+ class Propane::App
2
+ SimplexNoise = Java::MonkstoneNoise::SimplexNoise
3
+ end
data/pom.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
  project 'rp5extras', 'https://github.com/monkstone/propane' do
3
3
  model_version '4.0.0'
4
- id 'propane:rp5extras', '2.0.3'
4
+ id 'propane:propane', '2.0.4'
5
5
  packaging 'jar'
6
6
  description 'rp5extras for propane'
7
7
  organization 'ruby-processing', 'https://ruby-processing.github.io'
@@ -32,7 +32,7 @@ project 'rp5extras', 'https://github.com/monkstone/propane' do
32
32
  'jogl.version' => '2.3.2'
33
33
  )
34
34
 
35
- pom 'org.jruby:jruby:9.1.4.0'
35
+ pom 'org.jruby:jruby:9.1.5.0'
36
36
  jar 'org.processing:core:3.2.1'
37
37
  jar 'org.processing:video:3.0.2'
38
38
  jar('org.jogamp.jogl:jogl-all:${jogl.version}')
data/pom.xml CHANGED
@@ -10,8 +10,8 @@ DO NOT MODIFIY - GENERATED CODE
10
10
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
11
11
  <modelVersion>4.0.0</modelVersion>
12
12
  <groupId>propane</groupId>
13
- <artifactId>rp5extras</artifactId>
14
- <version>2.0.3</version>
13
+ <artifactId>propane</artifactId>
14
+ <version>2.0.4</version>
15
15
  <name>rp5extras</name>
16
16
  <description>rp5extras for propane</description>
17
17
  <url>https://github.com/monkstone/propane</url>
@@ -58,7 +58,7 @@ DO NOT MODIFIY - GENERATED CODE
58
58
  <dependency>
59
59
  <groupId>org.jruby</groupId>
60
60
  <artifactId>jruby</artifactId>
61
- <version>9.1.4.0</version>
61
+ <version>9.1.5.0</version>
62
62
  <type>pom</type>
63
63
  </dependency>
64
64
  <dependency>
@@ -9,8 +9,8 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ['monkstone']
10
10
  gem.email = ['mamba2928@yahoo.co.uk']
11
11
  gem.licenses = %w(GPL-3.0 LGPL-2.0)
12
- gem.description = %q{A Standalone Ruby Processing implementation}
13
- gem.summary = %q{A really slim layer between Ruby and Processing-3.2.1.}
12
+ gem.description = %q{A batteries included version of processing in ruby}
13
+ gem.summary = %q{A jruby wrapper for processing-3.2.1}
14
14
  gem.homepage = 'https://ruby-processing.github.io/propane/'
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.files << 'lib/propane.jar'
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The purpose of this tool is to allow JRubyArt users to use an alternative
2
+ * The purpose of this tool is to allow propane users to use an alternative
3
3
  * to processing.org map, lerp and norm methods in their sketches
4
4
  * Copyright (c) 2015-16 Martin Prout. This tool is free software; you can
5
5
  * redistribute it and/or modify it under the terms of the GNU Lesser General
@@ -45,7 +45,7 @@ public class MathToolModule {
45
45
  */
46
46
  @JRubyMethod(name = "map1d", rest = true, module = true)
47
47
  public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
48
- double value = (args[0] instanceof RubyFloat)
48
+ double value = (args[0] instanceof RubyFloat)
49
49
  ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
50
50
  RubyRange r1 = (RubyRange) args[1];
51
51
  RubyRange r2 = (RubyRange) args[2];
@@ -83,10 +83,10 @@ public class MathToolModule {
83
83
  double max = Math.max(first1, last1);
84
84
  double min = Math.min(first1, last1);
85
85
  if (value < min) {
86
- value = min;
86
+ return mapMt(context, min, first1, last1, first2, last2);
87
87
  }
88
88
  if (value > max) {
89
- value = max;
89
+ return mapMt(context, max, first1, last1, first2, last2);
90
90
  }
91
91
  return mapMt(context, value, first1, last1, first2, last2);
92
92
  }
@@ -164,15 +164,17 @@ public class MathToolModule {
164
164
  double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
165
165
  double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
166
166
  double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
167
- if (value <= start) {
168
- return new RubyFloat(ruby, 0);
169
- } else if (value >= stop) {
170
- return new RubyFloat(ruby, 1.0);
171
- } else {
172
- return mapMt(context, value, start, stop, 0, 1.0);
167
+ double max = Math.max(start, stop);
168
+ double min = Math.min(start, stop);
169
+ if (value < min) {
170
+ return mapMt(context, min, start, stop, 0, 1.0);
171
+ }
172
+ if (value > max) {
173
+ return mapMt(context, max, start, stop, 0, 1.0);
173
174
  }
175
+ return mapMt(context, value, start, stop, 0, 1.0);
174
176
  }
175
-
177
+ // start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
176
178
  static final RubyFloat mapMt(ThreadContext context, double value, double first1, double last1, double first2, double last2) {
177
179
  double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
178
180
  return context.runtime.newFloat(result);
@@ -0,0 +1,437 @@
1
+ /*
2
+ * A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
3
+ *
4
+ * Based on example code by Stefan Gustavson (stegu@itn.liu.se).
5
+ * Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
6
+ * Better rank ordering method for 4D by Stefan Gustavson in 2012.
7
+ *
8
+ * This could be speeded up even further, but it's useful as it is.
9
+ *
10
+ * Version 2012-03-09
11
+ *
12
+ * This code was placed in the public domain by its original author,
13
+ * Stefan Gustavson. You may use it as you see fit, but
14
+ * attribution is appreciated.
15
+ *
16
+ */
17
+
18
+ package monkstone.noise;
19
+
20
+ public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
21
+
22
+ private static Grad grad3[] = {new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0),
23
+ new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1),
24
+ new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)};
25
+
26
+ private static Grad grad4[] = {new Grad(0, 1, 1, 1), new Grad(0, 1, 1, -1), new Grad(0, 1, -1, 1), new Grad(0, 1, -1, -1),
27
+ new Grad(0, -1, 1, 1), new Grad(0, -1, 1, -1), new Grad(0, -1, -1, 1), new Grad(0, -1, -1, -1),
28
+ new Grad(1, 0, 1, 1), new Grad(1, 0, 1, -1), new Grad(1, 0, -1, 1), new Grad(1, 0, -1, -1),
29
+ new Grad(-1, 0, 1, 1), new Grad(-1, 0, 1, -1), new Grad(-1, 0, -1, 1), new Grad(-1, 0, -1, -1),
30
+ new Grad(1, 1, 0, 1), new Grad(1, 1, 0, -1), new Grad(1, -1, 0, 1), new Grad(1, -1, 0, -1),
31
+ new Grad(-1, 1, 0, 1), new Grad(-1, 1, 0, -1), new Grad(-1, -1, 0, 1), new Grad(-1, -1, 0, -1),
32
+ new Grad(1, 1, 1, 0), new Grad(1, 1, -1, 0), new Grad(1, -1, 1, 0), new Grad(1, -1, -1, 0),
33
+ new Grad(-1, 1, 1, 0), new Grad(-1, 1, -1, 0), new Grad(-1, -1, 1, 0), new Grad(-1, -1, -1, 0)};
34
+
35
+ private static short p[] = {151, 160, 137, 91, 90, 15,
36
+ 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
37
+ 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
38
+ 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
39
+ 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
40
+ 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
41
+ 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123,
42
+ 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
43
+ 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
44
+ 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
45
+ 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
46
+ 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
47
+ 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
48
+ // To remove the need for index wrapping, double the permutation table length
49
+ static short[] PERM = new short[512];
50
+ static short[] PERM_MOD_12 = new short[512];
51
+
52
+ static {
53
+ for (int i = 0; i < 512; i++) {
54
+ PERM[i] = p[i & 255];
55
+ PERM_MOD_12[i] = (short) (PERM[i] % 12);
56
+ }
57
+ }
58
+
59
+ // Skewing and unskewing factors for 2, 3, and 4 dimensions
60
+ private static final double F2 = 0.5 * (Math.sqrt(3.0) - 1.0);
61
+ private static final double G2 = (3.0 - Math.sqrt(3.0)) / 6.0;
62
+ private static final double F3 = 1.0 / 3.0;
63
+ private static final double G3 = 1.0 / 6.0;
64
+ private static final double F4 = (Math.sqrt(5.0) - 1.0) / 4.0;
65
+ private static final double G4 = (5.0 - Math.sqrt(5.0)) / 20.0;
66
+
67
+ // This method is a *lot* faster than using (int)Math.floor(x)
68
+ private static int fastfloor(double x) {
69
+ int xi = (int) x;
70
+ return x < xi ? xi - 1 : xi;
71
+ }
72
+
73
+ private static double dot(Grad g, double x, double y) {
74
+ return g.x * x + g.y * y;
75
+ }
76
+
77
+ private static double dot(Grad g, double x, double y, double z) {
78
+ return g.x * x + g.y * y + g.z * z;
79
+ }
80
+
81
+ private static double dot(Grad g, double x, double y, double z, double w) {
82
+ return g.x * x + g.y * y + g.z * z + g.w * w;
83
+ }
84
+
85
+ // 2D simplex noise
86
+ public static double noise(double xin, double yin) {
87
+ double n0, n1, n2; // Noise contributions from the three corners
88
+ // Skew the input space to determine which simplex cell we're in
89
+ double s = (xin + yin) * F2; // Hairy factor for 2D
90
+ int i = fastfloor(xin + s);
91
+ int j = fastfloor(yin + s);
92
+ double t = (i + j) * G2;
93
+ double X0 = i - t; // Unskew the cell origin back to (x,y) space
94
+ double Y0 = j - t;
95
+ double x0 = xin - X0; // The x,y distances from the cell origin
96
+ double y0 = yin - Y0;
97
+ // For the 2D case, the simplex shape is an equilateral triangle.
98
+ // Determine which simplex we are in.
99
+ int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
100
+ if (x0 > y0) {
101
+ i1 = 1;
102
+ j1 = 0;
103
+ } // lower triangle, XY order: (0,0)->(1,0)->(1,1)
104
+ else {
105
+ i1 = 0;
106
+ j1 = 1;
107
+ } // upper triangle, YX order: (0,0)->(0,1)->(1,1)
108
+ // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
109
+ // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
110
+ // c = (3-sqrt(3))/6
111
+ double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
112
+ double y1 = y0 - j1 + G2;
113
+ double x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords
114
+ double y2 = y0 - 1.0 + 2.0 * G2;
115
+ // Work out the hashed gradient indices of the three simplex corners
116
+ int ii = i & 255;
117
+ int jj = j & 255;
118
+ int gi0 = PERM_MOD_12[ii + PERM[jj]];
119
+ int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1]];
120
+ int gi2 = PERM_MOD_12[ii + 1 + PERM[jj + 1]];
121
+ // Calculate the contribution from the three corners
122
+ double t0 = 0.5 - x0 * x0 - y0 * y0;
123
+ if (t0 < 0) {
124
+ n0 = 0.0;
125
+ } else {
126
+ t0 *= t0;
127
+ n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
128
+ }
129
+ double t1 = 0.5 - x1 * x1 - y1 * y1;
130
+ if (t1 < 0) {
131
+ n1 = 0.0;
132
+ } else {
133
+ t1 *= t1;
134
+ n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
135
+ }
136
+ double t2 = 0.5 - x2 * x2 - y2 * y2;
137
+ if (t2 < 0) {
138
+ n2 = 0.0;
139
+ } else {
140
+ t2 *= t2;
141
+ n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
142
+ }
143
+ // Add contributions from each corner to get the final noise value.
144
+ // The result is scaled to return values in the interval [-1,1].
145
+ return 70.0 * (n0 + n1 + n2);
146
+ }
147
+
148
+ // 3D simplex noise
149
+ public static double noise(double xin, double yin, double zin) {
150
+ double n0, n1, n2, n3; // Noise contributions from the four corners
151
+ // Skew the input space to determine which simplex cell we're in
152
+ double s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D
153
+ int i = fastfloor(xin + s);
154
+ int j = fastfloor(yin + s);
155
+ int k = fastfloor(zin + s);
156
+ double t = (i + j + k) * G3;
157
+ double X0 = i - t; // Unskew the cell origin back to (x,y,z) space
158
+ double Y0 = j - t;
159
+ double Z0 = k - t;
160
+ double x0 = xin - X0; // The x,y,z distances from the cell origin
161
+ double y0 = yin - Y0;
162
+ double z0 = zin - Z0;
163
+ // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
164
+ // Determine which simplex we are in.
165
+ int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
166
+ int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
167
+ if (x0 >= y0) {
168
+ if (y0 >= z0) {
169
+ i1 = 1;
170
+ j1 = 0;
171
+ k1 = 0;
172
+ i2 = 1;
173
+ j2 = 1;
174
+ k2 = 0;
175
+ } // X Y Z order
176
+ else if (x0 >= z0) {
177
+ i1 = 1;
178
+ j1 = 0;
179
+ k1 = 0;
180
+ i2 = 1;
181
+ j2 = 0;
182
+ k2 = 1;
183
+ } // X Z Y order
184
+ else {
185
+ i1 = 0;
186
+ j1 = 0;
187
+ k1 = 1;
188
+ i2 = 1;
189
+ j2 = 0;
190
+ k2 = 1;
191
+ } // Z X Y order
192
+ } else { // x0<y0
193
+ if (y0 < z0) {
194
+ i1 = 0;
195
+ j1 = 0;
196
+ k1 = 1;
197
+ i2 = 0;
198
+ j2 = 1;
199
+ k2 = 1;
200
+ } // Z Y X order
201
+ else if (x0 < z0) {
202
+ i1 = 0;
203
+ j1 = 1;
204
+ k1 = 0;
205
+ i2 = 0;
206
+ j2 = 1;
207
+ k2 = 1;
208
+ } // Y Z X order
209
+ else {
210
+ i1 = 0;
211
+ j1 = 1;
212
+ k1 = 0;
213
+ i2 = 1;
214
+ j2 = 1;
215
+ k2 = 0;
216
+ } // Y X Z order
217
+ }
218
+ // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
219
+ // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
220
+ // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
221
+ // c = 1/6.
222
+ double x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
223
+ double y1 = y0 - j1 + G3;
224
+ double z1 = z0 - k1 + G3;
225
+ double x2 = x0 - i2 + 2.0 * G3; // Offsets for third corner in (x,y,z) coords
226
+ double y2 = y0 - j2 + 2.0 * G3;
227
+ double z2 = z0 - k2 + 2.0 * G3;
228
+ double x3 = x0 - 1.0 + 3.0 * G3; // Offsets for last corner in (x,y,z) coords
229
+ double y3 = y0 - 1.0 + 3.0 * G3;
230
+ double z3 = z0 - 1.0 + 3.0 * G3;
231
+ // Work out the hashed gradient indices of the four simplex corners
232
+ int ii = i & 255;
233
+ int jj = j & 255;
234
+ int kk = k & 255;
235
+ int gi0 = PERM_MOD_12[ii + PERM[jj + PERM[kk]]];
236
+ int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1 + PERM[kk + k1]]];
237
+ int gi2 = PERM_MOD_12[ii + i2 + PERM[jj + j2 + PERM[kk + k2]]];
238
+ int gi3 = PERM_MOD_12[ii + 1 + PERM[jj + 1 + PERM[kk + 1]]];
239
+ // Calculate the contribution from the four corners
240
+ double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;
241
+ if (t0 < 0) {
242
+ n0 = 0.0;
243
+ } else {
244
+ t0 *= t0;
245
+ n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
246
+ }
247
+ double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;
248
+ if (t1 < 0) {
249
+ n1 = 0.0;
250
+ } else {
251
+ t1 *= t1;
252
+ n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
253
+ }
254
+ double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;
255
+ if (t2 < 0) {
256
+ n2 = 0.0;
257
+ } else {
258
+ t2 *= t2;
259
+ n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
260
+ }
261
+ double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;
262
+ if (t3 < 0) {
263
+ n3 = 0.0;
264
+ } else {
265
+ t3 *= t3;
266
+ n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
267
+ }
268
+ // Add contributions from each corner to get the final noise value.
269
+ // The result is scaled to stay just inside [-1,1]
270
+ return 32.0 * (n0 + n1 + n2 + n3);
271
+ }
272
+
273
+ // 4D simplex noise, better simplex rank ordering method 2012-03-09
274
+ public static double noise(double x, double y, double z, double w) {
275
+
276
+ double n0, n1, n2, n3, n4; // Noise contributions from the five corners
277
+ // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
278
+ double s = (x + y + z + w) * F4; // Factor for 4D skewing
279
+ int i = fastfloor(x + s);
280
+ int j = fastfloor(y + s);
281
+ int k = fastfloor(z + s);
282
+ int l = fastfloor(w + s);
283
+ double t = (i + j + k + l) * G4; // Factor for 4D unskewing
284
+ double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
285
+ double Y0 = j - t;
286
+ double Z0 = k - t;
287
+ double W0 = l - t;
288
+ double x0 = x - X0; // The x,y,z,w distances from the cell origin
289
+ double y0 = y - Y0;
290
+ double z0 = z - Z0;
291
+ double w0 = w - W0;
292
+ // For the 4D case, the simplex is a 4D shape I won't even try to describe.
293
+ // To find out which of the 24 possible simplices we're in, we need to
294
+ // determine the magnitude ordering of x0, y0, z0 and w0.
295
+ // Six pair-wise comparisons are performed between each possible pair
296
+ // of the four coordinates, and the results are used to rank the numbers.
297
+ int rankx = 0;
298
+ int ranky = 0;
299
+ int rankz = 0;
300
+ int rankw = 0;
301
+ if (x0 > y0) {
302
+ rankx++;
303
+ } else {
304
+ ranky++;
305
+ }
306
+ if (x0 > z0) {
307
+ rankx++;
308
+ } else {
309
+ rankz++;
310
+ }
311
+ if (x0 > w0) {
312
+ rankx++;
313
+ } else {
314
+ rankw++;
315
+ }
316
+ if (y0 > z0) {
317
+ ranky++;
318
+ } else {
319
+ rankz++;
320
+ }
321
+ if (y0 > w0) {
322
+ ranky++;
323
+ } else {
324
+ rankw++;
325
+ }
326
+ if (z0 > w0) {
327
+ rankz++;
328
+ } else {
329
+ rankw++;
330
+ }
331
+ int i1, j1, k1, l1; // The integer offsets for the second simplex corner
332
+ int i2, j2, k2, l2; // The integer offsets for the third simplex corner
333
+ int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
334
+ // [rankx, ranky, rankz, rankw] is a 4-vector with the numbers 0, 1, 2 and 3
335
+ // in some order. We use a thresholding to set the coordinates in turn.
336
+ // Rank 3 denotes the largest coordinate.
337
+ i1 = rankx >= 3 ? 1 : 0;
338
+ j1 = ranky >= 3 ? 1 : 0;
339
+ k1 = rankz >= 3 ? 1 : 0;
340
+ l1 = rankw >= 3 ? 1 : 0;
341
+ // Rank 2 denotes the second largest coordinate.
342
+ i2 = rankx >= 2 ? 1 : 0;
343
+ j2 = ranky >= 2 ? 1 : 0;
344
+ k2 = rankz >= 2 ? 1 : 0;
345
+ l2 = rankw >= 2 ? 1 : 0;
346
+ // Rank 1 denotes the second smallest coordinate.
347
+ i3 = rankx >= 1 ? 1 : 0;
348
+ j3 = ranky >= 1 ? 1 : 0;
349
+ k3 = rankz >= 1 ? 1 : 0;
350
+ l3 = rankw >= 1 ? 1 : 0;
351
+ // The fifth corner has all coordinate offsets = 1, so no need to compute that.
352
+ double x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
353
+ double y1 = y0 - j1 + G4;
354
+ double z1 = z0 - k1 + G4;
355
+ double w1 = w0 - l1 + G4;
356
+ double x2 = x0 - i2 + 2.0 * G4; // Offsets for third corner in (x,y,z,w) coords
357
+ double y2 = y0 - j2 + 2.0 * G4;
358
+ double z2 = z0 - k2 + 2.0 * G4;
359
+ double w2 = w0 - l2 + 2.0 * G4;
360
+ double x3 = x0 - i3 + 3.0 * G4; // Offsets for fourth corner in (x,y,z,w) coords
361
+ double y3 = y0 - j3 + 3.0 * G4;
362
+ double z3 = z0 - k3 + 3.0 * G4;
363
+ double w3 = w0 - l3 + 3.0 * G4;
364
+ double x4 = x0 - 1.0 + 4.0 * G4; // Offsets for last corner in (x,y,z,w) coords
365
+ double y4 = y0 - 1.0 + 4.0 * G4;
366
+ double z4 = z0 - 1.0 + 4.0 * G4;
367
+ double w4 = w0 - 1.0 + 4.0 * G4;
368
+ // Work out the hashed gradient indices of the five simplex corners
369
+ int ii = i & 255;
370
+ int jj = j & 255;
371
+ int kk = k & 255;
372
+ int ll = l & 255;
373
+ int gi0 = PERM[ii + PERM[jj + PERM[kk + PERM[ll]]]] % 32;
374
+ int gi1 = PERM[ii + i1 + PERM[jj + j1 + PERM[kk + k1 + PERM[ll + l1]]]] % 32;
375
+ int gi2 = PERM[ii + i2 + PERM[jj + j2 + PERM[kk + k2 + PERM[ll + l2]]]] % 32;
376
+ int gi3 = PERM[ii + i3 + PERM[jj + j3 + PERM[kk + k3 + PERM[ll + l3]]]] % 32;
377
+ int gi4 = PERM[ii + 1 + PERM[jj + 1 + PERM[kk + 1 + PERM[ll + 1]]]] % 32;
378
+ // Calculate the contribution from the five corners
379
+ double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
380
+ if (t0 < 0) {
381
+ n0 = 0.0;
382
+ } else {
383
+ t0 *= t0;
384
+ n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
385
+ }
386
+ double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
387
+ if (t1 < 0) {
388
+ n1 = 0.0;
389
+ } else {
390
+ t1 *= t1;
391
+ n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
392
+ }
393
+ double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
394
+ if (t2 < 0) {
395
+ n2 = 0.0;
396
+ } else {
397
+ t2 *= t2;
398
+ n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
399
+ }
400
+ double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
401
+ if (t3 < 0) {
402
+ n3 = 0.0;
403
+ } else {
404
+ t3 *= t3;
405
+ n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
406
+ }
407
+ double t4 = 0.5 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
408
+ if (t4 < 0) {
409
+ n4 = 0.0;
410
+ } else {
411
+ t4 *= t4;
412
+ n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
413
+ }
414
+ // Sum up and scale the result to cover the range [-1,1]
415
+ return 27.0 * (n0 + n1 + n2 + n3 + n4);
416
+ }
417
+
418
+ // Inner class to speed upp gradient computations
419
+ // (In Java, array access is a lot slower than member access)
420
+ private static class Grad {
421
+
422
+ double x, y, z, w;
423
+
424
+ Grad(double x, double y, double z) {
425
+ this.x = x;
426
+ this.y = y;
427
+ this.z = z;
428
+ }
429
+
430
+ Grad(double x, double y, double z, double w) {
431
+ this.x = x;
432
+ this.y = y;
433
+ this.z = z;
434
+ this.w = w;
435
+ }
436
+ }
437
+ }
@@ -0,0 +1,29 @@
1
+ gem 'minitest' # don't use bundled minitest
2
+ require 'java'
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+
6
+ require_relative '../lib/propane'
7
+
8
+ Java::Monkstone::PropaneLibrary.load(JRuby.runtime)
9
+
10
+ Dir.chdir(File.dirname(__FILE__))
11
+
12
+ class DeglutTest < Minitest::Test
13
+ attr_reader :to_radian
14
+
15
+ def setup
16
+ @to_radian = Math::PI / 180
17
+ end
18
+
19
+ def test_cos_sin
20
+ (-720..720).step(1) do |deg|
21
+ sine = DegLut.sin(deg)
22
+ deg_sin = Math.sin(deg * to_radian)
23
+ assert_in_delta(sine, deg_sin, delta = 0.000001)
24
+ cosine = DegLut.cos(deg)
25
+ deg_cos = Math.cos(deg * to_radian)
26
+ assert_in_delta(cosine, deg_cos, delta = 0.000001)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,79 @@
1
+ gem 'minitest' # don't use bundled minitest
2
+ require 'java'
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+
6
+ require_relative '../lib/propane'
7
+ # require_relative '../lib/jruby_art/helper_methods'
8
+
9
+ Java::Monkstone::PropaneLibrary.new.load(JRuby.runtime, false)
10
+
11
+ # include Processing::HelperMethods
12
+
13
+
14
+ Dir.chdir(File.dirname(__FILE__))
15
+
16
+ class MathToolTest < Minitest::Test
17
+ include MathTool
18
+ def test_map1d
19
+ x = [0, 5, 7.5, 10]
20
+ range1 = (0..10)
21
+ range2 = (100..1)
22
+ range3 = (0..10)
23
+ range4 = (5..105)
24
+ assert_in_delta(map1d(x[0], range1, range2), 100, delta = 0.00001, msg = 'map to first')
25
+ assert_in_delta(map1d(x[1], range1, range2), 50.5, delta = 0.00001, msg = 'map to reversed intermediate')
26
+ assert_in_delta(map1d(x[2], range3, range4), 80.0, delta = 0.00001, msg = 'map to intermediate')
27
+ assert_in_delta(map1d(x[3], range1, range2), 1, delta = 0.00001, msg = 'map to last')
28
+ end
29
+
30
+ def test_p5map # as map1d except not using range input
31
+ x = [0, 5, 7.5, 10]
32
+ range1 = (0..10)
33
+ range2 = (100..1)
34
+ range3 = (0..10)
35
+ range4 = (5..105)
36
+ assert_in_delta(p5map(x[0], range1.first, range1.last, range2.first, range2.last), 100, delta = 0.00001)
37
+ assert_in_delta(p5map(x[1], range1.first, range1.last, range2.first, range2.last), 50.5, delta = 0.00001)
38
+ assert_in_delta(p5map(x[2], range3.first, range3.last, range4.first, range4.last), 80.0, delta = 0.00001)
39
+ assert_in_delta(p5map(x[3], range1.first, range1.last, range2.first, range2.last), 1, delta = 0.00001)
40
+ end
41
+
42
+ def test_norm
43
+ x = [10, 140, 210]
44
+ start0, last0 = 30, 200
45
+ start_int, last_int = 0, 200
46
+ assert_in_delta(norm(x[0], start0, last0), -0.11764705882352941, delta = 0.00001, msg = 'unclamped map')
47
+ assert_in_delta(norm(x[1], start_int, last_int), 0.7, delta = 0.00001, msg = 'map to intermediate')
48
+ assert_in_delta(norm(x[2], start_int, last_int), 1.05, delta = 0.00001, msg = 'unclamped map')
49
+ end
50
+
51
+ def test_norm_strict
52
+ x = [10, 140, 210]
53
+ assert_in_delta(norm_strict(x[2], x[0], x[1]), 1.0, delta = 0.00001, msg = 'clamped map to 0..1.0')
54
+ assert_in_delta(norm_strict(x[2], x[1], x[0]), 0.0, delta = 0.00001, msg = 'clamped map to 0..1.0')
55
+ assert_in_delta(norm_strict(x[1], x[0], x[2]), 0.65, delta = 0.00001, msg = 'clamped map to 0..1.0')
56
+ end
57
+
58
+ def test_lerp # behaviour is deliberately different to processing which is unclamped
59
+ x = [0.5, 0.8, 2.0]
60
+ start0, last0 = 300, 200
61
+ start_int, last_int = 0, 200
62
+ assert_in_delta(lerp(start0, last0, x[0]), 250, delta = 0.00001, msg = 'produces a intermediate value of a reversed range')
63
+ assert_in_delta(lerp(start_int, last_int, x[1]), 160, delta = 0.00001, msg = 'lerps to an intermediate value')
64
+ assert_in_delta(lerp(start_int, last_int, x[2]), 200, delta = 0.00001, msg = 'lerps to the last value of a range')
65
+ end
66
+
67
+ def test_constrain
68
+ x_int = [15, 2_500, -2_500]
69
+ start_int, last_int = 0, 200
70
+ assert_in_delta(constrain(x_int[0], start_int, last_int), 15, delta = 0.00001)
71
+ assert_in_delta(constrain(x_int[1], start_int, last_int), 200, delta = 0.00001)
72
+ assert_in_delta(constrain(x_int[2], start_int, last_int), 0, delta = 0.00001)
73
+ xf = [15.0, 2_500.0, -2_500.0]
74
+ startf, lastf = 0, 200.0
75
+ assert_in_delta(constrain(xf[0], startf, lastf), 15.0, delta = 0.00001, msg = 'constrain to 0..200')
76
+ assert_in_delta(constrain(xf[1], startf, lastf), 200.0, delta = 0.00001, msg = 'constrain to 0..200')
77
+ assert_in_delta(constrain(xf[2], startf, lastf), 0.0, delta = 0.00001, msg = 'constrain to 0..200')
78
+ end
79
+ end
@@ -9,7 +9,7 @@ SOUND = 'sound.zip'.freeze
9
9
  SOUND_VERSION = 'v1.3.2' # version 1.3.2
10
10
  VIDEO = 'video-2.zip'
11
11
  VIDEO_VERSION = '2' # version 1.0.1
12
- EXAMPLES = '0.3'.freeze
12
+ EXAMPLES = '0.4'.freeze
13
13
  HOME_DIR = ENV['HOME']
14
14
  MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propane
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: java
6
6
  authors:
7
7
  - monkstone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: arcball
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.3
27
- description: A Standalone Ruby Processing implementation
27
+ description: A batteries included version of processing in ruby
28
28
  email:
29
29
  - mamba2928@yahoo.co.uk
30
30
  executables:
@@ -67,6 +67,7 @@ files:
67
67
  - library/control_panel/control_panel.rb
68
68
  - library/file_chooser/chooser.rb
69
69
  - library/file_chooser/file_chooser.rb
70
+ - library/simplex_noise/simplex_noise.rb
70
71
  - library/slider/slider.rb
71
72
  - library/video_event/video_event.rb
72
73
  - pom.rb
@@ -79,6 +80,7 @@ files:
79
80
  - src/monkstone/fastmath/Deglut.java
80
81
  - src/monkstone/fastmath/package-info.java
81
82
  - src/monkstone/filechooser/Chooser.java
83
+ - src/monkstone/noise/SimplexNoise.java
82
84
  - src/monkstone/slider/CustomHorizontalSlider.java
83
85
  - src/monkstone/slider/CustomVerticalSlider.java
84
86
  - src/monkstone/slider/SimpleHorizontalSlider.java
@@ -99,6 +101,8 @@ files:
99
101
  - src/monkstone/videoevent/VideoInterface.java
100
102
  - src/monkstone/videoevent/package-info.java
101
103
  - test/create_test.rb
104
+ - test/deglut_spec_test.rb
105
+ - test/math_tool_test.rb
102
106
  - test/respond_to_test.rb
103
107
  - vendors/Rakefile
104
108
  homepage: https://ruby-processing.github.io/propane/
@@ -125,7 +129,9 @@ rubyforge_project:
125
129
  rubygems_version: 2.6.3
126
130
  signing_key:
127
131
  specification_version: 4
128
- summary: A really slim layer between Ruby and Processing-3.2.1.
132
+ summary: A jruby wrapper for processing-3.2.1
129
133
  test_files:
130
134
  - test/create_test.rb
135
+ - test/deglut_spec_test.rb
136
+ - test/math_tool_test.rb
131
137
  - test/respond_to_test.rb