propane 0.8.0-java → 0.9.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -1
  3. data/README.md +1 -1
  4. data/lib/propane/app.rb +56 -55
  5. data/lib/propane/creators/sketch_writer.rb +7 -3
  6. data/lib/propane/helper_methods.rb +40 -29
  7. data/lib/propane/runner.rb +3 -2
  8. data/lib/propane/version.rb +1 -1
  9. data/pom.rb +1 -1
  10. data/pom.xml +1 -1
  11. data/vendors/Rakefile +31 -1
  12. metadata +2 -59
  13. data/examples/data_path/Rakefile +0 -32
  14. data/examples/data_path/bw_shader.rb +0 -47
  15. data/examples/data_path/data/Texture01.jpg +0 -0
  16. data/examples/data_path/data/Texture02.jpg +0 -0
  17. data/examples/data_path/data/Univers45.vlw +0 -0
  18. data/examples/data_path/data/bwfrag.glsl +0 -23
  19. data/examples/data_path/data/displaceFrag.glsl +0 -8
  20. data/examples/data_path/data/displaceVert.glsl +0 -201
  21. data/examples/data_path/data/lachoy.jpg +0 -0
  22. data/examples/data_path/data/landscape.glsl +0 -352
  23. data/examples/data_path/data/monjori.glsl +0 -30
  24. data/examples/data_path/data/moon.jpg +0 -0
  25. data/examples/data_path/data/sea.jpg +0 -0
  26. data/examples/data_path/edge_detection.rb +0 -49
  27. data/examples/data_path/glsl_heightmap_noise.rb +0 -125
  28. data/examples/data_path/kinetic_type.rb +0 -79
  29. data/examples/data_path/landscape.rb +0 -34
  30. data/examples/data_path/linear_image.rb +0 -51
  31. data/examples/data_path/monjori.rb +0 -35
  32. data/examples/regular/Rakefile +0 -30
  33. data/examples/regular/arcball_box.rb +0 -28
  34. data/examples/regular/arcball_constrain.rb +0 -29
  35. data/examples/regular/bezier_playground.rb +0 -206
  36. data/examples/regular/circle_collision.rb +0 -118
  37. data/examples/regular/colors_two.rb +0 -60
  38. data/examples/regular/creating_colors.rb +0 -64
  39. data/examples/regular/drawolver.rb +0 -93
  40. data/examples/regular/elegant_ball.rb +0 -159
  41. data/examples/regular/empathy.rb +0 -80
  42. data/examples/regular/fern.rb +0 -57
  43. data/examples/regular/fibonacci_sphere.rb +0 -91
  44. data/examples/regular/flight_patterns.rb +0 -64
  45. data/examples/regular/fractions.rb +0 -32
  46. data/examples/regular/grapher.rb +0 -40
  47. data/examples/regular/gravity.rb +0 -120
  48. data/examples/regular/grey_circles.rb +0 -28
  49. data/examples/regular/jwishy.rb +0 -99
  50. data/examples/regular/letters.rb +0 -42
  51. data/examples/regular/lib/boundary.rb +0 -38
  52. data/examples/regular/lib/particle.rb +0 -77
  53. data/examples/regular/lib/particle_system.rb +0 -111
  54. data/examples/regular/lib/rain_drops.rb +0 -54
  55. data/examples/regular/liquidy.rb +0 -41
  56. data/examples/regular/mouse_button_demo.rb +0 -32
  57. data/examples/regular/polyhedrons.rb +0 -249
  58. data/examples/regular/raining.rb +0 -60
  59. data/examples/regular/ribbon_doodle.rb +0 -89
  60. data/examples/regular/select_file.rb +0 -32
  61. data/examples/regular/select_image.rb +0 -40
  62. data/examples/regular/slider_demo.rb +0 -61
  63. data/examples/regular/slider_example.rb +0 -53
  64. data/examples/regular/slider_simple.rb +0 -47
  65. data/examples/regular/tree.rb +0 -76
  66. data/examples/regular/vector_math.rb +0 -37
  67. data/examples/regular/words.rb +0 -41
  68. data/lib/propane/helpers/string_extra.rb +0 -45
  69. data/lib/propane/underscorer.rb +0 -19
@@ -1,29 +0,0 @@
1
- #!/usr/bin//env jruby -v -w
2
-
3
- require 'propane'
4
- require 'arcball'
5
-
6
- ############################
7
- # Use mouse drag to rotate
8
- # the arcball. Use mousewheel
9
- # to zoom. Custom constrain
10
- # default is yaxis.
11
- ############################
12
-
13
- class ArcballBox < Propane::App
14
-
15
- def setup
16
- size(600, 600, P3D)
17
- smooth(8)
18
- Processing::ArcBall.constrain(self, :xaxis)
19
- fill 180
20
- end
21
-
22
- def draw
23
- background(50)
24
- box(300, 300, 300)
25
- end
26
-
27
- end
28
-
29
- ArcballBox.new title: 'ArcBall Box'
@@ -1,206 +0,0 @@
1
- #!/usr/bin/env jruby -v -w
2
- require 'propane'
3
-
4
- X1, Y1, X2, Y2 = 50.0, 50.0, 250.0, 250.0
5
- REDDISH = [250, 100, 100]
6
- RADIUS = 7
7
-
8
- module Olap
9
- def self.overlaps(x, y, point_x, point_y)
10
- Math.hypot(x - point_x, y - point_y) < RADIUS
11
- end
12
- end
13
-
14
- class Curve
15
- include Olap, Propane::Proxy
16
- attr_accessor :x1, :y1, :c1x, :c1y, :c2x, :c2y, :x2, :y2
17
-
18
- def initialize
19
- @x1, @y1, @x2, @y2 = X1, Y1, X2, Y2
20
- set_control_points(X1 + 30, Y1, X2 - 30, Y2)
21
- end
22
-
23
- def contains(x, y)
24
- return :one if Olap.overlaps(x1, y1, x, y)
25
- return :two if Olap.overlaps(x2, y2, x, y)
26
- end
27
-
28
- def all_points
29
- return x1, y1, c1x, c1y, c2x, c2y, x2, y2
30
- end
31
-
32
- def control_points
33
- return c1x, c1y, c2x, c2y
34
- end
35
-
36
- def set_control_points(*points)
37
- @c1x, @c1y, @c2x, @c2y = *points
38
- end
39
-
40
- def draw
41
- bezier(*all_points)
42
- ellipse x1, y1, 3, 3
43
- ellipse x2, y2, 3, 3
44
- end
45
-
46
- def print_equation(id)
47
- pt = all_points.map(&:to_i)
48
- puts ''
49
- puts format('*** line #%s ***', id)
50
- xformat = 'x = (1-t)^3 %s + 3(1-t)^2 t%s + 3(1-t)t^2 %s + t^3 %s'
51
- yformat = 'y = -1 * ((1-t)^3 %s + 3(1-t)^2 t%s + 3(1-t)t^2 %s + t^3 %s'
52
- puts format(xformat, pt[0], pt[2], pt[4], pt[6])
53
- puts format(yformat, pt[1], pt[3], pt[5], pt[7])
54
- puts ''
55
- end
56
- end
57
-
58
- class BezierPlayground < Propane::App
59
- # A Bezier playground. Click to shape the curve. Drag to move it.
60
- # Arrows toggle between curves, delete removes them.
61
- # You can print out the parametric equations for t = 0..1
62
-
63
- attr_accessor :curves, :c1x, :c1y, :c2x, :c2y
64
- attr_reader :panel, :hide
65
-
66
- load_library :control_panel
67
- include Olap
68
-
69
- def setup
70
- size 300, 300
71
- @curves = []
72
- @hide = false
73
- control_panel do |c|
74
- c.look_feel 'Nimbus'
75
- c.button :new_curve
76
- c.button :print_equations
77
- @panel = c
78
- end
79
- generate_curve
80
- end
81
-
82
- def draw
83
- unless hide
84
- panel.visible = visible
85
- @hide = true
86
- end
87
- background 50
88
- draw_control_tangent_lines
89
- draw_curves
90
- draw_current_control_points
91
- end
92
-
93
- def print_equations
94
- curves.each_with_index { |c, i| c.print_equation(i + 1) }
95
- end
96
-
97
- def control_points
98
- return c1x, c1y, c2x, c2y
99
- end
100
-
101
- def set_control_points(*points)
102
- @c1x, @c1y, @c2x, @c2y = points.any? ? points : [X1, Y1, X2, Y2]
103
- end
104
-
105
- def generate_curve
106
- curves << current_curve = Curve.new
107
- @current = curves.length - 1
108
- set_control_points(*current_curve.control_points)
109
- end
110
-
111
- def current_curve
112
- curves[@current]
113
- end
114
-
115
- def new_curve
116
- current_curve.set_control_points(c1x, c1y, c2x, c2y)
117
- generate_curve
118
- end
119
-
120
- def clicked_control_point?
121
- x, y = mouse_x, mouse_y
122
- return :one if Olap.overlaps(c1x, c1y, x, y)
123
- return :two if Olap.overlaps(c2x, c2y, x, y)
124
- end
125
-
126
- def mouse_pressed
127
- switch_curve_if_endpoint_clicked
128
- @control = clicked_control_point?
129
- return if @control
130
- curve = curves.detect { |c| c.contains(mouse_x, mouse_y) }
131
- @end_point = curve.contains(mouse_x, mouse_y) if curve
132
- end
133
-
134
- def mouse_released
135
- @control, @end_point = nil, nil
136
- @hide = false
137
- end
138
-
139
- def mouse_dragged
140
- offs = compute_offsets
141
- return if offs.map(&:abs).max > 100
142
- return move_control_point(*offs) if @control
143
- return move_end_point(*offs) && move_control_point(*offs) if @end_point
144
- move_current_curve(*offs)
145
- end
146
-
147
- def switch_curve_if_endpoint_clicked
148
- become = curves.detect { |c| c.contains(mouse_x, mouse_y) }
149
- return unless become && become != current_curve
150
- current_curve.set_control_points(*control_points)
151
- self.set_control_points(*become.control_points)
152
- @current = curves.index(become)
153
- end
154
-
155
- def move_current_curve(x_off, y_off)
156
- @c1x += x_off; @c2x += x_off
157
- @c1y += y_off; @c2y += y_off
158
- current_curve.set_control_points(*control_points)
159
- current_curve.x1 += x_off; current_curve.x2 += x_off
160
- current_curve.y1 += y_off; current_curve.y2 += y_off
161
- end
162
-
163
- def move_control_point(x_off, y_off)
164
- case @control || @end_point
165
- when :one then @c1x += x_off and @c1y += y_off
166
- when :two then @c2x += x_off and @c2y += y_off
167
- end
168
- current_curve.set_control_points(*control_points)
169
- end
170
-
171
- def move_end_point(x_off, y_off)
172
- c = current_curve
173
- case @end_point
174
- when :one then c.x1 += x_off and c.y1 += y_off
175
- when :two then c.x2 += x_off and c.y2 += y_off
176
- end
177
- end
178
-
179
- def compute_offsets
180
- return mouse_x - pmouse_x, mouse_y - pmouse_y
181
- end
182
-
183
- def draw_curves
184
- stroke 255
185
- no_fill
186
- stroke_width 2
187
- curves.each(&:draw)
188
- end
189
-
190
- def draw_current_control_points
191
- fill color(*REDDISH)
192
- no_stroke
193
- ellipse c1x, c1y, 5, 5
194
- ellipse c2x, c2y, 5, 5
195
- end
196
-
197
- def draw_control_tangent_lines
198
- c = current_curve
199
- stroke color(*REDDISH)
200
- stroke_width 1
201
- line c1x, c1y, c.x1, c.y1
202
- line c2x, c2y, c.x2, c.y2
203
- end
204
- end
205
-
206
- BezierPlayground.new title: 'Bezier Playground'
@@ -1,118 +0,0 @@
1
- #!/usr/bin/env jruby -v -w
2
- require 'propane'
3
-
4
- # Based on http://processing.org/learning/topics/circlecollision.html
5
- class CircleCollision < Propane::App
6
- attr_reader :balls
7
-
8
- def setup
9
- size 640, 360
10
- @balls = [Ball.new(100, 40, 20), Ball.new(200, 100, 80)]
11
- end
12
-
13
- def draw
14
- background(51)
15
- balls.each do |b|
16
- b.update
17
- b.display
18
- b.check_boundary width, height
19
- end
20
- balls[0].check_collision(balls[1])
21
- end
22
- end
23
-
24
- # The Ball class knows how to behave, their is a case for a separate boundary class
25
- class Ball
26
- include Propane::Proxy, Math
27
- attr_accessor :position, :r, :m, :velocity
28
-
29
- def initialize(x = 0.0, y = 0.0, r = 0.0)
30
- @position = Vec2D.new(x, y)
31
- @r = r
32
- @m = r * 0.1
33
- @velocity = Vec2D.new(rand(-3.0..3), rand(-3.0..3))
34
- end
35
-
36
- def update
37
- @position += velocity
38
- end
39
-
40
- def check_boundary(width, height)
41
- unless (r..width - r).include?(position.x)
42
- (position.x > width - r) ? position.x = width - r : position.x = r
43
- velocity.x *= -1
44
- end
45
- return if (r..height - r).include?(position.y)
46
- (position.y > height - r) ? position.y = height - r : position.y = r
47
- velocity.y *= -1
48
- end
49
-
50
- def check_collision(other_ball)
51
- # get distances between the balls components
52
- difference = other_ball.position - position
53
- # calculate magnitude of the vector separating the balls
54
- return unless difference.mag < (r + other_ball.r)
55
- # get angle of difference
56
- theta = difference.heading
57
- # precalculate trig values
58
- sine = sin(theta)
59
- cosine = cos(theta)
60
- # ball_array will hold rotated ball positions. You just
61
- # need to worry about ball_array[1] position
62
- ball_array = [Ball.new, Ball.new]
63
- # other_ball's position is relative to ball's
64
- # so you can use the vector between them (difference) as the
65
- # reference point in the rotation expressions.
66
- # ball_array[0].x and ball_array[0].y will initialize
67
- # automatically to 0.0, which is what you want
68
- # since other_ball will rotate around ball
69
- ball_array[1].position.x = cosine * difference.x + sine * difference.y
70
- ball_array[1].position.y = cosine * difference.y - sine * difference.x
71
- # rotate Temporary velocities
72
- velocity_array = [Vec2D.new, Vec2D.new]
73
- velocity_array[0].x = cosine * velocity.x + sine * velocity.y
74
- velocity_array[0].y = cosine * velocity.y - sine * velocity.x
75
- velocity_array[1].x = cosine * other_ball.velocity.x + sine * other_ball.velocity.y
76
- velocity_array[1].y = cosine * other_ball.velocity.y - sine * other_ball.velocity.x
77
- # Now that velocities are rotated, you can use 1D
78
- # conservation of momentum equations to calculate
79
- # the final velocity along the x-axis.
80
- final_velocities = [Vec2D.new, Vec2D.new]
81
- # final rotated velocity for ball
82
- final_velocities[0].x = ((m - other_ball.m) * velocity_array[0].x + 2 * other_ball.m * velocity_array[1].x) / (m + other_ball.m)
83
- final_velocities[0].y = velocity_array[0].y
84
- # final rotated velocity for ball
85
- final_velocities[1].x = ((other_ball.m - m) * velocity_array[1].x + 2 * m * velocity_array[0].x) / (m + other_ball.m)
86
- final_velocities[1].y = velocity_array[1].y
87
- # HACK: to avoid clumping
88
- # ball_array[0].position.x += final_velocities[0].x
89
- # ball_array[1].position.x += final_velocities[1].x
90
- # Rotate ball positions and velocities back
91
- # Reverse signs in trig expressions to rotate
92
- # in the opposite direction
93
- # rotate balls
94
- final_positions = [Vec2D.new, Vec2D.new]
95
- final_positions[0].x = cosine * ball_array[0].position.x - sine * ball_array[0].position.y
96
- final_positions[0].y = cosine * ball_array[0].position.y + sine * ball_array[0].position.x
97
- final_positions[1].x = cosine * ball_array[1].position.x - sine * ball_array[1].position.y
98
- final_positions[1].y = cosine * ball_array[1].position.y + sine * ball_array[1].position.x
99
- # update balls to screen position
100
- other_ball.position = position + final_positions[1]
101
- @position += final_positions[0]
102
- # update velocities
103
- velocity.x = cosine * final_velocities[0].x - sine * final_velocities[0].y
104
- velocity.y = cosine * final_velocities[0].y + sine * final_velocities[0].x
105
- other_ball.velocity.x = cosine * final_velocities[1].x - sine * final_velocities[1].y
106
- other_ball.velocity.y = cosine * final_velocities[1].y + sine * final_velocities[1].x
107
- end
108
-
109
- def display
110
- no_stroke
111
- fill(204)
112
- ellipse(position.x, position.y, r * 2, r * 2)
113
- end
114
- end
115
-
116
-
117
-
118
- CircleCollision.new title: 'Circle Collision'
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env jruby -v -w
2
- # Creating Colors (Homage to Albers).
3
- #
4
- require 'propane'
5
-
6
- # Creating variables for colors that may be referred to
7
- # in the program by their name, rather than a number.
8
- class CreatingColors < Propane::App
9
- attr_reader :redder, :yellower, :orangish
10
- def setup
11
- size 640, 360
12
- # palette = web_to_color_array(['#CC6600', '#CC9900', '#993300'].to_java(:string))
13
- palette = web_to_color_array(['#CC6600', '#CC9900', '#993300'])
14
- # @redder = color 204, 102, 0
15
- # @yellower = color 204, 153, 0
16
- # @orangish = color 153, 51, 0
17
- # These statements are equivalent to the statements above.
18
- # Programmers may use the format they prefer.
19
-
20
- # hex color as a String (NB quotes are required)
21
- @redder = palette[0]
22
- @yellower = palette[1]
23
- @orangish = palette[2]
24
-
25
- # @redder = color '#CC6600'
26
- # @yellower = color '#CC9900'
27
- # @orangish = color '#993300'
28
-
29
- # or alternatively as a hexadecimal
30
-
31
- # @redder = color 0xFFCC6600
32
- # @yellower = color 0xFFCC9900
33
- # @orangish = color 0xFF993300
34
- end
35
-
36
- def draw
37
- no_stroke
38
- background 51, 0, 0
39
- push_matrix
40
- translate 80, 80
41
- fill orangish
42
- rect 0, 0, 200, 200
43
- fill yellower
44
- rect 40, 60, 120, 120
45
- fill redder
46
- rect 60, 90, 80, 80
47
- pop_matrix
48
- push_matrix
49
- translate 360, 80
50
- fill redder
51
- rect 0, 0, 200, 200
52
- fill orangish
53
- rect 40, 60, 120, 120
54
- fill yellower
55
- rect 60, 90, 80, 80
56
- pop_matrix
57
- end
58
- end
59
-
60
- CreatingColors.new title: 'Homage to Albers'
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env jruby -v -w
2
- # frozen_string_literal: true
3
- # Creating Colors (Homage to Albers).
4
- #
5
- require 'propane'
6
-
7
- # Creating variables for colors that may be referred to
8
- # in the program by their name, rather than a number.
9
- class CreatingColors < Propane::App
10
- attr_reader :redder, :yellower, :orangish
11
-
12
- WEB = %w(#CC6600 #CC9900 #993300)
13
-
14
- def setup
15
- size 640, 360
16
- palette = web_to_color_array(WEB)
17
- @redder = palette[0]
18
- @yellower = palette[1]
19
- @orangish = palette[2]
20
- # These statements are equivalent to the statements above.
21
- # Programmers may use the format they prefer.
22
-
23
- # hex color as a String (NB quotes are required)
24
- @redder = palette[0]
25
- @yellower = palette[1]
26
- @orangish = palette[2]
27
-
28
- # @redder = color '#CC6600'
29
- # @yellower = color '#CC9900'
30
- # @orangish = color '#993300'
31
-
32
- # or alternatively as a hexadecimal
33
-
34
- # @redder = color 0xFFCC6600
35
- # @yellower = color 0xFFCC9900
36
- # @orangish = color 0xFF993300
37
- puts int_to_ruby_colors(palette)
38
- end
39
-
40
- def draw
41
- no_stroke
42
- background 51, 0, 0
43
- push_matrix
44
- translate 80, 80
45
- fill orangish
46
- rect 0, 0, 200, 200
47
- fill yellower
48
- rect 40, 60, 120, 120
49
- fill redder
50
- rect 60, 90, 80, 80
51
- pop_matrix
52
- push_matrix
53
- translate 360, 80
54
- fill redder
55
- rect 0, 0, 200, 200
56
- fill orangish
57
- rect 40, 60, 120, 120
58
- fill yellower
59
- rect 60, 90, 80, 80
60
- pop_matrix
61
- end
62
- end
63
-
64
- CreatingColors.new title: 'Homage to Albers'