picrate 0.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.mvn/extensions.xml +9 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +165 -0
- data/README.md +51 -0
- data/Rakefile +59 -0
- data/bin/picrate +8 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +30 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +16 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2018-05-06-getting_started.md +8 -0
- data/docs/_posts/2018-05-06-install_jruby.md +35 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +10 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/lib/picrate.rb +10 -0
- data/lib/picrate/app.rb +187 -0
- data/lib/picrate/creators/sketch_class.rb +57 -0
- data/lib/picrate/creators/sketch_factory.rb +12 -0
- data/lib/picrate/creators/sketch_writer.rb +21 -0
- data/lib/picrate/helper_methods.rb +214 -0
- data/lib/picrate/helpers/numeric.rb +9 -0
- data/lib/picrate/library.rb +69 -0
- data/lib/picrate/library_loader.rb +53 -0
- data/lib/picrate/native_folder.rb +35 -0
- data/lib/picrate/native_loader.rb +27 -0
- data/lib/picrate/runner.rb +81 -0
- data/lib/picrate/version.rb +4 -0
- data/library/boids/boids.rb +209 -0
- data/library/chooser/chooser.rb +19 -0
- data/library/control_panel/control_panel.rb +182 -0
- data/library/library_proxy/README.md +99 -0
- data/library/library_proxy/library_proxy.rb +14 -0
- data/library/slider/slider.rb +42 -0
- data/library/vector_utils/vector_utils.rb +69 -0
- data/library/video_event/video_event.rb +3 -0
- data/license.txt +508 -0
- data/picrate.gemspec +35 -0
- data/pom.rb +122 -0
- data/pom.xml +214 -0
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/ColorUtil.java +115 -0
- data/src/main/java/monkstone/MathToolModule.java +236 -0
- data/src/main/java/monkstone/PicrateLibrary.java +47 -0
- data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
- data/src/main/java/monkstone/fastmath/package-info.java +6 -0
- data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
- data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
- data/src/main/java/monkstone/slider/Slider.java +67 -0
- data/src/main/java/monkstone/slider/SliderBar.java +277 -0
- data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
- data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
- data/src/main/java/monkstone/vecmath/JRender.java +56 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/src/main/java/monkstone/vecmath/package-info.java +20 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/main/java/monkstone/videoevent/package-info.java +20 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
- data/src/main/java/processing/core/PApplet.java +17647 -0
- data/src/main/java/processing/core/PConstants.java +1033 -0
- data/src/main/java/processing/core/PFont.java +1250 -0
- data/src/main/java/processing/core/PGraphics.java +9614 -0
- data/src/main/java/processing/core/PImage.java +3608 -0
- data/src/main/java/processing/core/PMatrix.java +347 -0
- data/src/main/java/processing/core/PMatrix2D.java +694 -0
- data/src/main/java/processing/core/PMatrix3D.java +1153 -0
- data/src/main/java/processing/core/PShape.java +4332 -0
- data/src/main/java/processing/core/PShapeOBJ.java +544 -0
- data/src/main/java/processing/core/PShapeSVG.java +1987 -0
- data/src/main/java/processing/core/PStyle.java +208 -0
- data/src/main/java/processing/core/PSurface.java +242 -0
- data/src/main/java/processing/core/PSurfaceNone.java +479 -0
- data/src/main/java/processing/core/PVector.java +1140 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +108 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/test/create_test.rb +68 -0
- data/test/deglut_spec_test.rb +24 -0
- data/test/helper_methods_test.rb +58 -0
- data/test/math_tool_test.rb +75 -0
- data/test/respond_to_test.rb +215 -0
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/test/test_helper.rb +3 -0
- data/test/vecmath_spec_test.rb +522 -0
- data/vendors/Rakefile +127 -0
- metadata +289 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2018 Martin Prout
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 3.0 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
package monkstone.fastmath;
|
22
|
+
|
23
|
+
import org.jruby.Ruby;
|
24
|
+
import org.jruby.RubyInteger;
|
25
|
+
import org.jruby.RubyModule;
|
26
|
+
import org.jruby.anno.JRubyModule;
|
27
|
+
import org.jruby.anno.JRubyMethod;
|
28
|
+
import org.jruby.runtime.ThreadContext;
|
29
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
30
|
+
|
31
|
+
/**
|
32
|
+
*
|
33
|
+
*
|
34
|
+
*/
|
35
|
+
@JRubyModule(name = "DegLut")
|
36
|
+
public class Deglut {
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Lookup table for degree cosine/sine, has a fixed precision 1.0
|
40
|
+
* degrees Quite accurate but imprecise
|
41
|
+
*/
|
42
|
+
static final double[] SIN_DEG_LUT = new double[91];
|
43
|
+
/**
|
44
|
+
*
|
45
|
+
*/
|
46
|
+
public static final double TO_RADIANS = Math.PI / 180;
|
47
|
+
/**
|
48
|
+
*
|
49
|
+
*/
|
50
|
+
private static boolean initialized = false;
|
51
|
+
|
52
|
+
private final static int NINETY = 90;
|
53
|
+
private final static int FULL = 360;
|
54
|
+
private static final long serialVersionUID = -1466528933765940101L;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Initialize sin table with values (first quadrant only)
|
58
|
+
*/
|
59
|
+
public static final void initTable() {
|
60
|
+
if (initialized == false) {
|
61
|
+
for (int i = 0; i <= NINETY; i++) {
|
62
|
+
SIN_DEG_LUT[i] = Math.sin(TO_RADIANS * i);
|
63
|
+
}
|
64
|
+
initialized = true;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
*
|
70
|
+
* @param runtime Ruby
|
71
|
+
*/
|
72
|
+
|
73
|
+
public static void createDeglut(final Ruby runtime){
|
74
|
+
RubyModule deglutModule = runtime.defineModule("DegLut");
|
75
|
+
deglutModule.defineAnnotatedMethods(Deglut.class);
|
76
|
+
Deglut.initTable();
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
/**
|
81
|
+
*
|
82
|
+
* @param context ThreadContext
|
83
|
+
* @param recv IRubyObject
|
84
|
+
* @param other IRubyObject degrees
|
85
|
+
* @return sin IRubyObject
|
86
|
+
*/
|
87
|
+
@JRubyMethod(name = "sin", module = true)
|
88
|
+
|
89
|
+
public static IRubyObject sin(ThreadContext context, IRubyObject recv, IRubyObject other) {
|
90
|
+
int thet = (int) ((RubyInteger)other).getLongValue();
|
91
|
+
while (thet < 0) {
|
92
|
+
thet += FULL; // Needed because negative modulus plays badly in java
|
93
|
+
}
|
94
|
+
int theta = thet % FULL;
|
95
|
+
int y = theta % NINETY;
|
96
|
+
double result = (theta < NINETY) ? SIN_DEG_LUT[y] : (theta < 180)
|
97
|
+
? SIN_DEG_LUT[NINETY - y] : (theta < 270)
|
98
|
+
? -SIN_DEG_LUT[y] : -SIN_DEG_LUT[NINETY - y];
|
99
|
+
return context.runtime.newFloat(result);
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
*
|
104
|
+
* @param context ThreadContext
|
105
|
+
* @param recv IRubyObject
|
106
|
+
* @param other IRubyObject degrees
|
107
|
+
* @return cos IRubyObject
|
108
|
+
*/
|
109
|
+
@JRubyMethod(name = "cos", module = true)
|
110
|
+
public static IRubyObject cos(ThreadContext context, IRubyObject recv, IRubyObject other) {
|
111
|
+
int thet = (int) ((RubyInteger)other).getLongValue();
|
112
|
+
while (thet < 0) {
|
113
|
+
thet += FULL; // Needed because negative modulus plays badly in java
|
114
|
+
}
|
115
|
+
int theta = thet % FULL;
|
116
|
+
int y = theta % NINETY;
|
117
|
+
double result = (theta < NINETY) ? SIN_DEG_LUT[NINETY - y] : (theta < 180)
|
118
|
+
? -SIN_DEG_LUT[y] : (theta < 270)
|
119
|
+
? -SIN_DEG_LUT[NINETY - y] : SIN_DEG_LUT[y];
|
120
|
+
return context.runtime.newFloat(result);
|
121
|
+
}
|
122
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-18 Martin Prout
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 3.0 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
package monkstone.filechooser;
|
21
|
+
|
22
|
+
import java.io.File;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* This interface makes it easier/possible to use the reflection methods
|
26
|
+
* selectInput
|
27
|
+
* def setup
|
28
|
+
* java_signature 'void selectInput(String, String)'
|
29
|
+
* selectInput('Select a file to process:', 'fileSelected')
|
30
|
+
* end
|
31
|
+
*
|
32
|
+
* def file_selected(selection)
|
33
|
+
* if selection.nil?
|
34
|
+
* puts 'Window was closed or the user hit cancel.'
|
35
|
+
* else
|
36
|
+
* puts format('User selected %s', selection.get_absolute_path)
|
37
|
+
* end
|
38
|
+
* end
|
39
|
+
*
|
40
|
+
*/
|
41
|
+
public interface Chooser {
|
42
|
+
|
43
|
+
/**
|
44
|
+
*
|
45
|
+
* @param selection
|
46
|
+
*/
|
47
|
+
public void file_selected(File selection);
|
48
|
+
}
|
@@ -0,0 +1,465 @@
|
|
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
|
+
/**
|
21
|
+
*
|
22
|
+
* @author tux
|
23
|
+
*/
|
24
|
+
public class SimplexNoise { // Simplex noise in 2D, 3D and 4D
|
25
|
+
|
26
|
+
private static Grad grad3[] = {new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0),
|
27
|
+
new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1),
|
28
|
+
new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)};
|
29
|
+
|
30
|
+
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),
|
31
|
+
new Grad(0, -1, 1, 1), new Grad(0, -1, 1, -1), new Grad(0, -1, -1, 1), new Grad(0, -1, -1, -1),
|
32
|
+
new Grad(1, 0, 1, 1), new Grad(1, 0, 1, -1), new Grad(1, 0, -1, 1), new Grad(1, 0, -1, -1),
|
33
|
+
new Grad(-1, 0, 1, 1), new Grad(-1, 0, 1, -1), new Grad(-1, 0, -1, 1), new Grad(-1, 0, -1, -1),
|
34
|
+
new Grad(1, 1, 0, 1), new Grad(1, 1, 0, -1), new Grad(1, -1, 0, 1), new Grad(1, -1, 0, -1),
|
35
|
+
new Grad(-1, 1, 0, 1), new Grad(-1, 1, 0, -1), new Grad(-1, -1, 0, 1), new Grad(-1, -1, 0, -1),
|
36
|
+
new Grad(1, 1, 1, 0), new Grad(1, 1, -1, 0), new Grad(1, -1, 1, 0), new Grad(1, -1, -1, 0),
|
37
|
+
new Grad(-1, 1, 1, 0), new Grad(-1, 1, -1, 0), new Grad(-1, -1, 1, 0), new Grad(-1, -1, -1, 0)};
|
38
|
+
|
39
|
+
private static short p[] = {151, 160, 137, 91, 90, 15,
|
40
|
+
131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
|
41
|
+
190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
|
42
|
+
88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
|
43
|
+
77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
|
44
|
+
102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
|
45
|
+
135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123,
|
46
|
+
5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
|
47
|
+
223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
|
48
|
+
129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
|
49
|
+
251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
|
50
|
+
49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
|
51
|
+
138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
|
52
|
+
// To remove the need for index wrapping, double the permutation table length
|
53
|
+
static short[] PERM = new short[512];
|
54
|
+
static short[] PERM_MOD_12 = new short[512];
|
55
|
+
|
56
|
+
static {
|
57
|
+
for (int i = 0; i < 512; i++) {
|
58
|
+
PERM[i] = p[i & 255];
|
59
|
+
PERM_MOD_12[i] = (short) (PERM[i] % 12);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
// Skewing and unskewing factors for 2, 3, and 4 dimensions
|
64
|
+
private static final double F2 = 0.5 * (Math.sqrt(3.0) - 1.0);
|
65
|
+
private static final double G2 = (3.0 - Math.sqrt(3.0)) / 6.0;
|
66
|
+
private static final double F3 = 1.0 / 3.0;
|
67
|
+
private static final double G3 = 1.0 / 6.0;
|
68
|
+
private static final double F4 = (Math.sqrt(5.0) - 1.0) / 4.0;
|
69
|
+
private static final double G4 = (5.0 - Math.sqrt(5.0)) / 20.0;
|
70
|
+
|
71
|
+
// This method is a *lot* faster than using (int)Math.floor(x)
|
72
|
+
private static int fastfloor(double x) {
|
73
|
+
int xi = (int) x;
|
74
|
+
return x < xi ? xi - 1 : xi;
|
75
|
+
}
|
76
|
+
|
77
|
+
private static double dot(Grad g, double x, double y) {
|
78
|
+
return g.x * x + g.y * y;
|
79
|
+
}
|
80
|
+
|
81
|
+
private static double dot(Grad g, double x, double y, double z) {
|
82
|
+
return g.x * x + g.y * y + g.z * z;
|
83
|
+
}
|
84
|
+
|
85
|
+
private static double dot(Grad g, double x, double y, double z, double w) {
|
86
|
+
return g.x * x + g.y * y + g.z * z + g.w * w;
|
87
|
+
}
|
88
|
+
|
89
|
+
// 2D simplex noise
|
90
|
+
|
91
|
+
/**
|
92
|
+
*
|
93
|
+
* @param xin
|
94
|
+
* @param yin
|
95
|
+
* @return
|
96
|
+
*/
|
97
|
+
public static double noise(double xin, double yin) {
|
98
|
+
double n0, n1, n2; // Noise contributions from the three corners
|
99
|
+
// Skew the input space to determine which simplex cell we're in
|
100
|
+
double s = (xin + yin) * F2; // Hairy factor for 2D
|
101
|
+
int i = fastfloor(xin + s);
|
102
|
+
int j = fastfloor(yin + s);
|
103
|
+
double t = (i + j) * G2;
|
104
|
+
double X0 = i - t; // Unskew the cell origin back to (x,y) space
|
105
|
+
double Y0 = j - t;
|
106
|
+
double x0 = xin - X0; // The x,y distances from the cell origin
|
107
|
+
double y0 = yin - Y0;
|
108
|
+
// For the 2D case, the simplex shape is an equilateral triangle.
|
109
|
+
// Determine which simplex we are in.
|
110
|
+
int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
|
111
|
+
if (x0 > y0) {
|
112
|
+
i1 = 1;
|
113
|
+
j1 = 0;
|
114
|
+
} // lower triangle, XY order: (0,0)->(1,0)->(1,1)
|
115
|
+
else {
|
116
|
+
i1 = 0;
|
117
|
+
j1 = 1;
|
118
|
+
} // upper triangle, YX order: (0,0)->(0,1)->(1,1)
|
119
|
+
// A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
|
120
|
+
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
|
121
|
+
// c = (3-sqrt(3))/6
|
122
|
+
double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
|
123
|
+
double y1 = y0 - j1 + G2;
|
124
|
+
double x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords
|
125
|
+
double y2 = y0 - 1.0 + 2.0 * G2;
|
126
|
+
// Work out the hashed gradient indices of the three simplex corners
|
127
|
+
int ii = i & 255;
|
128
|
+
int jj = j & 255;
|
129
|
+
int gi0 = PERM_MOD_12[ii + PERM[jj]];
|
130
|
+
int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1]];
|
131
|
+
int gi2 = PERM_MOD_12[ii + 1 + PERM[jj + 1]];
|
132
|
+
// Calculate the contribution from the three corners
|
133
|
+
double t0 = 0.5 - x0 * x0 - y0 * y0;
|
134
|
+
if (t0 < 0) {
|
135
|
+
n0 = 0.0;
|
136
|
+
} else {
|
137
|
+
t0 *= t0;
|
138
|
+
n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
|
139
|
+
}
|
140
|
+
double t1 = 0.5 - x1 * x1 - y1 * y1;
|
141
|
+
if (t1 < 0) {
|
142
|
+
n1 = 0.0;
|
143
|
+
} else {
|
144
|
+
t1 *= t1;
|
145
|
+
n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
|
146
|
+
}
|
147
|
+
double t2 = 0.5 - x2 * x2 - y2 * y2;
|
148
|
+
if (t2 < 0) {
|
149
|
+
n2 = 0.0;
|
150
|
+
} else {
|
151
|
+
t2 *= t2;
|
152
|
+
n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
|
153
|
+
}
|
154
|
+
// Add contributions from each corner to get the final noise value.
|
155
|
+
// The result is scaled to return values in the interval [-1,1].
|
156
|
+
return 70.0 * (n0 + n1 + n2);
|
157
|
+
}
|
158
|
+
|
159
|
+
// 3D simplex noise
|
160
|
+
|
161
|
+
/**
|
162
|
+
*
|
163
|
+
* @param xin
|
164
|
+
* @param yin
|
165
|
+
* @param zin
|
166
|
+
* @return
|
167
|
+
*/
|
168
|
+
public static double noise(double xin, double yin, double zin) {
|
169
|
+
double n0, n1, n2, n3; // Noise contributions from the four corners
|
170
|
+
// Skew the input space to determine which simplex cell we're in
|
171
|
+
double s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D
|
172
|
+
int i = fastfloor(xin + s);
|
173
|
+
int j = fastfloor(yin + s);
|
174
|
+
int k = fastfloor(zin + s);
|
175
|
+
double t = (i + j + k) * G3;
|
176
|
+
double X0 = i - t; // Unskew the cell origin back to (x,y,z) space
|
177
|
+
double Y0 = j - t;
|
178
|
+
double Z0 = k - t;
|
179
|
+
double x0 = xin - X0; // The x,y,z distances from the cell origin
|
180
|
+
double y0 = yin - Y0;
|
181
|
+
double z0 = zin - Z0;
|
182
|
+
// For the 3D case, the simplex shape is a slightly irregular tetrahedron.
|
183
|
+
// Determine which simplex we are in.
|
184
|
+
int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
|
185
|
+
int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
|
186
|
+
if (x0 >= y0) {
|
187
|
+
if (y0 >= z0) {
|
188
|
+
i1 = 1;
|
189
|
+
j1 = 0;
|
190
|
+
k1 = 0;
|
191
|
+
i2 = 1;
|
192
|
+
j2 = 1;
|
193
|
+
k2 = 0;
|
194
|
+
} // X Y Z order
|
195
|
+
else if (x0 >= z0) {
|
196
|
+
i1 = 1;
|
197
|
+
j1 = 0;
|
198
|
+
k1 = 0;
|
199
|
+
i2 = 1;
|
200
|
+
j2 = 0;
|
201
|
+
k2 = 1;
|
202
|
+
} // X Z Y order
|
203
|
+
else {
|
204
|
+
i1 = 0;
|
205
|
+
j1 = 0;
|
206
|
+
k1 = 1;
|
207
|
+
i2 = 1;
|
208
|
+
j2 = 0;
|
209
|
+
k2 = 1;
|
210
|
+
} // Z X Y order
|
211
|
+
} else { // x0<y0
|
212
|
+
if (y0 < z0) {
|
213
|
+
i1 = 0;
|
214
|
+
j1 = 0;
|
215
|
+
k1 = 1;
|
216
|
+
i2 = 0;
|
217
|
+
j2 = 1;
|
218
|
+
k2 = 1;
|
219
|
+
} // Z Y X order
|
220
|
+
else if (x0 < z0) {
|
221
|
+
i1 = 0;
|
222
|
+
j1 = 1;
|
223
|
+
k1 = 0;
|
224
|
+
i2 = 0;
|
225
|
+
j2 = 1;
|
226
|
+
k2 = 1;
|
227
|
+
} // Y Z X order
|
228
|
+
else {
|
229
|
+
i1 = 0;
|
230
|
+
j1 = 1;
|
231
|
+
k1 = 0;
|
232
|
+
i2 = 1;
|
233
|
+
j2 = 1;
|
234
|
+
k2 = 0;
|
235
|
+
} // Y X Z order
|
236
|
+
}
|
237
|
+
// A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
|
238
|
+
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
|
239
|
+
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
|
240
|
+
// c = 1/6.
|
241
|
+
double x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
|
242
|
+
double y1 = y0 - j1 + G3;
|
243
|
+
double z1 = z0 - k1 + G3;
|
244
|
+
double x2 = x0 - i2 + 2.0 * G3; // Offsets for third corner in (x,y,z) coords
|
245
|
+
double y2 = y0 - j2 + 2.0 * G3;
|
246
|
+
double z2 = z0 - k2 + 2.0 * G3;
|
247
|
+
double x3 = x0 - 1.0 + 3.0 * G3; // Offsets for last corner in (x,y,z) coords
|
248
|
+
double y3 = y0 - 1.0 + 3.0 * G3;
|
249
|
+
double z3 = z0 - 1.0 + 3.0 * G3;
|
250
|
+
// Work out the hashed gradient indices of the four simplex corners
|
251
|
+
int ii = i & 255;
|
252
|
+
int jj = j & 255;
|
253
|
+
int kk = k & 255;
|
254
|
+
int gi0 = PERM_MOD_12[ii + PERM[jj + PERM[kk]]];
|
255
|
+
int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1 + PERM[kk + k1]]];
|
256
|
+
int gi2 = PERM_MOD_12[ii + i2 + PERM[jj + j2 + PERM[kk + k2]]];
|
257
|
+
int gi3 = PERM_MOD_12[ii + 1 + PERM[jj + 1 + PERM[kk + 1]]];
|
258
|
+
// Calculate the contribution from the four corners
|
259
|
+
double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;
|
260
|
+
if (t0 < 0) {
|
261
|
+
n0 = 0.0;
|
262
|
+
} else {
|
263
|
+
t0 *= t0;
|
264
|
+
n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
|
265
|
+
}
|
266
|
+
double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;
|
267
|
+
if (t1 < 0) {
|
268
|
+
n1 = 0.0;
|
269
|
+
} else {
|
270
|
+
t1 *= t1;
|
271
|
+
n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
|
272
|
+
}
|
273
|
+
double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;
|
274
|
+
if (t2 < 0) {
|
275
|
+
n2 = 0.0;
|
276
|
+
} else {
|
277
|
+
t2 *= t2;
|
278
|
+
n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
|
279
|
+
}
|
280
|
+
double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;
|
281
|
+
if (t3 < 0) {
|
282
|
+
n3 = 0.0;
|
283
|
+
} else {
|
284
|
+
t3 *= t3;
|
285
|
+
n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
|
286
|
+
}
|
287
|
+
// Add contributions from each corner to get the final noise value.
|
288
|
+
// The result is scaled to stay just inside [-1,1]
|
289
|
+
return 32.0 * (n0 + n1 + n2 + n3);
|
290
|
+
}
|
291
|
+
|
292
|
+
// 4D simplex noise, better simplex rank ordering method 2012-03-09
|
293
|
+
|
294
|
+
/**
|
295
|
+
*
|
296
|
+
* @param x
|
297
|
+
* @param y
|
298
|
+
* @param z
|
299
|
+
* @param w
|
300
|
+
* @return
|
301
|
+
*/
|
302
|
+
public static double noise(double x, double y, double z, double w) {
|
303
|
+
|
304
|
+
double n0, n1, n2, n3, n4; // Noise contributions from the five corners
|
305
|
+
// Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
|
306
|
+
double s = (x + y + z + w) * F4; // Factor for 4D skewing
|
307
|
+
int i = fastfloor(x + s);
|
308
|
+
int j = fastfloor(y + s);
|
309
|
+
int k = fastfloor(z + s);
|
310
|
+
int l = fastfloor(w + s);
|
311
|
+
double t = (i + j + k + l) * G4; // Factor for 4D unskewing
|
312
|
+
double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
|
313
|
+
double Y0 = j - t;
|
314
|
+
double Z0 = k - t;
|
315
|
+
double W0 = l - t;
|
316
|
+
double x0 = x - X0; // The x,y,z,w distances from the cell origin
|
317
|
+
double y0 = y - Y0;
|
318
|
+
double z0 = z - Z0;
|
319
|
+
double w0 = w - W0;
|
320
|
+
// For the 4D case, the simplex is a 4D shape I won't even try to describe.
|
321
|
+
// To find out which of the 24 possible simplices we're in, we need to
|
322
|
+
// determine the magnitude ordering of x0, y0, z0 and w0.
|
323
|
+
// Six pair-wise comparisons are performed between each possible pair
|
324
|
+
// of the four coordinates, and the results are used to rank the numbers.
|
325
|
+
int rankx = 0;
|
326
|
+
int ranky = 0;
|
327
|
+
int rankz = 0;
|
328
|
+
int rankw = 0;
|
329
|
+
if (x0 > y0) {
|
330
|
+
rankx++;
|
331
|
+
} else {
|
332
|
+
ranky++;
|
333
|
+
}
|
334
|
+
if (x0 > z0) {
|
335
|
+
rankx++;
|
336
|
+
} else {
|
337
|
+
rankz++;
|
338
|
+
}
|
339
|
+
if (x0 > w0) {
|
340
|
+
rankx++;
|
341
|
+
} else {
|
342
|
+
rankw++;
|
343
|
+
}
|
344
|
+
if (y0 > z0) {
|
345
|
+
ranky++;
|
346
|
+
} else {
|
347
|
+
rankz++;
|
348
|
+
}
|
349
|
+
if (y0 > w0) {
|
350
|
+
ranky++;
|
351
|
+
} else {
|
352
|
+
rankw++;
|
353
|
+
}
|
354
|
+
if (z0 > w0) {
|
355
|
+
rankz++;
|
356
|
+
} else {
|
357
|
+
rankw++;
|
358
|
+
}
|
359
|
+
int i1, j1, k1, l1; // The integer offsets for the second simplex corner
|
360
|
+
int i2, j2, k2, l2; // The integer offsets for the third simplex corner
|
361
|
+
int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
|
362
|
+
// [rankx, ranky, rankz, rankw] is a 4-vector with the numbers 0, 1, 2 and 3
|
363
|
+
// in some order. We use a thresholding to set the coordinates in turn.
|
364
|
+
// Rank 3 denotes the largest coordinate.
|
365
|
+
i1 = rankx >= 3 ? 1 : 0;
|
366
|
+
j1 = ranky >= 3 ? 1 : 0;
|
367
|
+
k1 = rankz >= 3 ? 1 : 0;
|
368
|
+
l1 = rankw >= 3 ? 1 : 0;
|
369
|
+
// Rank 2 denotes the second largest coordinate.
|
370
|
+
i2 = rankx >= 2 ? 1 : 0;
|
371
|
+
j2 = ranky >= 2 ? 1 : 0;
|
372
|
+
k2 = rankz >= 2 ? 1 : 0;
|
373
|
+
l2 = rankw >= 2 ? 1 : 0;
|
374
|
+
// Rank 1 denotes the second smallest coordinate.
|
375
|
+
i3 = rankx >= 1 ? 1 : 0;
|
376
|
+
j3 = ranky >= 1 ? 1 : 0;
|
377
|
+
k3 = rankz >= 1 ? 1 : 0;
|
378
|
+
l3 = rankw >= 1 ? 1 : 0;
|
379
|
+
// The fifth corner has all coordinate offsets = 1, so no need to compute that.
|
380
|
+
double x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
|
381
|
+
double y1 = y0 - j1 + G4;
|
382
|
+
double z1 = z0 - k1 + G4;
|
383
|
+
double w1 = w0 - l1 + G4;
|
384
|
+
double x2 = x0 - i2 + 2.0 * G4; // Offsets for third corner in (x,y,z,w) coords
|
385
|
+
double y2 = y0 - j2 + 2.0 * G4;
|
386
|
+
double z2 = z0 - k2 + 2.0 * G4;
|
387
|
+
double w2 = w0 - l2 + 2.0 * G4;
|
388
|
+
double x3 = x0 - i3 + 3.0 * G4; // Offsets for fourth corner in (x,y,z,w) coords
|
389
|
+
double y3 = y0 - j3 + 3.0 * G4;
|
390
|
+
double z3 = z0 - k3 + 3.0 * G4;
|
391
|
+
double w3 = w0 - l3 + 3.0 * G4;
|
392
|
+
double x4 = x0 - 1.0 + 4.0 * G4; // Offsets for last corner in (x,y,z,w) coords
|
393
|
+
double y4 = y0 - 1.0 + 4.0 * G4;
|
394
|
+
double z4 = z0 - 1.0 + 4.0 * G4;
|
395
|
+
double w4 = w0 - 1.0 + 4.0 * G4;
|
396
|
+
// Work out the hashed gradient indices of the five simplex corners
|
397
|
+
int ii = i & 255;
|
398
|
+
int jj = j & 255;
|
399
|
+
int kk = k & 255;
|
400
|
+
int ll = l & 255;
|
401
|
+
int gi0 = PERM[ii + PERM[jj + PERM[kk + PERM[ll]]]] % 32;
|
402
|
+
int gi1 = PERM[ii + i1 + PERM[jj + j1 + PERM[kk + k1 + PERM[ll + l1]]]] % 32;
|
403
|
+
int gi2 = PERM[ii + i2 + PERM[jj + j2 + PERM[kk + k2 + PERM[ll + l2]]]] % 32;
|
404
|
+
int gi3 = PERM[ii + i3 + PERM[jj + j3 + PERM[kk + k3 + PERM[ll + l3]]]] % 32;
|
405
|
+
int gi4 = PERM[ii + 1 + PERM[jj + 1 + PERM[kk + 1 + PERM[ll + 1]]]] % 32;
|
406
|
+
// Calculate the contribution from the five corners
|
407
|
+
double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
|
408
|
+
if (t0 < 0) {
|
409
|
+
n0 = 0.0;
|
410
|
+
} else {
|
411
|
+
t0 *= t0;
|
412
|
+
n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
|
413
|
+
}
|
414
|
+
double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
|
415
|
+
if (t1 < 0) {
|
416
|
+
n1 = 0.0;
|
417
|
+
} else {
|
418
|
+
t1 *= t1;
|
419
|
+
n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
|
420
|
+
}
|
421
|
+
double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
|
422
|
+
if (t2 < 0) {
|
423
|
+
n2 = 0.0;
|
424
|
+
} else {
|
425
|
+
t2 *= t2;
|
426
|
+
n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
|
427
|
+
}
|
428
|
+
double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
|
429
|
+
if (t3 < 0) {
|
430
|
+
n3 = 0.0;
|
431
|
+
} else {
|
432
|
+
t3 *= t3;
|
433
|
+
n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
|
434
|
+
}
|
435
|
+
double t4 = 0.5 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
|
436
|
+
if (t4 < 0) {
|
437
|
+
n4 = 0.0;
|
438
|
+
} else {
|
439
|
+
t4 *= t4;
|
440
|
+
n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
|
441
|
+
}
|
442
|
+
// Sum up and scale the result to cover the range [-1,1]
|
443
|
+
return 27.0 * (n0 + n1 + n2 + n3 + n4);
|
444
|
+
}
|
445
|
+
|
446
|
+
// Inner class to speed upp gradient computations
|
447
|
+
// (In Java, array access is a lot slower than member access)
|
448
|
+
private static class Grad {
|
449
|
+
|
450
|
+
double x, y, z, w;
|
451
|
+
|
452
|
+
Grad(double x, double y, double z) {
|
453
|
+
this.x = x;
|
454
|
+
this.y = y;
|
455
|
+
this.z = z;
|
456
|
+
}
|
457
|
+
|
458
|
+
Grad(double x, double y, double z, double w) {
|
459
|
+
this.x = x;
|
460
|
+
this.y = y;
|
461
|
+
this.z = z;
|
462
|
+
this.w = w;
|
463
|
+
}
|
464
|
+
}
|
465
|
+
}
|