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,30 +0,0 @@
1
- #define PROCESSING_COLOR_SHADER
2
-
3
- uniform vec2 resolution;
4
- uniform float time;
5
-
6
- void main(void) {
7
- vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
8
- float a = time*40.0;
9
- float d,e,f,g=1.0/40.0,h,i,r,q;
10
- e=400.0*(p.x*0.5+0.5);
11
- f=400.0*(p.y*0.5+0.5);
12
- i=200.0+sin(e*g+a/150.0)*20.0;
13
- d=200.0+cos(f*g/2.0)*18.0+cos(e*g)*7.0;
14
- r=sqrt(pow(i-e,2.0)+pow(d-f,2.0));
15
- q=f/r;
16
- e=(r*cos(q))-a/2.0;f=(r*sin(q))-a/2.0;
17
- d=sin(e*g)*176.0+sin(e*g)*164.0+r;
18
- h=((f+d)+a/2.0)*g;
19
- i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.0)*(r+h/3.0);
20
- h=sin(f*g)*144.0-sin(e*g)*212.0*p.x;
21
- h=(h+(f-e)*q+sin(r-(a+h)/7.0)*10.0+i/4.0)*g;
22
- i+=cos(h*2.3*sin(a/350.0-q))*184.0*sin(q-(r*4.3+a/12.0)*g)+tan(r*g+h)*184.0*cos(r*g+h);
23
- i=mod(i/5.6,256.0)/64.0;
24
- if(i<0.0) i+=4.0;
25
- if(i>=2.0) i=4.0-i;
26
- d=r/350.0;
27
- d+=sin(d*d*8.0)*0.52;
28
- f=(sin(a*g)+1.0)/2.0;
29
- gl_FragColor=vec4(vec3(f*i/1.6,i/2.0+d/13.0,i)*d*p.x+vec3(i/1.3+d/8.0,i/2.0+d/18.0,i)*d*(1.0-p.x),1.0);
30
- }
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env jruby -v -W2
2
- # frozen_string_literal: true
3
- require 'propane'
4
- # Edge Detection.
5
- #
6
- # A high-pass filter sharpens an image. This program analyzes every
7
- # pixel in an image in relation to the neighboring pixels to sharpen
8
- # the image.
9
- class EdgeDetection < Propane::App
10
- KERNEL = [[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]].freeze
11
- attr_reader :img
12
-
13
- def setup
14
- size(640, 360)
15
- @img = load_image(File.expand_path('./data/moon.jpg')) # Load the original image
16
- no_loop
17
- end
18
-
19
- def draw
20
- image(img, 0, 0) # Displays the image from point (0,0)
21
- img.load_pixels
22
- # Create an opaque image of the same size as the original
23
- edge_img = create_image(img.width, img.height, RGB)
24
- # Loop through every pixel in the image
25
- (1...img.height - 1).each do |y|
26
- (1...img.width - 1).each do |x|
27
- sum = 0 # Kernel sum for this pixel
28
- (-1..1).each do |ky|
29
- (-1..1).each do |kx|
30
- # Calculate the adjacent pixel for this kernel point
31
- pos = (y + ky) * img.width + (x + kx)
32
- # Image is grayscale, red/green/blue are identical
33
- val = red(img.pixels[pos])
34
- # Multiply adjacent pixels based on the kernel values
35
- sum += KERNEL[ky + 1][kx + 1] * val
36
- end
37
- end
38
- # For this pixel in the new image, set the gray value
39
- # based on the sum from the kernel
40
- edge_img.pixels[y * img.width + x] = color(sum, sum, sum)
41
- end
42
- end
43
- # State that there are changes to edge_img.pixels[]
44
- edge_img.update_pixels
45
- image(edge_img, width / 2, 0) # Draw the new image
46
- end
47
- end
48
-
49
- EdgeDetection.new title: 'Edge Detection'
@@ -1,125 +0,0 @@
1
- #!/usr/bin/env jruby -v -W2
2
- # frozen_string_literal: true
3
- # Noise-Based GLSL Heightmap by Amnon Owed (May 2013)
4
- # https://github.com/AmnonOwed
5
- # http://vimeo.com/amnon
6
- #
7
- # Creating a GLSL heightmap running on shader-based procedural noise.
8
- #
9
- # c = cycle through the color maps
10
- #
11
- # Tested with propane-0.8.0
12
- #
13
- # Photographs by Folkert Gorter (@folkertgorter / http://superfamous.com/) made available under a CC Attribution 3.0 license.
14
-
15
- require 'propane'
16
-
17
- class HeightMap < Propane::App
18
- include Propane::Render
19
- SHADERS = %w(displaceFrag.glsl displaceVert.glsl).freeze
20
- SHADER_NAME = %i(frag vert).freeze
21
- DIM = 300 # the grid dimensions of the heightmap
22
- attr_reader :blur_factor # the blur for the displacement map
23
- attr_reader :resize_factor # the resize factor for the displacement map
24
- attr_reader :displace_strength
25
- attr_reader :positions
26
- attr_reader :tex_coords
27
- attr_reader :height_map # PShape holds the geometry, textures etc.
28
- attr_reader :displace # GLSL shader
29
- attr_reader :images # array to hold 2 input images
30
- attr_reader :color_map # variable to keep track of the current colorMap
31
-
32
- def setup
33
- size(1280, 720, P3D) # use the P3D OpenGL renderer
34
- @blur_factor = 3
35
- @resize_factor = 0.25
36
- displace_strength = 0.25 # the displace strength of the GLSL shader displacement effect
37
- # load the images from the _Images folder (relative path from this sketch's folder)
38
- textures = %w(Texture01.jpg Texture02.jpg)
39
- glsl_files = SHADERS.map { |shade| File.expand_path("./data/#{shade}") }
40
- shaders = SHADER_NAME.zip(glsl_files.to_java(:string)).to_h
41
- @images = textures.map { |texture| load_image(File.expand_path("./data/#{texture}")) }
42
- @color_map = 0
43
- # load the PShader with a fragment and a vertex shader
44
- @displace = load_shader(shaders[:frag], shaders[:vert])
45
- displace.set('displaceStrength', displace_strength) # set the displace_strength
46
- displace.set('colorMap', images[color_map]) # set the initial colorMap
47
- # create the heightmap PShape (see custom creation method) and put it in the global height_map reference
48
- @height_map = create_plane(DIM, DIM)
49
- end
50
-
51
- def draw
52
- # required for texLight shader
53
- pointLight(255, 255, 255, 2 * (mouse_x - width / 2), 2 * (mouse_y - height / 2), 500)
54
- translate(width / 2, height / 2) # translate to center of the screen
55
- rotate_x(60.radians) # fixed rotation of 60 degrees over the X axis
56
- rotate_z(frame_count * 0.005) # dynamic frameCount-based rotation over the Z axis
57
- background(0) # black background
58
- perspective(PI/3.0, width.to_f / height, 0.1, 1_000_000) # perspective for close shapes
59
- scale(750) # scale by 750 (the model itself is unit length
60
- displace.set('time', millis / 5_000.0) # feed time to the GLSL shader
61
- shader(displace) # use shader
62
- shape(height_map) # display the PShape
63
- end
64
-
65
- # custom method to create a PShape plane with certain xy DIMensions
66
- def create_plane(xsegs, ysegs)
67
- # STEP 1: create all the relevant data
68
-
69
- @positions = [] # arrayList to hold positions
70
- @tex_coords = [] # arrayList to hold texture coordinates
71
-
72
- usegsize = 1 / xsegs.to_f # horizontal stepsize
73
- vsegsize = 1 / ysegs.to_f # vertical stepsize
74
-
75
- xsegs.times do |x|
76
- ysegs.times do |y|
77
- u = x / xsegs.to_f
78
- v = y / ysegs.to_f
79
-
80
- # generate positions for the vertices of each cell
81
- # (-0.5 to center the shape around the origin)
82
- positions << Vec3D.new(u - 0.5, v - 0.5, 0)
83
- positions << Vec3D.new(u + usegsize - 0.5, v - 0.5, 0)
84
- positions << Vec3D.new(u + usegsize - 0.5, v + vsegsize - 0.5, 0)
85
- positions << Vec3D.new(u - 0.5, v + vsegsize - 0.5, 0)
86
-
87
- # generate texture coordinates for the vertices of each cell
88
- tex_coords << Vec2D.new(u, v)
89
- tex_coords << Vec2D.new(u + usegsize, v)
90
- tex_coords << Vec2D.new(u + usegsize, v + vsegsize)
91
- tex_coords << Vec2D.new(u, v + vsegsize)
92
- end
93
- end
94
-
95
- # STEP 2: put all the relevant data into the PShape
96
-
97
- texture_mode(NORMAL) # set texture_mode to normalized (range 0 to 1)
98
- tex = images[0]
99
-
100
- mesh = create_shape # create the initial PShape
101
- renderer = ShapeRender.new(mesh) # initialize the shape renderer
102
- mesh.begin_shape(QUADS) # define the PShape type: QUADS
103
- mesh.no_stroke
104
- mesh.texture(tex) # set a texture to make a textured PShape
105
- # put all the vertices, uv texture coordinates and normals into the PShape
106
- positions.each_with_index do |p, i|
107
- p.to_vertex_uv(renderer, tex_coords[i]) # NB: tex_coords as Vec2D
108
- # p.to_vertex_uv(renderer, u, v) # u, v as floats is the alternate form
109
- end
110
- mesh.end_shape
111
- mesh # our work is done here, return DA MESH! -)
112
- end
113
-
114
- def key_released
115
- case key
116
- when '1', '2'
117
- @color_map = key.to_i - 1 # images.size for more than two
118
- displace.set('colorMap', images[color_map])
119
- else
120
- puts format('key pressed: %s', key)
121
- end # cycle through colorMaps (set variable and set colorMap in PShader)
122
- end
123
- end
124
-
125
- HeightMap.new title: 'Height Map'
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env jruby -v -W2
2
- # frozen_string_literal: true
3
- # From the Processing Examples
4
- # by Zach Lieberman
5
-
6
- WORDS = %w(sometimes\ it's\ like the\ lines\ of\ text are\ so\ happy
7
- that\ they\ want\ to\ dance or\ leave\ the\ page\ or\ jump
8
- can\ you\ blame\ them? living\ on\ the\ page\ like\ that
9
- waiting\ to\ be\ read...)
10
-
11
- require 'propane' # temporary local
12
-
13
- # dispay them 'words'
14
- class KineticType < Propane::App
15
-
16
- def setup
17
- size(200, 200, P3D)
18
- frame_rate 30
19
- # Load the font from the sketch's data directory.
20
- text_font load_font(File.expand_path('./data/Univers45.vlw')), 1.0
21
- fill 255
22
- # Creating the line objects
23
- @lines = WORDS.map.with_index { |word, i| Line.new(self, word, 0, i * 70) }
24
- end
25
-
26
- def draw
27
- background 0
28
- translate(-240, -120, -450)
29
- rotate_y 0.3
30
- # Now animate every line object & draw it...
31
- @lines.each_with_index do |line, i|
32
- push_matrix
33
- translate 0.0, line.ypos, 0.0
34
- line.draw(i)
35
- pop_matrix
36
- end
37
- end
38
- end
39
-
40
-
41
- class Line
42
- attr_accessor :app, :string, :xpos, :ypos, :letters
43
-
44
- def initialize(app, string, x, y)
45
- @app, @string, @xpos, @ypos = app, string, x, y
46
- spacing = 0.0
47
- @letters = string.split('').map do |c|
48
- spacing += app.text_width(c)
49
- Letter.new(c, spacing, 0.0)
50
- end
51
- end
52
-
53
- def compute_curve(line_num)
54
- base = app.millis / 10_000.0 * Math::PI * 2
55
- Math.sin((line_num + 1.0) * base) * Math.sin((8.0 - line_num) * base)
56
- end
57
-
58
- def draw(line_num)
59
- curve = compute_curve(line_num)
60
- letters.each_with_index do |letter, i|
61
- return if i < 0
62
- app.translate(app.text_width(letters[i - 1].char) * 75, 0.0, 0.0)
63
- app.rotate_y(curve * 0.035)
64
- app.push_matrix
65
- app.scale(75.0, 75.0, 75.0)
66
- app.text(letter.char, 0.0, 0.0)
67
- app.pop_matrix
68
- end
69
- end
70
- end
71
-
72
- class Letter
73
- attr_accessor :char, :x, :y
74
- def initialize(c, x, y)
75
- @char, @x, @y = c, x, y
76
- end
77
- end
78
-
79
- KineticType.new title: 'Kinetic Type'
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env jruby -v -W2
2
- # frozen_string_literal: true
3
- require 'propane'
4
-
5
- class Landscape < Propane::App
6
- #
7
- # Elevated
8
- # https://www.shadertoy.com/view/MdX3Rr by inigo quilez
9
- # Created by inigo quilez - iq/2013
10
- # License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
11
- # Processing port by Raphaël de Courville.
12
- #
13
- attr_reader :landscape
14
- java_alias :background_int, :background, [Java::int]
15
-
16
- def setup
17
- size(640, 360, P2D)
18
- no_stroke
19
- # The code of this shader shows how to integrate shaders from shadertoy
20
- # into Processing with minimal changes.
21
- @landscape = load_shader(File.expand_path('./data/landscape.glsl'))
22
- landscape.set('resolution', width.to_f, height.to_f)
23
- end
24
-
25
- def draw
26
- background_int 0
27
- landscape.set('time', (millis/1000.0).to_f)
28
- shader(landscape)
29
- rect(0, 0, width, height)
30
- frame.set_title("frame: #{frame_count} - fps: #{format('%0.2f', frame_rate)}")
31
- end
32
- end
33
-
34
- Landscape.new title: 'Landscape'
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env jruby -v -W2
2
- # frozen_string_literal: true
3
- require 'propane'
4
- # Linear Image.
5
- #
6
- # Click and drag mouse up and down to control the signal.
7
- #
8
- # Note in ruby-processing to access booleans use
9
- # mouse_pressed? and key_pressed?
10
- #
11
- # Press and hold any key to view the image scanning
12
- class LinearImage < Propane::App
13
- attr_reader :signal, :img, :direction
14
-
15
- def setup
16
- size(640, 360)
17
- stroke(255)
18
- @img = load_image(File.expand_path('./data/sea.jpg'))
19
- @direction = 1
20
- @signal = 0
21
- img.load_pixels
22
- load_pixels
23
- end
24
-
25
- def draw
26
- @direction = direction * -1 if signal > img.height - 1 || signal < 0
27
- if mouse_pressed?
28
- @signal = (mouse_y % img.height).abs
29
- else
30
- @signal += (0.3 * direction)
31
- end
32
- if key_pressed?
33
- set(0, 0, img)
34
- line(0, signal, img.width, signal)
35
- else
36
- signal_offset = signal.to_i * img.width
37
- (0...img.height).each do |y|
38
- java.lang.System.arraycopy(
39
- img.pixels.to_java,
40
- signal_offset,
41
- pixels,
42
- y * width,
43
- img.width
44
- )
45
- end
46
- update_pixels
47
- end
48
- end
49
- end
50
-
51
- LinearImage.new title: 'Linear Image'
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env jruby -v -W2
2
- # frozen_string_literal: true
3
- require 'propane'
4
-
5
- class Monjori < Propane::App
6
- ##
7
- # Monjori.
8
- #
9
- # GLSL version of the 1k intro Monjori from the demoscene
10
- # (http://www.pouet.net/prod.php?which=52761)
11
- # Ported from the webGL version available in ShaderToy:
12
- # http://www.iquilezles.org/apps/shadertoy/
13
- # (Look for Monjori under the Plane Deformations Presets)
14
-
15
- attr_reader :monjori
16
-
17
- def setup
18
- size(640, 360, P2D)
19
- no_stroke
20
- @monjori = load_shader(File.expand_path('./data/monjori.glsl'))
21
- monjori.set('resolution', width.to_f, height.to_f)
22
- end
23
-
24
- def draw
25
- monjori.set('time', millis / 1000.0)
26
- shader(monjori)
27
- # This kind of effects are entirely implemented in the
28
- # fragment shader, they only need a quad covering the
29
- # entire view area so every pixel is pushed through the
30
- # shader.
31
- rect(0, 0, width, height)
32
- end
33
- end
34
-
35
- Monjori.new title: 'Monjori'
@@ -1,30 +0,0 @@
1
- # Simple demo Rakefile to autorun samples in current directory
2
- # adjust path to rp5 executable, and or opts as required
3
-
4
- SAMPLES_DIR = './'
5
-
6
- desc 'run demo'
7
- task default: [:demo]
8
-
9
- desc 'demo'
10
- task :demo do
11
- samples_list.shuffle.each { |sample| run_sample sample }
12
- end
13
-
14
- def samples_list
15
- files = []
16
- Dir.chdir(SAMPLES_DIR)
17
- Dir.glob('*.rb').each do |file|
18
- files << File.join(SAMPLES_DIR, file)
19
- end
20
- return files
21
- end
22
-
23
- def run_sample(sample_name)
24
- puts "Running #{sample_name}...quit to run next sample"
25
- open("|jruby #{sample_name}", 'r') do |io|
26
- while l = io.gets
27
- puts(l.chop)
28
- end
29
- end
30
- end
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env jruby -v -w
2
- require 'arcball'
3
- require 'propane'
4
-
5
- ############################
6
- # Use mouse drag to rotate
7
- # The arcball. Use mousewheel
8
- # to zoom. Hold down x, y, z
9
- # to constrain rotation axis.
10
- ############################
11
-
12
- class ArcballBox < Propane::App
13
-
14
- def setup
15
- size(600, 600, P3D)
16
- smooth(8)
17
- Processing::ArcBall.init(self, 300, 300)
18
- fill 180
19
- end
20
-
21
- def draw
22
- background(50)
23
- box(300, 300, 300)
24
- end
25
-
26
- end
27
-
28
- ArcballBox.new title: 'ArcBall Box'