propane 0.7.0-java → 0.8.0-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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -3
  3. data/CHANGELOG.md +2 -0
  4. data/README.md +3 -5
  5. data/examples/{complete → data_path}/Rakefile +2 -2
  6. data/examples/{complete → data_path}/bw_shader.rb +7 -6
  7. data/examples/{complete → data_path}/data/Texture01.jpg +0 -0
  8. data/examples/{complete → data_path}/data/Texture02.jpg +0 -0
  9. data/examples/{complete → data_path}/data/Univers45.vlw +0 -0
  10. data/examples/{complete → data_path}/data/bwfrag.glsl +0 -0
  11. data/examples/{complete → data_path}/data/displaceFrag.glsl +0 -0
  12. data/examples/{complete → data_path}/data/displaceVert.glsl +0 -0
  13. data/examples/{complete → data_path}/data/lachoy.jpg +0 -0
  14. data/examples/{complete → data_path}/data/landscape.glsl +0 -0
  15. data/examples/{complete → data_path}/data/monjori.glsl +0 -0
  16. data/examples/{complete → data_path}/data/moon.jpg +0 -0
  17. data/examples/{complete → data_path}/data/sea.jpg +0 -0
  18. data/examples/{complete → data_path}/edge_detection.rb +2 -2
  19. data/examples/{complete → data_path}/glsl_heightmap_noise.rb +9 -5
  20. data/examples/{complete → data_path}/kinetic_type.rb +5 -5
  21. data/examples/{complete → data_path}/landscape.rb +11 -9
  22. data/examples/{complete → data_path}/linear_image.rb +2 -2
  23. data/examples/{complete → data_path}/monjori.rb +7 -5
  24. data/examples/regular/arcball_box.rb +3 -13
  25. data/examples/regular/arcball_constrain.rb +12 -21
  26. data/examples/regular/bezier_playground.rb +32 -31
  27. data/examples/regular/circle_collision.rb +9 -9
  28. data/examples/regular/colors_two.rb +2 -1
  29. data/examples/regular/creating_colors.rb +2 -2
  30. data/examples/regular/drawolver.rb +1 -0
  31. data/examples/regular/elegant_ball.rb +1 -1
  32. data/examples/regular/empathy.rb +11 -10
  33. data/examples/regular/fern.rb +1 -0
  34. data/examples/regular/fibonacci_sphere.rb +1 -0
  35. data/examples/regular/flight_patterns.rb +6 -5
  36. data/examples/regular/fractions.rb +1 -0
  37. data/examples/regular/grapher.rb +6 -5
  38. data/examples/regular/gravity.rb +17 -17
  39. data/examples/regular/grey_circles.rb +2 -2
  40. data/examples/regular/jwishy.rb +5 -6
  41. data/examples/regular/letters.rb +19 -19
  42. data/examples/regular/liquidy.rb +5 -4
  43. data/examples/regular/mouse_button_demo.rb +5 -7
  44. data/examples/regular/polyhedrons.rb +1 -0
  45. data/examples/regular/raining.rb +6 -5
  46. data/examples/regular/ribbon_doodle.rb +1 -1
  47. data/examples/regular/select_file.rb +32 -0
  48. data/examples/regular/select_image.rb +40 -0
  49. data/examples/regular/slider_demo.rb +2 -1
  50. data/examples/regular/slider_example.rb +1 -1
  51. data/examples/regular/slider_simple.rb +1 -1
  52. data/examples/regular/tree.rb +7 -6
  53. data/lib/propane/creators/sketch_writer.rb +66 -0
  54. data/lib/propane/library_loader.rb +1 -5
  55. data/lib/propane/runner.rb +4 -3
  56. data/lib/propane/version.rb +1 -1
  57. data/library/file_chooser/chooser.rb +20 -0
  58. data/library/file_chooser/file_chooser.rb +20 -0
  59. data/pom.rb +1 -1
  60. data/pom.xml +1 -1
  61. data/propane.gemspec +1 -1
  62. data/src/monkstone/MathToolModule.java +63 -47
  63. data/src/monkstone/filechooser/Chooser.java +44 -0
  64. data/test/create_test.rb +48 -0
  65. metadata +30 -23
  66. data/lib/propane/creators/creator.rb +0 -136
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env jruby -v -W2
1
2
  require 'propane'
2
3
  require 'pbox2d'
3
4
  require_relative 'lib/particle_system'
@@ -7,7 +8,7 @@ Vect = Struct.new(:x, :y)
7
8
 
8
9
  class Liquidy < Propane::App
9
10
  attr_reader :box2d, :boundaries, :systems
10
-
11
+
11
12
  def setup
12
13
  size(400, 300)
13
14
  @box2d = WorldBuilder.build(app: self, gravity: [0, -20])
@@ -17,7 +18,7 @@ class Liquidy < Propane::App
17
18
  Boundary.new(box2d, Vect.new(250, 175), Vect.new(300, 5), 0.5)
18
19
  ]
19
20
  end
20
-
21
+
21
22
  def draw
22
23
  background(255)
23
24
  # Run all the particle systems
@@ -30,11 +31,11 @@ class Liquidy < Propane::App
30
31
  # Display all the boundaries
31
32
  boundaries.each(&:display)
32
33
  end
33
-
34
+
34
35
  def mouse_pressed
35
36
  # Add a new Particle System whenever the mouse is clicked
36
37
  systems << ParticleSystem.new(box2d, 0, mouse_x, mouse_y)
37
- end
38
+ end
38
39
  end
39
40
 
40
41
  Liquidy.new title: 'Liquidy'
@@ -1,23 +1,21 @@
1
- # encoding: utf-8
1
+ #!/usr/bin/env jruby -v -W2
2
2
  # frozen_string_literal: true
3
3
 
4
- #
5
- require_relative '../../lib/propane' # temporary local
6
-
4
+ require_relative 'propane'
7
5
  # Demo of Mouse Button
8
6
  class MouseButtonDemo < Propane::App
9
7
  # Click within the image and press
10
- # the left and right mouse buttons to
8
+ # the left and right mouse buttons to
11
9
  # change the value of the rectangle
12
10
  def setup
13
11
  size 300, 200
14
12
  end
15
-
13
+
16
14
  def draw
17
15
  rect(25, 25, 150, 80)
18
16
  end
19
17
 
20
- def mouse_pressed
18
+ def mouse_pressed
21
19
  case mouse_button
22
20
  when LEFT
23
21
  fill 0
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env jruby -v -W2
1
2
  ###
2
3
  # Polyhedrons after sketch by Chinchbug on openprocessing.org
3
4
  ###
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env jruby -v -W2
1
2
  require 'propane'
2
3
  require_relative 'lib/rain_drops'
3
4
 
@@ -15,12 +16,12 @@ class Raining < Propane::App
15
16
  #
16
17
  # License: Same as processing
17
18
  #
18
-
19
+
19
20
  attr_reader :drops, :weight, :drops_size, :paused
20
-
21
+
21
22
  def setup
22
23
  size 640, 480
23
- frame_rate 30
24
+ frame_rate 30
24
25
  @drops_size = 20
25
26
  @weight = 20
26
27
  @drops = RainDrops.new width, height
@@ -28,7 +29,7 @@ class Raining < Propane::App
28
29
  font = create_font('Georgia', 15)
29
30
  text_font(font)
30
31
  end
31
-
32
+
32
33
  def draw
33
34
  return if paused
34
35
  # we fill up with new drops randomly
@@ -39,7 +40,7 @@ class Raining < Propane::App
39
40
  form = '%d of %d drops with a size of %d'
40
41
  text(format(form, drops.size, drops_size, weight), 10, 20)
41
42
  end
42
-
43
+
43
44
  def key_pressed
44
45
  case key
45
46
  when '+'
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ #!/usr/bin/env jruby -v -W2
2
2
  # frozen_string_literal: true
3
3
  # Adapted to use Propane Vec2D and Vec3D classes by Martin Prout
4
4
 
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env jruby -v -W2
2
+
3
+ ############################
4
+ # Use mouse drag to rotate
5
+ # The arcball. Use mousewheel
6
+ # to zoom. Hold down x, y, z
7
+ # to constrain rotation axis.
8
+ ############################
9
+
10
+ require 'propane'
11
+
12
+ class SelectFile < Propane::App
13
+
14
+ load_library :file_chooser
15
+ ###########
16
+ # Example Native File Chooser using vanilla processing
17
+ # select_input, and file_selected
18
+ ###########
19
+
20
+ def setup
21
+ size 200, 100
22
+ # java_signature 'void selectInput(String, String)'
23
+ select_input('Select a File', 'file_selected')
24
+ end
25
+
26
+ # signature 'void file_selected(java.io.File file)'
27
+ def file_selected(file)
28
+ puts file.get_absolute_path unless file.nil?
29
+ end
30
+ end
31
+
32
+ SelectFile.new
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env jruby -v -W2
2
+
3
+ require 'propane'
4
+
5
+ class SelectImage < Propane::App
6
+
7
+ load_library :file_chooser
8
+ ###########
9
+ # Example Native File Chooser using vanilla processing
10
+ # select_input, and file_selected
11
+ ###########
12
+ attr_reader :img
13
+
14
+ def setup
15
+ size(400, 200)
16
+ fill 0, 0, 200
17
+ text('Click Window to Load Image', 10, 100)
18
+ end
19
+
20
+ def draw
21
+ image(img, 0, 0) unless img.nil?
22
+ end
23
+
24
+ def file_selected(selection)
25
+ if selection.nil?
26
+ puts 'Nothing Chosen'
27
+ else
28
+ @img = load_image(selection.get_absolute_path)
29
+ img.resize(width, height)
30
+ end
31
+ end
32
+
33
+ def mouse_clicked
34
+ @img = nil
35
+ # java_signature 'void selectInput(String, String)'
36
+ select_input('Select Image File', 'file_selected')
37
+ end
38
+ end
39
+
40
+ SelectImage.new
@@ -1,5 +1,6 @@
1
- # encoding: utf-8
1
+ #!/usr/bin/env jruby -v -W2
2
2
  # frozen_string_literal: true
3
+ # example usage of experimental slider library
3
4
  require 'propane'
4
5
 
5
6
  class SliderDemo < Propane::App
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ #!/usr/bin/env jruby -v -W2
2
2
  # frozen_string_literal: true
3
3
  require 'propane'
4
4
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ #!/usr/bin/env jruby -v -W2
2
2
  # frozen_string_literal: true
3
3
  require 'propane'
4
4
 
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env jruby -v -W2
1
2
  require 'propane'
2
3
 
3
4
  class Tree < Propane::App
@@ -13,7 +14,7 @@ class Tree < Propane::App
13
14
  @start_time = Time.now
14
15
  @frame_time = nil
15
16
  end
16
-
17
+
17
18
  def draw
18
19
  t = Time.now
19
20
  if @frame_time
@@ -21,7 +22,7 @@ class Tree < Propane::App
21
22
  # printf "%0.1f fps\n", fps
22
23
  end
23
24
  @frame_time = t
24
-
25
+
25
26
  background 0
26
27
  stroke 1, 1, 1
27
28
  # Let's pick an angle 0 to 90 degrees based on the mouse position
@@ -37,7 +38,7 @@ class Tree < Propane::App
37
38
  translate(0, -h)
38
39
  # Start the recursive branching!
39
40
  branch(h)
40
-
41
+
41
42
  @x += @dx
42
43
  if @x < 0
43
44
  puts "Time after this iteration: " + (Time.now - @start_time).to_s
@@ -47,7 +48,7 @@ class Tree < Propane::App
47
48
  @x += @dx * 2
48
49
  end
49
50
  end
50
-
51
+
51
52
  def branch(h)
52
53
  # Each branch will be 2/3rds the size of the previous one
53
54
  h *= 0.66
@@ -60,7 +61,7 @@ class Tree < Propane::App
60
61
  translate(0, -h) # Move to the end of the branch
61
62
  branch(h) # Ok, now call myself to draw two new branches!!
62
63
  pop_matrix # Whenever we get back here, we "pop" in order to restore the previous matrix state
63
-
64
+
64
65
  # Repeat the same thing, only branch off to the "left" this time!
65
66
  push_matrix
66
67
  rotate(-@theta)
@@ -69,7 +70,7 @@ class Tree < Propane::App
69
70
  branch(h)
70
71
  pop_matrix
71
72
  end
72
- end
73
+ end
73
74
  end
74
75
 
75
76
  Tree.new title: 'Tree'
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: false
2
+ # The SketchParameters class knows how to format, size, title & class name
3
+ class SketchParameters
4
+ attr_reader :name, :args
5
+ def initialize(name:, args:)
6
+ @name = name
7
+ @args = args
8
+ end
9
+
10
+ def class_name
11
+ name.split('_').collect(&:capitalize).join
12
+ end
13
+
14
+ def sketch_title
15
+ human = name.split('_').collect(&:capitalize).join(' ')
16
+ format("sketch_title '%s'", human)
17
+ end
18
+
19
+ def sketch_size
20
+ mode = args.length == 3 ? format(', %s', args[2].upcase) : ''
21
+ return 'size 200, 200' if args.empty?
22
+ format('size %d, %d%s', args[0].to_i, args[1].to_i, mode)
23
+ end
24
+ end
25
+
26
+ # The file writer can write a sketch when given instance of Sketch type
27
+ class SketchWriter
28
+ attr_reader :file, :param
29
+
30
+ def initialize(path, args)
31
+ @param = SketchParameters.new(name: path, args: args)
32
+ @file = format('%s/%s.rb', File.dirname(path), path)
33
+ end
34
+
35
+ def write(creator)
36
+ sketch = creator.code(param)
37
+ File.open(file, 'w+') { |f| f.write sketch.join("\n") }
38
+ end
39
+ end
40
+
41
+ # A simple class wrapped sketch
42
+ class ClassSketch
43
+ INDENT ||= ' '
44
+ def code(param)
45
+ lines = [
46
+ '# frozen_string_literal: false',
47
+ "require 'propane'",
48
+ ''
49
+ ]
50
+ lines << format('class %s < Propane::App', param.class_name)
51
+ lines.concat method_lines('setup', param.sketch_size)
52
+ lines.concat method_lines('draw', '')
53
+ lines << 'end'
54
+ end
55
+
56
+ private
57
+
58
+ def method_lines(name, content)
59
+ one = format('%sdef %s', INDENT, name)
60
+ two = content.empty? ? '' : format(' %s%s', INDENT, content)
61
+ three = format('%send', INDENT)
62
+ return [one, two, three] if /draw/ =~ name
63
+ [one, two, three, '']
64
+ end
65
+ end
66
+
@@ -1,8 +1,4 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: false
3
-
4
- require "#{PROPANE_ROOT}/lib/propane"
5
-
6
2
  # The processing wrapper module
7
3
  module Propane
8
4
  # Encapsulate library loader functionality as a class
@@ -112,6 +108,6 @@ module Propane
112
108
  end
113
109
  end
114
110
  nil
115
- end
111
+ end
116
112
  end
117
113
  end
@@ -37,7 +37,7 @@ module Propane
37
37
  opt_parser = OptionParser.new do |opts|
38
38
  # Set a banner, displayed at the top
39
39
  # of the help screen.
40
- opts.banner = 'Usage: propane [options] sketch.rb'
40
+ opts.banner = 'Usage: propane [options] [<sketch.rb>]'
41
41
 
42
42
  # Define the options, and what they do
43
43
  options[:version] = false
@@ -109,8 +109,9 @@ module Propane
109
109
  end
110
110
 
111
111
  def create
112
- require_relative 'creators/creator'
113
- Propane::BasicSketch.new.create!(filename, argc)
112
+ require_relative 'creators/sketch_writer'
113
+ sketch = ClassSketch.new
114
+ SketchWriter.new(File.basename(filename, '.rb'), argc).write(sketch)
114
115
  end
115
116
 
116
117
  def show_version
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
  module Propane
4
- VERSION = '0.7.0'.freeze
4
+ VERSION = '0.8.0'.freeze
5
5
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ # Usage: :wq
3
+ # load_library :chooser
4
+ #
5
+ # def setup
6
+ # java_signature 'void selectInput(String, String)'
7
+ # selectInput('Select a file to process:', 'fileSelected')
8
+ # end
9
+ #
10
+ # def fileSelected(selection)
11
+ # if selection.nil?
12
+ # puts 'Window was closed or the user hit cancel.'
13
+ # else
14
+ # puts format('User selected %s', selection.get_absolute_path)
15
+ # end
16
+ # end
17
+ class Propane::App
18
+ include Java::MonkstoneFilechooser::Chooser
19
+ Chooser
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ # Usage:
3
+ # load_library :file_chooser
4
+ # class ...
5
+ # def setup
6
+ # java_signature 'void selectInput(String, String)'
7
+ # selectInput('Select a file to process:', 'fileSelected')
8
+ # end
9
+ #
10
+ # def fileSelected(selection)
11
+ # if selection.nil?
12
+ # puts 'Window was closed or the user hit cancel.'
13
+ # else
14
+ # puts format('User selected %s', selection.get_absolute_path)
15
+ # end
16
+ # end
17
+ # ...
18
+ class Propane::App
19
+ include Java::MonkstoneFilechooser::Chooser
20
+ end
data/pom.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
  project 'rp5extras', 'https://github.com/monkstone/propane' do
3
3
  model_version '4.0.0'
4
- id 'propane:rp5extras', '0.7.0'
4
+ id 'propane:rp5extras', '0.8.0'
5
5
  packaging 'jar'
6
6
  description 'rp5extras for propane'
7
7
  organization 'ruby-processing', 'https://ruby-processing.github.io'
data/pom.xml CHANGED
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
11
11
  <modelVersion>4.0.0</modelVersion>
12
12
  <groupId>propane</groupId>
13
13
  <artifactId>rp5extras</artifactId>
14
- <version>0.7.0</version>
14
+ <version>0.8.0</version>
15
15
  <name>rp5extras</name>
16
16
  <description>rp5extras for propane</description>
17
17
  <url>https://github.com/monkstone/propane</url>