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,40 @@
1
+ require 'propane'
2
+ require 'pbox2d'
3
+ require_relative 'lib/particle_system'
4
+ require_relative 'lib/boundary'
5
+
6
+ Vect = Struct.new(:x, :y)
7
+
8
+ class Liquidy < Propane::App
9
+ attr_reader :box2d, :boundaries, :systems
10
+
11
+ def setup
12
+ size(400, 300)
13
+ @box2d = WorldBuilder.build(app: self, gravity: [0, -20])
14
+ @systems = []
15
+ @boundaries = [
16
+ Boundary.new(box2d, Vect.new(50, 100), Vect.new(300, 5), -0.3),
17
+ Boundary.new(box2d, Vect.new(250, 175), Vect.new(300, 5), 0.5)
18
+ ]
19
+ end
20
+
21
+ def draw
22
+ background(255)
23
+ # Run all the particle systems
24
+ if systems.size > 0
25
+ systems.each do |system|
26
+ system.run
27
+ system.add_particles(box2d, rand(0..2))
28
+ end
29
+ end
30
+ # Display all the boundaries
31
+ boundaries.each(&:display)
32
+ end
33
+
34
+ def mouse_pressed
35
+ # Add a new Particle System whenever the mouse is clicked
36
+ systems << ParticleSystem.new(box2d, 0, mouse_x, mouse_y)
37
+ end
38
+ end
39
+
40
+ Liquidy.new title: 'Liquidy'
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ require_relative '../../lib/propane' # temporary local
6
+
7
+ # Demo of Mouse Button
8
+ class MouseButtonDemo < Propane::App
9
+ # Click within the image and press
10
+ # the left and right mouse buttons to
11
+ # change the value of the rectangle
12
+ def setup
13
+ size 300, 200
14
+ end
15
+
16
+ def draw
17
+ rect(25, 25, 150, 80)
18
+ end
19
+
20
+ def mouse_pressed
21
+ case mouse_button
22
+ when LEFT
23
+ fill 0
24
+ when RIGHT
25
+ fill 255
26
+ when CENTER
27
+ fill 125
28
+ else
29
+ fill 200, 0, 0
30
+ end
31
+ end
32
+ end
33
+
34
+ MouseButtonDemo.new title: 'Mouse Button Demo'
@@ -0,0 +1,248 @@
1
+ ###
2
+ # Polyhedrons after sketch by Chinchbug on openprocessing.org
3
+ ###
4
+ Vert = Struct.new(:x, :y, :z) do
5
+ def dist_sq(v)
6
+ (x - v.x) * (x - v.x) + (y - v.y) * (y - v.y) + (z - v.z) * (z - v.z)
7
+ end
8
+
9
+ def self.permutations(x, y, z)
10
+ [new(x, y, z), new(z, x, y), new(y, z, x)]
11
+ end
12
+ end
13
+
14
+ PHI = (1 + Math.sqrt(5)) / 2
15
+ PHI_SQ = PHI * PHI
16
+ PHI_CU = PHI * PHI * PHI
17
+ ROOT2 = Math.sqrt(2)
18
+ TYPE = "Type Archimedian\nFaces: "
19
+
20
+ require 'propane'
21
+
22
+ class Polyhedrons < Propane::App
23
+
24
+ attr_reader :verts, :curr_id, :scayl, :ang, :spd, :name, :notes, :off_x, :off_y
25
+ attr_reader :off_z, :len_edge
26
+
27
+ def setup
28
+ size(1020, 576, P3D)
29
+ smooth 4
30
+ text_size(14)
31
+ # some positional variables for translation
32
+ @off_y = height / 2
33
+ @off_x = width / 2 - 100
34
+ @off_z = -off_y / 8
35
+ # angle and speed for rotation
36
+ @ang = 0.0
37
+ @spd = 0.015
38
+ # set up initial polyhedron
39
+ @verts = []
40
+ @curr_id = 0
41
+ create_poly(curr_id)
42
+ end
43
+
44
+ def draw
45
+ # setup the view
46
+ background(200)
47
+ push_matrix
48
+ translate(off_x, off_y, off_z)
49
+ rotate_x(Math.sin(-ang * 0.3) * 0.5)
50
+ rotate_y(ang)
51
+ draw_axis
52
+ # draw the polyhedron
53
+ stroke_weight(0.75)
54
+ stroke(0)
55
+ (0...verts.size).each do |i|
56
+ (i...verts.size).each do |j|
57
+ draw_line(verts[i], verts[j]) if edge?(verts[i], verts[j])
58
+ end
59
+ end
60
+ pop_matrix
61
+ hint(DISABLE_DEPTH_TEST)
62
+ # show some notes
63
+ fill(80, 50, 20)
64
+ text(name, width - 360, 50)
65
+ text(notes, width - 340, 70)
66
+ text('Click to view next polyhedron...', width - 360, height - 50)
67
+ hint(ENABLE_DEPTH_TEST)
68
+ # bump up the angle for the spin
69
+ @ang += spd
70
+ end
71
+
72
+ def mouse_released
73
+ # change the polyhedron
74
+ create_poly(@curr_id += 1)
75
+ end
76
+
77
+ def draw_line(v1, v2)
78
+ # Draws an edge line
79
+ line(v1.x * scayl, v1.y * scayl, v1.z * scayl, v2.x * scayl, v2.y * scayl, v2.z * scayl)
80
+ end
81
+
82
+ def edge?(v1, v2)
83
+ # had some rounding errors, now a bit more forgiving...
84
+ pres = 1000
85
+ d = v1.dist_sq(v2) + 0.00001
86
+ ((d * pres).round == (len_edge * len_edge * pres).round)
87
+ end
88
+
89
+ def add_verts(x, y, z)
90
+ # adds the requested vert and all 'mirrored' verts
91
+ verts << Vert.new(x, y, z)
92
+ verts << Vert.new(x, y, -z) unless (z == 0.0)
93
+ verts << Vert.new(x, -y, z) unless (y == 0.0)
94
+ verts << Vert.new(x, -y, -z) unless (z == 0.0)
95
+ verts << Vert.new(-x, y, z) unless (x == 0.0)
96
+ verts << Vert.new(-x, y, -z) unless (z == 0.0)
97
+ verts << Vert.new(-x, -y, z) unless (y == 0.0)
98
+ verts << Vert.new(-x, -y, -z) unless (z == 0.0)
99
+ end
100
+
101
+ def permutations(x, y, z)
102
+ # adds vertices for all three permutations of x, y, and z
103
+ Vert.permutations(x, y, z).each { |v| add_verts(v.x, v.y, v.z) }
104
+ end
105
+
106
+ def draw_axis
107
+ # based off how Sketchup handles their axis
108
+ stroke_weight(0.5)
109
+ stroke(0, 128, 0)
110
+ line(-300, 0, 0, 0, 0, 0)
111
+ stroke(0, 0, 128)
112
+ line(0, -300, 0, 0, 0, 0)
113
+ stroke(128, 0, 0)
114
+ line(0, 0, -300, 0, 0, 0)
115
+ stroke_weight(0.25)
116
+ stroke(0, 128, 0)
117
+ line(300, 0, 0, 0, 0, 0)
118
+ stroke(0, 0, 128)
119
+ line(0, 300, 0, 0, 0, 0)
120
+ stroke(128, 0, 0)
121
+ line(0, 0, 300, 0, 0, 0)
122
+ end
123
+
124
+ def create_poly(id)
125
+ # This is where the actual defining of the polyhedrons takes place
126
+ verts.clear # clear out whatever verts are currently defined
127
+ case (id)
128
+ when 0
129
+ @name = 'Cube:'
130
+ @notes = "Type platonic\nFaces: 6 squares\nVertices 8\nEdges 12"
131
+ add_verts(1, 1, 1)
132
+ @len_edge = 2
133
+ @scayl = 140
134
+ when 1
135
+ @name = 'Octohedron:'
136
+ @notes = "Type platonic\nFaces: 8 triangles\nVertices 6\nEdges 12"
137
+ permutations(1, 0, 0)
138
+ @len_edge = ROOT2
139
+ @scayl = 220
140
+ when 2
141
+ @name = 'Dodecahedron:'
142
+ @notes = "Type platonic\nFaces: 12 pentagons\nVertices 20\nEdges 30"
143
+ add_verts(1, 1, 1)
144
+ permutations(0, 1 / PHI, PHI)
145
+ @len_edge = 2 / PHI
146
+ @scayl = 130
147
+ when 3
148
+ @name = 'Icosahedron:'
149
+ @notes = "Type platonic\nFaces: 20 triangles\nVertices 12\nEdges 30"
150
+ permutations(0, 1, PHI)
151
+ @len_edge = 2.0
152
+ @scayl = 120
153
+ when 4
154
+ @name = 'Rhombic Dodecahedron:'
155
+ @notes = "Type Catalan\nFaces: 12 rhombuses\nVertices 14\nEdges 24"
156
+ add_verts(1, 1, 1)
157
+ permutations(0, 0, 2)
158
+ @len_edge = Math.sqrt(3)
159
+ @scayl = 110
160
+ when 5
161
+ @name = 'Rhombic Triacontahedron:'
162
+ @notes = "Type Catalan\nFaces: 30 rhombuses\nVertices 32\nEdges 60"
163
+ add_verts(PHI_SQ, PHI_SQ, PHI_SQ)
164
+ permutations(PHI_SQ, 0, PHI_CU)
165
+ permutations(0, PHI, PHI_CU)
166
+ @len_edge = PHI * Math.sqrt(PHI + 2)
167
+ @scayl = 46
168
+ when 6
169
+ @name = 'Cuboctahedron:'
170
+ @notes = format("%s %d triangles, 6 squares\nVertices 12\nEdges 24", TYPE, 8)
171
+ permutations(1, 0, 1)
172
+ @len_edge = ROOT2
173
+ @scayl = 170
174
+ when 7
175
+ @name = 'Truncated Cube:'
176
+ @notes = format("%s %d triangles, 6 octogons\nVertices 24\nEdges 36", TYPE, 8)
177
+ permutations(ROOT2 - 1, 1, 1)
178
+ @len_edge = 2 * (ROOT2 - 1)
179
+ @scayl = 155
180
+ when 8
181
+ @name = 'Truncated Octahedron:'
182
+ @notes = format("%s %d squares, 8 hexagons\nVertices 24\nEdges 36", TYPE, 6)
183
+ permutations(0, 1, 2)
184
+ permutations(2, 1, 0)
185
+ @len_edge = ROOT2
186
+ @scayl = 100
187
+ when 9
188
+ @name = 'Rhombicuboctahedron:'
189
+ @notes = format("%s %d triangles, 18 squares\nVertices 24\nEdges 48", TYPE, 8)
190
+ permutations(ROOT2 + 1, 1, 1)
191
+ @len_edge = 2
192
+ @scayl = 80
193
+ when 10
194
+ @name = 'Truncated Cuboctahedron:'
195
+ @notes = format("%s %d squares, 8 hexagons, 6 octogons\nVertices 48\nEdges 72", TYPE, 12)
196
+ permutations(ROOT2 + 1, 2 * ROOT2 + 1, 1)
197
+ permutations(ROOT2 + 1, 1, 2 * ROOT2 + 1)
198
+ @len_edge = 2
199
+ @scayl = 50
200
+ when 11
201
+ @name = 'Icosidodecahedron:'
202
+ @notes = format("%s %d triangles, 12 pentagons\nVertices 30\nEdges 60", TYPE, 20)
203
+ permutations(0, 0, 2 * PHI)
204
+ permutations(1, PHI, PHI_SQ)
205
+ @len_edge = 2
206
+ @scayl = 70
207
+ when 12
208
+ @name = 'Truncated Dodecahedron:'
209
+ @notes = format("%s %d triangles, 12 decagons\nVertices 60\nEdges 90", TYPE, 20)
210
+ permutations(0, 1 / PHI, PHI + 2)
211
+ permutations(1 / PHI, PHI, 2 * PHI)
212
+ permutations(PHI, 2, PHI_SQ)
213
+ @len_edge = 2 * (PHI - 1)
214
+ @scayl = 60
215
+ when 13
216
+ @name = 'Truncated Icosahedron:'
217
+ @notes = format("%s %d pentagons, 20 hexagons\nVertices 60\nEdges 90", TYPE, 12)
218
+ permutations(0, 1, 3 * PHI)
219
+ permutations(2, 2 * PHI + 1, PHI)
220
+ permutations(1, PHI + 2, 2 * PHI)
221
+ @len_edge = 2
222
+ @scayl = 45
223
+ when 14
224
+ @name = 'Small Rhombicosidodecahedron:'
225
+ @notes = format("%s %d triangles, 30 squares, 12 pentagons\nVertices 60\nEdges 120", TYPE, 20)
226
+ permutations(1, 1, PHI_CU)
227
+ permutations(PHI_SQ, PHI, 2 * PHI)
228
+ permutations(PHI + 2, 0, PHI_SQ)
229
+ @len_edge = 2
230
+ @scayl = 50
231
+ when 15
232
+ @name = 'Great Rhombicosidodecahedron:'
233
+ @notes = format("%s %d squares, 20 hexagons, 12 decagons\nVertices 120\nEdges 180", TYPE, 30)
234
+ permutations(1 / PHI, 1 / PHI, PHI + 3)
235
+ permutations(2 / PHI, PHI, 2 * PHI + 1)
236
+ permutations(1 / PHI, PHI_SQ, 3 * PHI - 1)
237
+ permutations(2 * PHI - 1, 2, PHI + 2)
238
+ permutations(PHI, 3, 2 * PHI)
239
+ @len_edge = 2 * PHI - 2
240
+ @scayl = 48
241
+ else # start again
242
+ @curr_id = 0
243
+ create_poly(curr_id)
244
+ end
245
+ end
246
+ end
247
+
248
+ Polyhedrons.new title: 'Polyhedrons'
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ # Adapted to use Propane Vec2D and Vec3D classes by Martin Prout
4
+
5
+ # Use Face Struct triangle 'mesh'.
6
+ Face = Struct.new(:a, :b, :c) # triangle mesh face
7
+ require 'propane'
8
+
9
+ # Monkey patch the Vec3D class to support rotations
10
+ Vec3D.class_eval do # re-open the Vec3D class to add the rotate methods
11
+ def rotate_y!(theta)
12
+ co = Math.cos(theta)
13
+ si = Math.sin(theta)
14
+ xx = co * x - si * z
15
+ self.z = si * x + co * z
16
+ self.x = xx
17
+ self
18
+ end
19
+
20
+ def rotate_x!(theta)
21
+ co = Math.cos(theta)
22
+ si = Math.sin(theta)
23
+ zz = co * z - si * y
24
+ self.y = si * z + co * y
25
+ self.z = zz
26
+ self
27
+ end
28
+ end
29
+
30
+ # After a toxiclibs "MeshDoodle" sketch by Karsten Schmidt
31
+ class Doodle < Propane::App
32
+ attr_reader :prev, :p, :q, :rotation, :faces, :pos, :weight
33
+
34
+ def setup
35
+ size(600, 600, P3D)
36
+ @weight = 0
37
+ @prev = Vec3D.new
38
+ @p = Vec3D.new
39
+ @q = Vec3D.new
40
+ @rotation = Vec2D.new
41
+ @faces = []
42
+ end
43
+
44
+ def draw
45
+ background(0)
46
+ lights
47
+ translate(width / 2, height / 2, 0)
48
+ rotate_x(rotation.x)
49
+ rotate_y(rotation.y)
50
+ no_stroke
51
+ begin_shape(TRIANGLES)
52
+ # iterate over all faces/triangles of the 'mesh'
53
+ faces.each do |f|
54
+ # create vertices for each corner point
55
+ f.a.to_vertex(renderer)
56
+ f.b.to_vertex(renderer)
57
+ f.c.to_vertex(renderer)
58
+ end
59
+ end_shape
60
+ # update rotation
61
+ @rotation += Vec2D.new(0.014, 0.0237)
62
+ end
63
+
64
+ def mouse_moved
65
+ # get 3D rotated mouse position
66
+ @pos = Vec3D.new(mouse_x - width / 2, mouse_y - height / 2, 0)
67
+ pos.rotate_x!(rotation.x)
68
+ pos.rotate_y!(rotation.y)
69
+ # use distance to previous point as target stroke weight
70
+ @weight += (sqrt(pos.dist(prev)) * 2 - weight) * 0.1
71
+ # define offset points for the triangle strip
72
+ a = pos + Vec3D.new(0, 0, weight)
73
+ b = pos + Vec3D.new(0, 0, -weight)
74
+ # add 2 faces to the mesh
75
+ faces << Face.new(p, b, q)
76
+ faces << Face.new(p, a, b)
77
+ # store current points for next iteration
78
+ @prev = pos
79
+ @p = a
80
+ @q = b
81
+ end
82
+
83
+ # An example of AppRenderer usage for Vec3D => vertex conversion
84
+ def renderer
85
+ @renderer ||= Propane::Render::AppRender.new(self)
86
+ end
87
+ end
88
+
89
+ Doodle.new title: 'Ribbon Doodle'
@@ -0,0 +1,36 @@
1
+ #
2
+ # Vector
3
+ # by Daniel Shiffman.
4
+ # PVector was used in the original (instead of Vec2D)
5
+ # Demonstration some basic vector math: subtraction, normalization, scaling
6
+ # Normalizing a vector sets its length to 1.
7
+ #
8
+ require 'propane'
9
+
10
+ class VectorMath < Propane::App
11
+
12
+ def setup
13
+ size(640, 360)
14
+ stroke(255)
15
+ stroke_weight(4)
16
+ end
17
+
18
+ def draw
19
+ background(0)
20
+ # A vector that points to the mouse location
21
+ mouse = Vec2D.new(mouse_x, mouse_y)
22
+ # A vector that points to the center of the window
23
+ center = Vec2D.new(width/2, height/2)
24
+ # Subtract center from mouse which results in a vector that points from center to mouse
25
+ mouse -= center
26
+ # Normalize the vector
27
+ mouse.normalize!
28
+ # Multiply its length by 150 (Scaling its length)
29
+ mouse *= 150
30
+ translate(width / 2,height / 2)
31
+ # Draw the resulting vector
32
+ line(0, 0, mouse.x, mouse.y)
33
+ end
34
+ end
35
+
36
+ VectorMath.new title: 'Vector Math'