jruby_art 2.2.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/bin/k9 +4 -3
  3. data/lib/gluegen-rt-natives-linux-amd64.jar +0 -0
  4. data/lib/gluegen-rt-natives-macosx-universal.jar +0 -0
  5. data/lib/gluegen-rt-natives-windows-amd64.jar +0 -0
  6. data/lib/gluegen-rt.jar +0 -0
  7. data/lib/jogl-all-natives-linux-amd64.jar +0 -0
  8. data/lib/jogl-all-natives-macosx-universal.jar +0 -0
  9. data/lib/jogl-all-natives-windows-amd64.jar +0 -0
  10. data/lib/jogl-all.jar +0 -0
  11. data/lib/jruby_art-2.4.1.jar +0 -0
  12. data/lib/jruby_art/app.rb +8 -7
  13. data/lib/jruby_art/config.rb +2 -0
  14. data/lib/jruby_art/creators/sketch_writer.rb +31 -13
  15. data/lib/jruby_art/default_config.rb +2 -0
  16. data/lib/jruby_art/helper_methods.rb +23 -23
  17. data/lib/jruby_art/helpers/aabb.rb +3 -0
  18. data/lib/jruby_art/helpers/numeric.rb +1 -0
  19. data/lib/jruby_art/installer.rb +10 -7
  20. data/lib/jruby_art/java_opts.rb +2 -0
  21. data/lib/jruby_art/jruby_complete.rb +2 -0
  22. data/lib/jruby_art/launcher.rb +8 -3
  23. data/lib/jruby_art/library.rb +14 -5
  24. data/lib/jruby_art/library_loader.rb +4 -1
  25. data/lib/jruby_art/native_folder.rb +16 -14
  26. data/lib/jruby_art/native_loader.rb +3 -0
  27. data/lib/jruby_art/processing_ide.rb +5 -1
  28. data/lib/jruby_art/runner.rb +65 -44
  29. data/lib/jruby_art/runners/base.rb +5 -4
  30. data/lib/jruby_art/runners/live.rb +10 -7
  31. data/lib/jruby_art/runners/run.rb +1 -0
  32. data/lib/jruby_art/runners/watch.rb +6 -4
  33. data/lib/jruby_art/version.rb +2 -1
  34. data/library/boids/boids.rb +19 -10
  35. data/library/chooser/chooser.rb +10 -9
  36. data/library/color_group/color_group.rb +2 -0
  37. data/library/control_panel/control_panel.rb +8 -5
  38. data/library/dxf/dxf.rb +2 -0
  39. data/library/library_proxy/library_proxy.rb +2 -0
  40. data/library/net/net.rb +2 -0
  41. data/library/slider/slider.rb +24 -23
  42. data/library/vector_utils/vector_utils.rb +5 -1
  43. data/library/video_event/video_event.rb +5 -1
  44. data/vendors/Rakefile +90 -37
  45. metadata +12 -12
  46. data/lib/jruby_art-2.2.0.jar +0 -0
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A wrapper for version
3
4
  module JRubyArt
4
- VERSION = '2.2.0'
5
+ VERSION = '2.4.1'
5
6
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Boids -- after Tom de Smedt.
3
4
  # See his Python version: http://nodebox.net/code/index.php/Boids
4
5
  # This is an example of how a pure-Ruby library can work. Original for
@@ -8,7 +9,8 @@ class Boid
8
9
  attr_reader :boids
9
10
  attr_accessor :vel, :pos, :is_perching, :perch_time
10
11
  def initialize(boids, pos)
11
- @boids, @flock = boids, boids
12
+ @boids = boids
13
+ @flock = boids
12
14
  @pos = pos
13
15
  @vel = Vec3D.new
14
16
  @is_perching = false
@@ -54,6 +56,7 @@ class Boid
54
56
  # Tweet, Tweet! The boid police will bust you for breaking the speed limit.
55
57
  most = [vel.x.abs, vel.y.abs, vel.z.abs].max
56
58
  return if most < max
59
+
57
60
  scale = max / most.to_f
58
61
  @vel *= scale
59
62
  end
@@ -70,13 +73,13 @@ end
70
73
 
71
74
  require 'forwardable'
72
75
 
73
- # The Boids class
76
+ # The Boids class NB: perchance => perch chance
74
77
  class Boids
75
78
  include Enumerable
76
79
  extend Forwardable
77
80
  def_delegators(:@boids, :reject, :<<, :each, :shuffle!, :length, :next)
78
81
 
79
- attr_reader :has_goal, :perch, :perch_tm, :perch_y
82
+ attr_reader :has_goal, :perchance, :perch_tm, :perch_y
80
83
 
81
84
  def initialize
82
85
  @boids = []
@@ -89,16 +92,20 @@ class Boids
89
92
 
90
93
  def setup(n, x, y, w, h)
91
94
  n.times do
92
- dx, dy = rand(w), rand(h)
95
+ dx = rand(w)
96
+ dy = rand(h)
93
97
  z = rand(200.0)
94
98
  self << Boid.new(self, Vec3D.new(x + dx, y + dy, z))
95
99
  end
96
- @x, @y, @w, @h = x, y, w, h
100
+ @x = x
101
+ @y = y
102
+ @w = w
103
+ @h = h
97
104
  @scattered = false
98
105
  @scatter = 0.005
99
106
  @scatter_time = 50.0
100
107
  @scatter_i = 0.0
101
- @perch = 1.0 # Lower this number to divebomb.
108
+ @perchance = 1.0 # Lower this number to divebomb.
102
109
  @perch_y = h
103
110
  @perch_tm = -> { 25.0 + rand(50.0) }
104
111
  @has_goal = false
@@ -119,11 +126,11 @@ class Boids
119
126
  def perch(ground = nil, chance = 1.0, frames = nil)
120
127
  @perch_tm = frames.nil? ? -> { 25.0 + rand(50.0) } : frames
121
128
  @perch_y = ground.nil? ? @h : ground
122
- @perch = chance
129
+ @perchance = chance
123
130
  end
124
131
 
125
132
  def no_perch
126
- @perch = 0.0
133
+ @perchance = 0.0
127
134
  end
128
135
 
129
136
  def reset_goal(target)
@@ -146,7 +153,8 @@ class Boids
146
153
 
147
154
  def constrain
148
155
  # Put them boids in a cage.
149
- dx, dy = @w * 0.1, @h * 0.1
156
+ dx = @w * 0.1
157
+ dy = @h * 0.1
150
158
  each do |b|
151
159
  b.vel.x += rand(dx) if b.pos.x < @x - dx
152
160
  b.vel.y += rand(dy) if b.pos.y < @y - dy
@@ -154,7 +162,8 @@ class Boids
154
162
  b.vel.y -= rand(dy) if b.pos.y > @y + @h + dy
155
163
  b.vel.z += 10.0 if b.pos.z < 0.0
156
164
  b.vel.z -= 10.0 if b.pos.z > 100.0
157
- next unless b.pos.y > perch_y && rand < perch
165
+ next unless b.pos.y > perch_y && rand < perchance
166
+
158
167
  b.pos.y = perch_y
159
168
  b.vel.y = b.vel.y.abs * -0.2
160
169
  b.is_perching = true
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Usage:
3
4
  # load_library :chooser
4
- #
5
+ #
5
6
  # def setup
6
- # java_signature 'void selectInput(String, String)'
7
- # selectInput('Select a file to process:', 'fileSelected')
7
+ # java_signature 'void selectInput(String, String)'
8
+ # selectInput('Select a file to process:', 'fileSelected')
8
9
  # end
9
- #
10
+ #
10
11
  # 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
12
+ # if selection.nil?
13
+ # puts 'Window was closed or the user hit cancel.'
14
+ # else
15
+ # puts format('User selected %s', selection.get_absolute_path)
16
+ # end
16
17
  # end
17
18
  class Processing::App
18
19
  include Java::MonkstoneFilechooser::Chooser
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  java_import Java::Monkstone::ColorUtil
2
4
 
3
5
  # class wraps a java color array, supports shuffle!, last and ruby_string
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Here's a little library for quickly hooking up controls to sketches.
2
4
  # For messing with the parameters and such.
3
5
  # These controls will set instance variables on the sketches.
@@ -25,7 +27,7 @@ module ControlPanel
25
27
  add_change_listener do
26
28
  update_label(label, name, value)
27
29
  ControlPanel.app_value(name, value)
28
- proc.call(value) if proc
30
+ proc&.call(value)
29
31
  end
30
32
  ControlPanel.app_value(name, val)
31
33
  end
@@ -49,7 +51,7 @@ module ControlPanel
49
51
  control_panel.add_element(self, name)
50
52
  add_action_listener do
51
53
  ControlPanel.app_value(name, value) unless value.nil?
52
- proc.call(value) if proc
54
+ proc&.call(value)
53
55
  end
54
56
  set_selected_index(initial_value ? elements.index(initial_value) : 0)
55
57
  end
@@ -69,7 +71,7 @@ module ControlPanel
69
71
  control_panel.add_element(self, name, false)
70
72
  add_action_listener do
71
73
  ControlPanel.app_value(name, value)
72
- proc.call(value) if proc
74
+ proc&.call(value)
73
75
  end
74
76
  end
75
77
 
@@ -87,7 +89,7 @@ module ControlPanel
87
89
  control_panel.add_element(self, name, false, true)
88
90
  add_action_listener do
89
91
  Processing.app.send(name)
90
- proc.call(value) if proc
92
+ proc&.call(value)
91
93
  end
92
94
  end
93
95
  end
@@ -160,7 +162,7 @@ module ControlPanel
160
162
  def feel(lf = 'metal')
161
163
  lafinfo = javax.swing.UIManager.getInstalledLookAndFeels
162
164
  laf = lafinfo.to_ary.find do |info|
163
- info.name =~ Regexp.new(Regexp.escape(lf), Regexp::IGNORECASE)
165
+ info.name.match?(Regexp.new(Regexp.escape(lf), Regexp::IGNORECASE))
164
166
  end
165
167
  javax.swing.UIManager.setLookAndFeel(laf.class_name)
166
168
  end
@@ -171,6 +173,7 @@ module ControlPanel
171
173
  def control_panel
172
174
  @control_panel ||= ControlPanel::Panel.new
173
175
  return @control_panel unless block_given?
176
+
174
177
  yield(@control_panel)
175
178
  @control_panel.display
176
179
  @control_panel.set_visible true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # @TODO usage
2
4
  class Processing::App
3
5
  java_import Java::ProcessingDxf::RawDXF
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  java_import Java::MonkstoneCore::LibraryProxy
2
4
  java_import Java::ProcessingEvent::KeyEvent
3
5
  java_import Java::ProcessingEvent::MouseEvent
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # @TODO usage
2
4
  class Processing::App
3
5
  java_import Java::ProcessingNet::Client
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Here's a little library for quickly hooking up in sketch sliders.
3
- # Copyright (c) 2016-19 Martin Prout.
4
+ # Copyright (c) 2015-20 Martin Prout.
4
5
 
5
6
  java_import 'monkstone.slider.CustomHorizontalSlider'
6
7
  java_import 'monkstone.slider.CustomVerticalSlider'
@@ -8,34 +9,34 @@ java_import 'monkstone.slider.CustomVerticalSlider'
8
9
  module Slider
9
10
  def self.slider(app:, x:, y:, name:, **opts)
10
11
  options = default.merge opts
11
- if options[:vertical]
12
- slider = CustomVerticalSlider.new(
13
- app,
14
- x,
15
- y,
16
- options[:length],
17
- options[:range].first,
18
- options[:range].last,
19
- name
20
- )
21
- else
22
- slider = CustomHorizontalSlider.new(
23
- app,
24
- x,
25
- y,
26
- options[:length],
27
- options[:range].first,
28
- options[:range].last,
29
- name
30
- )
31
- end
12
+ slider = if options[:vertical]
13
+ CustomVerticalSlider.new(
14
+ app,
15
+ x,
16
+ y,
17
+ options[:length],
18
+ options[:range].first,
19
+ options[:range].last,
20
+ name
21
+ )
22
+ else
23
+ CustomHorizontalSlider.new(
24
+ app,
25
+ x,
26
+ y,
27
+ options[:length],
28
+ options[:range].first,
29
+ options[:range].last,
30
+ name
31
+ )
32
+ end
32
33
  unless opts.empty?
33
34
  slider.bar_width(opts.fetch(:bar_width, 10))
34
35
  slider.set_value(opts.fetch(:initial_value, 0))
35
36
  end
36
37
  slider
37
38
  end
38
-
39
+
39
40
  def self.default
40
41
  { length: 100, range: (0..100) }
41
42
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  PHI ||= (1 + Math.sqrt(5)) / 2 # golden ratio
2
4
  GA = PHI * 2 * Math::PI # golden angle
3
5
 
@@ -47,7 +49,8 @@ module VectorUtil
47
49
 
48
50
  def self.cartesian_to_polar(vec:)
49
51
  res = Vec3D.new(vec.mag, 0, 0)
50
- return Vec3D.new unless res.x > 0
52
+ return Vec3D.new unless res.x.positive?
53
+
51
54
  res.y = -Math.atan2(vec.z, vec.x)
52
55
  res.z = Math.asin(vec.y / res.x)
53
56
  res
@@ -64,6 +67,7 @@ module VectorUtil
64
67
 
65
68
  def self.polar_to_cartesian(vec:)
66
69
  return Vec3D.new if vec.mag <= 0
70
+
67
71
  Vec3D.new(Math.asin(vec.y / vec.mag), vec.mag, -Math.atan2(vec.z, vec.x))
68
72
  end
69
73
  end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # include interfaces
1
4
  class Processing::App
2
- include Java::MonkstoneVideoevent::VideoInterface
5
+ include Java::MonkstoneVideoevent::MovieEvent
6
+ include Java::MonkstoneVideoevent::CaptureEvent
3
7
  end
@@ -1,50 +1,57 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'rake/clean'
3
5
 
4
- WARNING = <<-WARN.freeze
5
- WARNING: you may not have wget installed, you could just download
6
- the correct version of jruby-complete to the vendors folder, and
7
- re-run k9 setup install instead of installing wget. Some systems
8
- may also require 'sudo' access to install, NB: this is untested....
6
+ WARNING = <<~WARN
7
+ WARNING: you may not have wget installed, you could just download
8
+ the correct version of jruby-complete to the vendors folder, and
9
+ re-run k9 setup install instead of installing wget. Some systems
10
+ may also require 'sudo' access to install, NB: this is untested....
9
11
 
10
12
  WARN
11
-
12
- JRUBYC_VERSION = '9.2.8.0'.freeze
13
-
14
- EXAMPLES = '3.4'.freeze
13
+ # https://github.com/processing/processing-video/releases/download/r6-v2.0-beta4/video-2.0-beta4.zip
14
+ JRUBYC_VERSION = '9.2.12.0'
15
+ SOUND = 'sound.zip'
16
+ SOUND_VERSION = 'v2.2.2'
17
+ VIDEO = 'video-2.0-beta4.zip'
18
+ VIDEO_VERSION = 'r6-v2.0-beta4'
19
+ EXAMPLES = '3.7'
15
20
  HOME_DIR = ENV['HOME']
16
- MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
21
+ MAC_OR_LINUX = /linux|mac|darwin/.match?(RbConfig::CONFIG['host_os'])
17
22
 
18
23
  CLOBBER << "jruby-complete-#{JRUBYC_VERSION}.jar"
19
24
  CLOBBER << "jruby-complete-#{JRUBYC_VERSION}.jar.sha256"
20
25
 
21
- file "jruby-complete-#{JRUBYC_VERSION}.jar.sha256" do
22
- begin
23
- system "wget https://repo1.maven.org/maven2/org/jruby/jruby-complete/#{JRUBYC_VERSION}/jruby-complete-#{JRUBYC_VERSION}.jar.sha256"
24
- rescue
25
- warn(WARNING)
26
- end
26
+ desc 'dependency check'
27
+ task :wget_check do
28
+ WGET ||= `which wget`.freeze
29
+ warn WARNING unless WGET
27
30
  end
28
31
 
29
- desc 'get sha256'
30
- task get_sha256: ["jruby-complete-#{JRUBYC_VERSION}.jar.sha256"]
31
-
32
- desc 'download, and copy to jruby_art'
33
- task default: %i[get_sha256 download copy_ruby]
34
-
35
- desc 'download JRuby upstream sources'
36
- task download: ["jruby-complete-#{JRUBYC_VERSION}.jar"]
32
+ file "jruby-complete-#{JRUBYC_VERSION}.jar.sha256" do
33
+ system "wget https://repo1.maven.org/maven2/org/jruby/jruby-complete/#{JRUBYC_VERSION}/jruby-complete-#{JRUBYC_VERSION}.jar.sha256"
34
+ end
37
35
 
38
36
  file "jruby-complete-#{JRUBYC_VERSION}.jar" do
39
37
  begin
40
38
  system "wget https://repo1.maven.org/maven2/org/jruby/jruby-complete/#{JRUBYC_VERSION}/jruby-complete-#{JRUBYC_VERSION}.jar"
41
- rescue
39
+ rescue NameError
42
40
  warn(WARNING)
43
41
  end
44
42
  value = File.read("jruby-complete-#{JRUBYC_VERSION}.jar.sha256")
45
43
  check_sha256("jruby-complete-#{JRUBYC_VERSION}.jar", value)
46
44
  end
47
45
 
46
+ desc 'get sha256'
47
+ task get_sha256: ['wget_check', "jruby-complete-#{JRUBYC_VERSION}.jar.sha256"]
48
+
49
+ desc 'download, and copy to jruby_art'
50
+ task default: %i[wget_check download copy_ruby install_samples]
51
+
52
+ desc 'download JRuby upstream sources'
53
+ task download: ['get_sha256', "jruby-complete-#{JRUBYC_VERSION}.jar"]
54
+
48
55
  directory '../lib/ruby'
49
56
 
50
57
  desc 'copy jruby-complete'
@@ -67,32 +74,78 @@ def check_sha256(filename, expected_hash)
67
74
  raise "bad sha256 checksum for #{filename} (expected #{expected_hash} got #{sha256.hexdigest})"
68
75
  end
69
76
 
77
+ desc 'initialize ~/.jruby_art directories'
78
+ task :init_dir do
79
+ unless File.exist? "#{HOME_DIR}/.jruby_art/libraries"
80
+ FileUtils.mkdir_p "#{HOME_DIR}/.jruby_art/libraries"
81
+ end
82
+ end
83
+
84
+ desc 'download and copy sound library to ~/.jruby_art'
85
+ task download_and_copy_sound: %i[wget_check init_dir download_sound copy_sound clobber]
86
+
87
+ desc 'download and copy video library to ~/.jruby_art'
88
+ task download_and_copy_video: %i[wget_check init_dir download_video copy_video clobber]
89
+
90
+ desc 'download sound library'
91
+ task :download_sound do
92
+ wget_base = 'wget https://github.com/processing/processing-sound'
93
+ wget_string = [wget_base, 'releases/download/latest', SOUND].join('/')
94
+ puts wget_string
95
+ system wget_string
96
+ end
97
+
98
+ desc 'download video library'
99
+ task :download_video do
100
+ wget_base = 'wget https://github.com/processing/processing-video'
101
+ wget_string = [wget_base, 'releases/download', VIDEO_VERSION, VIDEO].join('/')
102
+ system wget_string
103
+ end
104
+
105
+ desc 'copy sound library'
106
+ task copy_sound: SOUND do
107
+ system "unzip #{SOUND}"
108
+ if File.exist? "#{HOME_DIR}/.jruby_art/libraries/sound"
109
+ FileUtils.rm_r "#{HOME_DIR}/.picrate/libraries/sound"
110
+ end
111
+ FileUtils.cp_r 'sound', "#{HOME_DIR}/.jruby_art/libraries"
112
+ FileUtils.rm_r 'sound'
113
+ end
114
+
115
+ desc 'copy video library'
116
+ task copy_video: VIDEO do
117
+ system "unzip #{VIDEO}"
118
+ if File.exist? "#{HOME_DIR}/.jruby_art/libraries/video"
119
+ FileUtils.rm_r "#{HOME_DIR}/.picrate/libraries/video"
120
+ end
121
+ FileUtils.cp_r 'video', "#{HOME_DIR}/.jruby_art/libraries/video"
122
+ FileUtils.rm_r 'video'
123
+ end
124
+
70
125
  desc 'download, and copy to jruby_art'
71
- task unpack_samples: %i[download_examples copy_examples]
126
+ task install_samples: %i[download_examples copy_examples]
72
127
 
73
128
  desc 'download and copy examples to user home'
74
129
  task :download_examples
75
130
  file_name = MAC_OR_LINUX.nil? ? "#{EXAMPLES}.zip" : "#{EXAMPLES}.tar.gz"
76
131
  file file_name do
77
- begin
78
- if MAC_OR_LINUX.nil?
79
- system "wget https://github.com/ruby-processing/JRubyArt-examples/archive/#{EXAMPLES}.zip"
80
- else
81
- system "wget https://github.com/ruby-processing/JRubyArt-examples/archive/#{EXAMPLES}.tar.gz"
82
- end
83
- rescue
84
- warn(WARNING)
132
+ if MAC_OR_LINUX.nil?
133
+ system "wget https://github.com/ruby-processing/JRubyArt-examples/archive/#{EXAMPLES}.zip"
134
+ else
135
+ system "wget https://github.com/ruby-processing/JRubyArt-examples/archive/#{EXAMPLES}.tar.gz"
85
136
  end
86
137
  end
87
138
 
88
139
  desc 'copy examples'
89
140
  task copy_examples: file_name do
90
141
  if MAC_OR_LINUX.nil?
91
- sh "unzip #{EXAMPLES}.zip"
142
+ system "unzip #{EXAMPLES}.zip"
92
143
  else
93
- sh "tar xzvf #{EXAMPLES}.tar.gz"
144
+ system "tar xzvf #{EXAMPLES}.tar.gz"
145
+ end
146
+ if File.exist? "#{HOME_DIR}/k9_samples"
147
+ FileUtils.rm_r("#{HOME_DIR}/k9_samples")
94
148
  end
95
- FileUtils.rm_r("#{HOME_DIR}/k9_samples") if File.exist? "#{HOME_DIR}/k9_samples"
96
149
  FileUtils.cp_r("JRubyArt-examples-#{EXAMPLES}", "#{HOME_DIR}/k9_samples")
97
150
  FileUtils.rm_r("JRubyArt-examples-#{EXAMPLES}")
98
151
  end