propane 0.3.0.pre-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.mvn/extensions.xml +8 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  5. data/.travis.yml +9 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +69 -0
  9. data/Rakefile +59 -0
  10. data/VERSION.txt +4 -0
  11. data/bin/propane +8 -0
  12. data/examples/complete/Rakefile +32 -0
  13. data/examples/complete/data/Texture01.jpg +0 -0
  14. data/examples/complete/data/Texture02.jpg +0 -0
  15. data/examples/complete/data/Univers45.vlw +0 -0
  16. data/examples/complete/data/displaceFrag.glsl +8 -0
  17. data/examples/complete/data/displaceVert.glsl +201 -0
  18. data/examples/complete/glsl_heightmap_noise.rb +121 -0
  19. data/examples/complete/kinetic_type.rb +79 -0
  20. data/examples/regular/Rakefile +30 -0
  21. data/examples/regular/arcball_box.rb +36 -0
  22. data/examples/regular/creating_colors.rb +57 -0
  23. data/examples/regular/elegant_ball.rb +159 -0
  24. data/examples/regular/flight_patterns.rb +63 -0
  25. data/examples/regular/grey_circles.rb +28 -0
  26. data/examples/regular/jwishy.rb +100 -0
  27. data/examples/regular/letters.rb +42 -0
  28. data/examples/regular/lib/boundary.rb +38 -0
  29. data/examples/regular/lib/particle.rb +77 -0
  30. data/examples/regular/lib/particle_system.rb +111 -0
  31. data/examples/regular/liquidy.rb +40 -0
  32. data/examples/regular/mouse_button_demo.rb +34 -0
  33. data/examples/regular/polyhedrons.rb +248 -0
  34. data/examples/regular/ribbon_doodle.rb +89 -0
  35. data/examples/regular/vector_math.rb +36 -0
  36. data/examples/regular/words.rb +41 -0
  37. data/lib/PROCESSING_LICENSE.txt +456 -0
  38. data/lib/export.txt +10 -0
  39. data/lib/propane.rb +12 -0
  40. data/lib/propane/app.rb +197 -0
  41. data/lib/propane/helper_methods.rb +177 -0
  42. data/lib/propane/helpers/numeric.rb +9 -0
  43. data/lib/propane/library_loader.rb +117 -0
  44. data/lib/propane/runner.rb +88 -0
  45. data/lib/propane/underscorer.rb +19 -0
  46. data/lib/propane/version.rb +5 -0
  47. data/library/boids/boids.rb +201 -0
  48. data/library/control_panel/control_panel.rb +172 -0
  49. data/pom.rb +113 -0
  50. data/pom.xml +198 -0
  51. data/propane.gemspec +28 -0
  52. data/src/monkstone/ColorUtil.java +67 -0
  53. data/src/monkstone/MathTool.java +195 -0
  54. data/src/monkstone/PropaneLibrary.java +47 -0
  55. data/src/monkstone/core/AbstractLibrary.java +102 -0
  56. data/src/monkstone/fastmath/Deglut.java +115 -0
  57. data/src/monkstone/vecmath/AppRender.java +87 -0
  58. data/src/monkstone/vecmath/JRender.java +56 -0
  59. data/src/monkstone/vecmath/ShapeRender.java +87 -0
  60. data/src/monkstone/vecmath/vec2/Vec2.java +670 -0
  61. data/src/monkstone/vecmath/vec3/Vec3.java +708 -0
  62. data/test/respond_to_test.rb +208 -0
  63. data/vendors/Rakefile +48 -0
  64. metadata +130 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The purpose of this class is to load the MathTool into ruby-processing runtime
3
+ * Copyright (C) 2015-16 Martin Prout. This code is free software; you can
4
+ * redistribute it and/or modify it under the terms of the GNU Lesser General
5
+ * Public License as published by the Free Software Foundation; either version
6
+ * 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html
9
+ */
10
+
11
+ package monkstone;
12
+
13
+ import java.io.IOException;
14
+ import monkstone.fastmath.Deglut;
15
+ import monkstone.vecmath.vec2.Vec2;
16
+ import monkstone.vecmath.vec3.Vec3;
17
+ import org.jruby.Ruby;
18
+ import org.jruby.runtime.load.Library;
19
+
20
+ /**
21
+ *
22
+ * @author Martin Prout
23
+ */
24
+ public class PropaneLibrary implements Library{
25
+
26
+ /**
27
+ *
28
+ * @param runtime
29
+ */
30
+ public static void load(final Ruby runtime) {
31
+ MathTool.createMathTool(runtime);
32
+ Deglut.createDeglut(runtime);
33
+ Vec2.createVec2(runtime);
34
+ Vec3.createVec3(runtime);
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @param runtime
40
+ * @param wrap
41
+ * @throws java.io.IOException
42
+ */
43
+ @Override
44
+ public void load(final Ruby runtime, boolean wrap) throws IOException {
45
+ load(runtime);
46
+ }
47
+ }
@@ -0,0 +1,102 @@
1
+ package monkstone.core;
2
+
3
+ import static processing.core.PConstants.*;
4
+
5
+ /**
6
+ * The purpose of this class is to enable
7
+ * access to processing pre, draw and post loops in
8
+ * ruby-processing as a regular java library class.
9
+ * Also included background, fill and stroke methods.
10
+ * PConstants should also be available from static import
11
+ * @author Martin Prout
12
+ */
13
+ public abstract class AbstractLibrary {
14
+
15
+ private final processing.core.PApplet app;
16
+
17
+ /**
18
+ * Useful accessors
19
+ */
20
+ public int width, height;
21
+
22
+ /**
23
+ *
24
+ * @param app PApplet
25
+ */
26
+ public AbstractLibrary(processing.core.PApplet app) {
27
+ this.app = app;
28
+ this.width = app.width;
29
+ this.height = app.height;
30
+ setActive(true);
31
+ }
32
+
33
+ /**
34
+ * Extending classes must implement this gives access to, by reflection,
35
+ * processing PApplet pre loop (called before draw)
36
+ */
37
+ public abstract void pre();
38
+
39
+ /**
40
+ * Extending classes must implement this gives access to processing PApplet
41
+ * draw loop
42
+ */
43
+ public abstract void draw();
44
+
45
+ /**
46
+ * Extending classes must implement this gives access to, by reflection,
47
+ * processing PApplet post loop (called after draw)
48
+ */
49
+ public abstract void post();
50
+
51
+ private void setActive(boolean active) {
52
+ if (active) {
53
+ this.app.registerMethod("pre", this);
54
+ this.app.registerMethod("draw", this);
55
+ this.app.registerMethod("post", this);
56
+ this.app.registerMethod("dispose", this);
57
+ } else {
58
+ this.app.unregisterMethod("pre", this);
59
+ this.app.unregisterMethod("draw", this);
60
+ this.app.unregisterMethod("post", this);
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Simple signature for background hides need to call app
66
+ * @param col
67
+ */
68
+ public void background(int col) {
69
+ this.app.background(col);
70
+ }
71
+
72
+ /**
73
+ * Simple signature for fill hides need to call app
74
+ * @param col
75
+ */
76
+ public void fill(int col) {
77
+ this.app.fill(col);
78
+ }
79
+
80
+ /**
81
+ * Simple signature for stroke hides need to call app
82
+ * @param col
83
+ */
84
+ public void stroke(int col) {
85
+ this.app.stroke(col);
86
+ }
87
+
88
+ /**
89
+ * Access applet if we must
90
+ * @return app PApplet
91
+ */
92
+ public processing.core.PApplet app() {
93
+ return this.app;
94
+ }
95
+
96
+ /**
97
+ * required for processing
98
+ */
99
+ public void dispose() {
100
+ setActive(false);
101
+ }
102
+ }
@@ -0,0 +1,115 @@
1
+ package monkstone.fastmath;
2
+
3
+ import org.jruby.Ruby;
4
+ import org.jruby.RubyClass;
5
+ import org.jruby.RubyModule;
6
+ import org.jruby.RubyObject;
7
+ import org.jruby.anno.JRubyClass;
8
+ import org.jruby.anno.JRubyMethod;
9
+ import org.jruby.runtime.ThreadContext;
10
+ import org.jruby.runtime.builtin.IRubyObject;
11
+
12
+ /**
13
+ *
14
+ * @author Martin Prout
15
+ */
16
+ @JRubyClass(name = "DegLut")
17
+ public class Deglut extends RubyObject {
18
+
19
+ /**
20
+ * Lookup table for degree cosine/sine, has a fixed precision 1.0
21
+ * degrees Quite accurate but imprecise
22
+ *
23
+ * @author Martin Prout <martin_p@lineone.net>
24
+ */
25
+ static final double[] SIN_DEG_LUT = new double[91];
26
+ /**
27
+ *
28
+ */
29
+ public static final double TO_RADIANS = Math.PI / 180;
30
+ /**
31
+ *
32
+ */
33
+ private static boolean initialized = false;
34
+
35
+ private final static int NINETY = 90;
36
+ private final static int FULL = 360;
37
+ private static final long serialVersionUID = -1466528933765940101L;
38
+
39
+ /**
40
+ * Initialise sin table with values (first quadrant only)
41
+ */
42
+ public static final void initTable() {
43
+ if (initialized == false) {
44
+ for (int i = 0; i <= NINETY; i++) {
45
+ SIN_DEG_LUT[i] = Math.sin(TO_RADIANS * i);
46
+ }
47
+ initialized = true;
48
+ }
49
+ }
50
+
51
+
52
+ /**
53
+ *
54
+ * @param runtime
55
+ */
56
+
57
+ public static void createDeglut(final Ruby runtime){
58
+ RubyModule deglutModule = runtime.defineModule("DegLut");
59
+ deglutModule.defineAnnotatedMethods(Deglut.class);
60
+ Deglut.initTable();
61
+ }
62
+
63
+
64
+ /**
65
+ *
66
+ * @param runtime
67
+ * @param klass
68
+ */
69
+ private Deglut(Ruby runtime, RubyClass klass) {
70
+ super(runtime, klass);
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @param context
76
+ * @param klazz
77
+ * @param other
78
+ * @return sin float
79
+ */
80
+ @JRubyMethod(name = "sin", meta = true)
81
+
82
+ public static IRubyObject sin(ThreadContext context, IRubyObject klazz, IRubyObject other) {
83
+ int thet = (Integer) other.toJava(Integer.class);
84
+ while (thet < 0) {
85
+ thet += FULL; // Needed because negative modulus plays badly in java
86
+ }
87
+ int theta = thet % FULL;
88
+ int y = theta % NINETY;
89
+ double result = (theta < NINETY) ? SIN_DEG_LUT[y] : (theta < 180)
90
+ ? SIN_DEG_LUT[NINETY - y] : (theta < 270)
91
+ ? -SIN_DEG_LUT[y] : -SIN_DEG_LUT[NINETY - y];
92
+ return context.getRuntime().newFloat(result);
93
+ }
94
+
95
+ /**
96
+ *
97
+ * @param context
98
+ * @param klazz
99
+ * @param other
100
+ * @return cos float
101
+ */
102
+ @JRubyMethod(name = "cos", meta = true)
103
+ public static IRubyObject cos(ThreadContext context, IRubyObject klazz, IRubyObject other) {
104
+ int thet = (Integer) other.toJava(Integer.class);
105
+ while (thet < 0) {
106
+ thet += FULL; // Needed because negative modulus plays badly in java
107
+ }
108
+ int theta = thet % FULL;
109
+ int y = theta % NINETY;
110
+ double result = (theta < NINETY) ? SIN_DEG_LUT[NINETY - y] : (theta < 180)
111
+ ? -SIN_DEG_LUT[y] : (theta < 270)
112
+ ? -SIN_DEG_LUT[NINETY - y] : SIN_DEG_LUT[y];
113
+ return context.getRuntime().newFloat(result);
114
+ }
115
+ }
@@ -0,0 +1,87 @@
1
+ package monkstone.vecmath;
2
+
3
+ import processing.core.PApplet;
4
+
5
+ /**
6
+ *
7
+ * @author Martin Prout
8
+ */
9
+ public class AppRender implements JRender {
10
+
11
+ final PApplet app;
12
+
13
+ /**
14
+ *
15
+ * @param app
16
+ */
17
+ public AppRender(final PApplet app) {
18
+ this.app = app;
19
+ }
20
+
21
+ /**
22
+ *
23
+ * @param x
24
+ * @param y
25
+ */
26
+ @Override
27
+ public void vertex(double x, double y) {
28
+ app.vertex((float) x, (float) y);
29
+ }
30
+
31
+ /**
32
+ *
33
+ * @param x
34
+ * @param y
35
+ */
36
+ @Override
37
+ public void curveVertex(double x, double y) {
38
+ app.curveVertex((float) x, (float) y);
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @param x
44
+ * @param y
45
+ * @param z
46
+ */
47
+ @Override
48
+ public void vertex(double x, double y, double z) {
49
+ app.vertex((float) x, (float) y, (float) z);
50
+ }
51
+
52
+ /**
53
+ *
54
+ * @param x
55
+ * @param y
56
+ * @param z
57
+ */
58
+ @Override
59
+ public void normal(double x, double y, double z) {
60
+ app.normal((float) x, (float) y, (float) z);
61
+ }
62
+
63
+ /**
64
+ *
65
+ * @param x
66
+ * @param y
67
+ * @param z
68
+ * @param u
69
+ * @param v
70
+ */
71
+ @Override
72
+ public void vertex(double x, double y, double z, double u, double v) {
73
+ app.vertex((float) x, (float) y, (float) z, (float) u, (float) v);
74
+ }
75
+
76
+ /**
77
+ *
78
+ * @param x
79
+ * @param y
80
+ * @param z
81
+ */
82
+ @Override
83
+ public void curveVertex(double x, double y, double z) {
84
+ app.curveVertex((float) x, (float) y, (float) z);
85
+ }
86
+
87
+ }
@@ -0,0 +1,56 @@
1
+ package monkstone.vecmath;
2
+
3
+ /**
4
+ *
5
+ * @author Martin Prout
6
+ */
7
+ public interface JRender {
8
+
9
+ /**
10
+ *
11
+ * @param x
12
+ * @param y
13
+ */
14
+ public void vertex(double x, double y);
15
+
16
+ /**
17
+ *
18
+ * @param x
19
+ * @param y
20
+ */
21
+ public void curveVertex(double x, double y);
22
+
23
+ /**
24
+ *
25
+ * @param x
26
+ * @param y
27
+ * @param z
28
+ */
29
+ public void vertex(double x, double y, double z);
30
+
31
+ /**
32
+ *
33
+ * @param x
34
+ * @param y
35
+ * @param z
36
+ * @param u
37
+ * @param v
38
+ */
39
+ public void vertex(double x, double y, double z, double u, double v);
40
+
41
+ /**
42
+ *
43
+ * @param x
44
+ * @param y
45
+ * @param z
46
+ */
47
+ public void curveVertex(double x, double y, double z);
48
+
49
+ /**
50
+ *
51
+ * @param x
52
+ * @param y
53
+ * @param z
54
+ */
55
+ public void normal(double x, double y, double z);
56
+ }
@@ -0,0 +1,87 @@
1
+ package monkstone.vecmath;
2
+
3
+ import processing.core.PShape;
4
+
5
+ /**
6
+ *
7
+ * @author Martin Prout
8
+ */
9
+ public class ShapeRender implements JRender {
10
+
11
+ final PShape shape;
12
+
13
+ /**
14
+ *
15
+ * @param shape
16
+ */
17
+ public ShapeRender(final PShape shape) {
18
+ this.shape = shape;
19
+
20
+ }
21
+
22
+ /**
23
+ *
24
+ * @param x
25
+ * @param y
26
+ */
27
+ @Override
28
+ public void vertex(double x, double y) {
29
+ shape.vertex((float) x, (float) y);
30
+ }
31
+
32
+ /**
33
+ *
34
+ * @param x
35
+ * @param y
36
+ */
37
+ @Override
38
+ public void curveVertex(double x, double y) {
39
+ throw new UnsupportedOperationException("Not implemented for this renderer");
40
+ }
41
+
42
+ /**
43
+ *
44
+ * @param x
45
+ * @param y
46
+ * @param z
47
+ */
48
+ @Override
49
+ public void vertex(double x, double y, double z) {
50
+ shape.vertex((float) x, (float) y, (float) z);
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @param x
56
+ * @param y
57
+ * @param z
58
+ */
59
+ @Override
60
+ public void normal(double x, double y, double z) {
61
+ shape.normal((float) x, (float) y, (float) z);
62
+ }
63
+
64
+ /**
65
+ *
66
+ * @param x
67
+ * @param y
68
+ * @param z
69
+ * @param u
70
+ * @param v
71
+ */
72
+ @Override
73
+ public void vertex(double x, double y, double z, double u, double v) {
74
+ shape.vertex((float) x, (float) y, (float) z, (float) u, (float) v);
75
+ }
76
+
77
+ /**
78
+ *
79
+ * @param x
80
+ * @param y
81
+ * @param z
82
+ */
83
+ @Override
84
+ public void curveVertex(double x, double y, double z) {
85
+ throw new UnsupportedOperationException("Not implemented for this renderer");
86
+ }
87
+ }