propane 0.3.0.pre-java

Sign up to get free protection for your applications and to get access to all the features.
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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d427bc8bff6a2ecdae40c103234be639ce4f78db
4
+ data.tar.gz: 84d89e9ff7e3d14aebd3daa2eccf80e62be05bbd
5
+ SHA512:
6
+ metadata.gz: 647c0f4a7f69ecd471205ecdba116d99b012f201ca705a1cef5c9660f5f23e920688e5b61603da4012f0af3a0b1f5e6a07b4a4b8e914b3f93fc8f64e21f6735c
7
+ data.tar.gz: 3315621182cb97955f3d9cbd6c88bc7d3ae0f4f67679fe7f83b6e774facf09ef6959ad01653c0488d5d8732f9e1c16ebddb514a41aba731c2cd673ea1410d68a
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ target
18
+ *.jar
19
+ *~
20
+ MANIFEST.MF
21
+
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <extensions>
3
+ <extension>
4
+ <groupId>io.takari.polyglot</groupId>
5
+ <artifactId>polyglot-ruby</artifactId>
6
+ <version>0.1.15</version>
7
+ </extension>
8
+ </extensions>
@@ -0,0 +1 @@
1
+ distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - jruby-19mode
5
+ script:
6
+ - bundle exec rake spec
7
+ before_install:
8
+ - "export DISPLAY=:99.0"
9
+ - "sh -e /etc/init.d/xvfb start"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem 'rspec'
4
+ gem 'rake'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Philip Cunningham
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ # Propane
2
+
3
+ A really 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, albeit tied to processing-2.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 a gem distribution, and hence we should not require configuration. This would is mainly scriptable version ie files get run direct from jruby. For certain sketches we need to call jruby via jruby-complete for this we have created an executable `propane` that can used to install `jruby-complete` and run sketches (maybe export?, possibly watch).
4
+
5
+ ## Building and testing
6
+
7
+ ```bash
8
+ rake
9
+ rake gem
10
+ rake javadoc
11
+ ```
12
+
13
+ ## Installation
14
+ ```bash
15
+ jgem install propane-{version}-java.gem
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ``` ruby
21
+ require 'propane'
22
+
23
+ class FlashingLightsSketch < Propane::App
24
+
25
+ attr_reader :random_background
26
+
27
+ def initialize opts={}
28
+ @random_background = opts.fetch :random_background, RandomBackground.new(self)
29
+ super
30
+ end
31
+
32
+ def setup
33
+ size(800, 600)
34
+ end
35
+
36
+ def draw
37
+ random_background.generate
38
+ end
39
+
40
+ end
41
+
42
+ class RandomBackground
43
+ include Propane::Proxy
44
+
45
+ def generate
46
+ background(rand(255), rand(255), rand(255))
47
+ end
48
+
49
+ end
50
+
51
+ FlashingLightsSketch.new title: "Flashing Lights"
52
+ ```
53
+
54
+ Many sketches will run just using an installed jruby, but shader sketches must be run using jruby-complete, but don't worry we make it easy, to install jruby-complete:
55
+ ```bash
56
+ propane --install
57
+ ```
58
+ To run sketches using the installed jruby-complete
59
+ ```bash
60
+ propane --run my_sketch.rb # or
61
+ jruby -S propane --run my_sketch.rb # belt and braces version
62
+ ```
63
+ ## Contributing
64
+
65
+ 1. Fork it
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create new Pull Request
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: false
3
+ require_relative 'lib/propane/version'
4
+
5
+ def create_manifest
6
+ title = 'Implementation-Title: rpextras (java extension for propane)'
7
+ version = format('Implementation-Version: %s', Propane::VERSION)
8
+ File.open('MANIFEST.MF', 'w') do |f|
9
+ f.puts(title)
10
+ f.puts(version)
11
+ end
12
+ end
13
+
14
+ task default: [:init, :compile, :install, :test]
15
+
16
+ desc 'Create Manifest'
17
+ task :init do
18
+ create_manifest
19
+ end
20
+
21
+ desc 'Install'
22
+ task :install do
23
+ sh 'mvn dependency:copy'
24
+ sh 'mv target/rpextras.jar lib'
25
+ end
26
+
27
+ desc 'Gem'
28
+ task :gem do
29
+ sh 'gem build propane.gemspec'
30
+ end
31
+
32
+ desc 'Document'
33
+ task :javadoc do
34
+ sh 'mvn javadoc:javadoc'
35
+ end
36
+
37
+ desc 'Compile'
38
+ task :compile do
39
+ sh 'mvn package'
40
+ end
41
+
42
+ desc 'JRuby-Complete'
43
+ task :install_complete do
44
+ sh 'cd vendors && rake'
45
+ end
46
+
47
+ desc 'Test'
48
+ task :test do
49
+ sh 'jruby test/respond_to_test.rb'
50
+ end
51
+
52
+ desc 'clean'
53
+ task :clean do
54
+ Dir['./**/*.%w{jar gem}'].each do |path|
55
+ puts 'Deleting #{path} ...'
56
+ File.delete(path)
57
+ end
58
+ FileUtils.rm_rf('./target')
59
+ end
@@ -0,0 +1,4 @@
1
+ 0.2.0
2
+ =====
3
+
4
+ * Added some guard clauses and fleshed out specs.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env jruby
2
+ unless defined? PROPANE_ROOT
3
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
4
+ PROPANE_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')
5
+ end
6
+
7
+ require "#{PROPANE_ROOT}/lib/propane/runner"
8
+ Propane::Runner.execute
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ # Simple demo Rakefile to autorun samples in current directory
4
+ # adjust path to jruby-complete, and or opts as required
5
+
6
+ SAMPLES_DIR = './'
7
+
8
+ desc 'run demo'
9
+ task default: [:demo]
10
+
11
+ desc 'demo'
12
+ task :demo do
13
+ samples_list.shuffle.each { |sample| run_sample sample }
14
+ end
15
+
16
+ def samples_list
17
+ files = []
18
+ Dir.chdir(SAMPLES_DIR)
19
+ Dir.glob('*.rb').each do |file|
20
+ files << File.join(SAMPLES_DIR, file)
21
+ end
22
+ return files
23
+ end
24
+
25
+ def run_sample(sample_name)
26
+ puts "Running #{sample_name}...quit to run next sample"
27
+ open("|jruby -S propane --run #{sample_name}", 'r') do |io|
28
+ while l = io.gets
29
+ puts(l.chop)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+
2
+ uniform sampler2D colorMap;
3
+
4
+ varying vec4 vertTexCoord;
5
+
6
+ void main() {
7
+ gl_FragColor = texture2D(colorMap, vertTexCoord.st);
8
+ }
@@ -0,0 +1,201 @@
1
+
2
+ #define PROCESSING_TEXLIGHT_SHADER
3
+
4
+ uniform mat4 modelview;
5
+ uniform mat4 transform;
6
+ uniform mat3 normalMatrix;
7
+ uniform mat4 texMatrix;
8
+
9
+ uniform int lightCount;
10
+ uniform vec4 lightPosition[8];
11
+ uniform vec3 lightNormal[8];
12
+ uniform vec3 lightAmbient[8];
13
+ uniform vec3 lightDiffuse[8];
14
+ uniform vec3 lightSpecular[8];
15
+ uniform vec3 lightFalloff[8];
16
+ uniform vec2 lightSpot[8];
17
+
18
+ attribute vec4 vertex;
19
+ attribute vec4 color;
20
+ attribute vec3 normal;
21
+ attribute vec2 texCoord;
22
+
23
+ attribute vec4 ambient;
24
+ attribute vec4 specular;
25
+ attribute vec4 emissive;
26
+ attribute float shininess;
27
+
28
+ varying vec4 vertColor;
29
+ varying vec4 vertTexCoord;
30
+
31
+ const float zero_float = 0.0;
32
+ const float one_float = 1.0;
33
+ const vec3 zero_vec3 = vec3(0);
34
+
35
+ uniform float displaceStrength;
36
+ uniform float time;
37
+
38
+ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) {
39
+ vec3 lpv = lightPos - vertPos;
40
+ vec3 dist = vec3(one_float);
41
+ dist.z = dot(lpv, lpv);
42
+ dist.y = sqrt(dist.z);
43
+ return one_float / dot(dist, coeff);
44
+ }
45
+
46
+ float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) {
47
+ vec3 lpv = normalize(lightPos - vertPos);
48
+ vec3 nln = -one_float * lightNorm;
49
+ float spotCos = dot(nln, lpv);
50
+ return spotCos <= minCos ? zero_float : pow(spotCos, spotExp);
51
+ }
52
+
53
+ float lambertFactor(vec3 lightDir, vec3 vecNormal) {
54
+ return max(zero_float, dot(lightDir, vecNormal));
55
+ }
56
+
57
+ float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) {
58
+ vec3 np = normalize(vertPos);
59
+ vec3 ldp = normalize(lightDir - np);
60
+ return pow(max(zero_float, dot(ldp, vecNormal)), shine);
61
+ }
62
+
63
+ // Source code for GLSL Perlin noise courtesy of:
64
+ // https://github.com/ashima/webgl-noise/wiki
65
+
66
+ vec3 mod289(vec3 x) {
67
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
68
+ }
69
+
70
+ vec2 mod289(vec2 x) {
71
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
72
+ }
73
+
74
+ vec3 permute(vec3 x) {
75
+ return mod289(((x*34.0)+1.0)*x);
76
+ }
77
+
78
+ float snoise(vec2 v)
79
+ {
80
+ const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
81
+ 0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
82
+ -0.577350269189626, // -1.0 + 2.0 * C.x
83
+ 0.024390243902439); // 1.0 / 41.0
84
+ // First corner
85
+ vec2 i = floor(v + dot(v, C.yy) );
86
+ vec2 x0 = v - i + dot(i, C.xx);
87
+
88
+ // Other corners
89
+ vec2 i1;
90
+ //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
91
+ //i1.y = 1.0 - i1.x;
92
+ i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
93
+ // x0 = x0 - 0.0 + 0.0 * C.xx ;
94
+ // x1 = x0 - i1 + 1.0 * C.xx ;
95
+ // x2 = x0 - 1.0 + 2.0 * C.xx ;
96
+ vec4 x12 = x0.xyxy + C.xxzz;
97
+ x12.xy -= i1;
98
+
99
+ // Permutations
100
+ i = mod289(i); // Avoid truncation effects in permutation
101
+ vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
102
+ + i.x + vec3(0.0, i1.x, 1.0 ));
103
+
104
+ vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
105
+ m = m*m ;
106
+ m = m*m ;
107
+
108
+ // Gradients: 41 points uniformly over a line, mapped onto a diamond.
109
+ // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
110
+
111
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
112
+ vec3 h = abs(x) - 0.5;
113
+ vec3 ox = floor(x + 0.5);
114
+ vec3 a0 = x - ox;
115
+
116
+ // Normalise gradients implicitly by scaling m
117
+ // Approximation of: m *= inversesqrt( a0*a0 + h*h );
118
+ m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
119
+
120
+ // Compute final noise value at P
121
+ vec3 g;
122
+ g.x = a0.x * x0.x + h.x * x0.y;
123
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
124
+ return 130.0 * dot(m, g);
125
+ }
126
+
127
+ void main() {
128
+ // Calculating texture coordinates, with r and q set both to one
129
+ vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
130
+
131
+ vec2 p = texCoord; // put coordinates into vec2 p for convenience
132
+ p.x += time; // add time to make the noise and the subsequent displacement move
133
+ float df = snoise( p ); // create displacement float value from shader-based 2D Perlin noise
134
+ vec4 newVertexPos = vertex + vec4(normal * df * displaceStrength, 0.0); // regular vertex position + direction * displacementMap * displaceStrength
135
+
136
+ // Vertex in clip coordinates
137
+ gl_Position = transform * newVertexPos;
138
+
139
+ // Vertex in eye coordinates
140
+ vec3 ecVertex = vec3(modelview * vertex);
141
+
142
+ // Normal vector in eye coordinates
143
+ vec3 ecNormal = normalize(normalMatrix * normal);
144
+
145
+ if (dot(-one_float * ecVertex, ecNormal) < zero_float) {
146
+ // If normal is away from camera, choose its opposite.
147
+ // If we add backface culling, this will be backfacing
148
+ ecNormal *= -one_float;
149
+ }
150
+
151
+ // Light calculations
152
+ vec3 totalAmbient = vec3(0, 0, 0);
153
+ vec3 totalDiffuse = vec3(0, 0, 0);
154
+ vec3 totalSpecular = vec3(0, 0, 0);
155
+ for (int i = 0; i < 8; i++) {
156
+ if (lightCount == i) break;
157
+
158
+ vec3 lightPos = lightPosition[i].xyz;
159
+ bool isDir = zero_float < lightPosition[i].w;
160
+ float spotCos = lightSpot[i].x;
161
+ float spotExp = lightSpot[i].y;
162
+
163
+ vec3 lightDir;
164
+ float falloff;
165
+ float spotf;
166
+
167
+ if (isDir) {
168
+ falloff = one_float;
169
+ lightDir = -one_float * lightNormal[i];
170
+ } else {
171
+ falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
172
+ lightDir = normalize(lightPos - ecVertex);
173
+ }
174
+
175
+ spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
176
+ spotCos, spotExp)
177
+ : one_float;
178
+
179
+ if (any(greaterThan(lightAmbient[i], zero_vec3))) {
180
+ totalAmbient += lightAmbient[i] * falloff;
181
+ }
182
+
183
+ if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
184
+ totalDiffuse += lightDiffuse[i] * falloff * spotf *
185
+ lambertFactor(lightDir, ecNormal);
186
+ }
187
+
188
+ if (any(greaterThan(lightSpecular[i], zero_vec3))) {
189
+ totalSpecular += lightSpecular[i] * falloff * spotf *
190
+ blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
191
+ }
192
+ }
193
+
194
+ // Calculating final color as result of all lights (plus emissive term).
195
+ // Transparency is determined exclusively by the diffuse component.
196
+ vertColor = vec4(totalAmbient, 0) * ambient +
197
+ vec4(totalDiffuse, 1) * color +
198
+ vec4(totalSpecular, 0) * specular +
199
+ vec4(emissive.rgb, 0);
200
+
201
+ }