jruby_art 0.9.0 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb0e41ec051e87ef6d10ef371905c31970530399
4
- data.tar.gz: bffce18e731c80959680481a1426aac30512fab3
3
+ metadata.gz: 8a6cd608ad55dfa06a0d23d02cd9f8d211f628e4
4
+ data.tar.gz: 6771e86dee627b35774d39b42fd4076681be5454
5
5
  SHA512:
6
- metadata.gz: 438f7e83fac4d48ead0fae4e53fa2c8d9366eebc1f28fbcf34be225e59d3d5d48849ccf72ddc9b3c386ea511259325af7114057bf83144ebf9f3a808704a00c5
7
- data.tar.gz: efb75f96fb117f63a215bd648a9b79ace3b7b8c96cf1addc3a6adff9a16940a7affe2473451a50db63371f6dfa63cc1a6454ef805efa89855f65304880f0069e
6
+ metadata.gz: bd5a6f88284c164a91e907cea990e42a572026a6cad2307687ef777450cbc7c895a5e7bdc8ce067508b6198af8d1f7d292d31eef07cb381671f6eb7aed06219f
7
+ data.tar.gz: 61ed2bd5e0881a7bcad3e179d3b36462d2d6a69e5944d543749afa01364433584b84ae9e69774fda56e5fe88defd5380c872eecc4e85ccbdfecbb11e35e0597e
@@ -8,7 +8,8 @@ def draw
8
8
  end
9
9
 
10
10
  def settings
11
- size %s, %s, FX2D
11
+ size %s, %s
12
+ # pixel_density(2) # here for hi-dpi displays only
12
13
  # smooth # here
13
14
  end
14
15
 
@@ -41,7 +42,8 @@ class %s < Processing::App
41
42
  end
42
43
 
43
44
  def settings
44
- size %s, %s, FX2D
45
+ size %s, %s
46
+ # pixel_density(2) # here for hi-dpi displays only
45
47
  # smooth # here
46
48
  end
47
49
  end
@@ -1,3 +1,3 @@
1
1
  module JRubyArt
2
- VERSION = '0.9.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/rpextras.jar CHANGED
Binary file
@@ -1,120 +1,109 @@
1
1
  # Boids -- after Tom de Smedt.
2
2
  # See his Python version: http://nodebox.net/code/index.php/Boids
3
- # This is an example of how a pure-Ruby library can work.
4
- # -- omygawshkenas
5
-
3
+ # This is an example of how a pure-Ruby library can work. Original for
4
+ # ruby-processing Jeremy Ashkenas. Reworked, re-factored for JRubyArt 0.9+
5
+ # by Martin Prout, features forwardable, keyword args, Vec3D and Vec2D.
6
6
  class Boid
7
- attr_accessor :boids, :x, :y, :z, :vx, :vy, :vz, :is_perching, :perch_time
7
+ attr_accessor :boids, :pos, :vel, :is_perching, :perch_time
8
8
 
9
- def initialize(boids, x, y, z)
9
+ def initialize(boids, pos)
10
10
  @boids, @flock = boids, boids
11
- @x, @y, @z = x, y, z
12
- @vx, @vy, @vz = 0.0, 0.0, 0.0
11
+ @pos = pos
12
+ @vel = Vec3D.new
13
13
  @is_perching = false
14
14
  @perch_time = 0.0
15
15
  end
16
16
 
17
- def cohesion(d = 100.0)
17
+ def cohesion(d:)
18
18
  # Boids gravitate towards the center of the flock,
19
19
  # Which is the averaged position of the rest of the boids.
20
- cvx, cvy, cvz = 0.0, 0.0, 0.0
21
- boids.reject { |bd| bd.equal? self }.each do |boid|
22
- cvx, cvy, cvz = cvx + boid.x, cvy + boid.y, cvz + boid.z
20
+ vect = Vec3D.new
21
+ @boids.each do |boid|
22
+ vect += boid.pos unless boid == self
23
23
  end
24
- count = boids.length - 1.0
25
- cvx, cvy, cvz = cvx / count, cvy / count, cvz / count
26
- [(cvx - x) / d, (cvy - y) / d, (cvz - z) / d]
24
+ count = @boids.length - 1.0
25
+ vect /= count
26
+ (vect - pos) / d
27
27
  end
28
28
 
29
- def separation(radius = 10.0)
29
+ def separation(radius:)
30
30
  # Boids don't like to cuddle.
31
- svx, svy, svz = 0.0, 0.0, 0.0
32
- boids.reject { |bd| bd.equal? self }.each do |boid|
33
- dvx, dvy, dvz = x - boid.x, y - boid.y, z - boid.z
34
- svx += dvx if dvx.abs < radius
35
- svy += dvy if dvy.abs < radius
36
- svz += dvz if dvz.abs < radius
31
+ vect = Vec3D.new
32
+ @boids.each do |boid|
33
+ if boid != self
34
+ dv = pos - boid.pos
35
+ vect += dv if dv.mag < radius
36
+ end
37
37
  end
38
- [svx, svy, svz]
38
+ vect
39
39
  end
40
40
 
41
- def alignment(d = 5.0)
41
+ def alignment(d:)
42
42
  # Boids like to fly at the speed of traffic.
43
- avx, avy, avz = 0.0, 0.0, 0.0
44
- boids.reject { |bd| bd.equal? self }.each do |boid|
45
- avx, avy, avz = avx + boid.vx, avy + boid.vy, avz + boid.vz
43
+ vect = Vec3D.new
44
+ @boids.each do |boid|
45
+ vect += boid.vel if boid != self
46
46
  end
47
- count = boids.length - 1.0
48
- avx, avy, avz = avx / count, avy / count, avz / count
49
- [(avx - vx) / d, (avy - vy) / d, (avz - vz) / d]
47
+ count = @boids.length - 1.0
48
+ vect /= count
49
+ (vect - vel) / d
50
50
  end
51
51
 
52
- def limit(max = 30.0)
52
+ def limit(max:)
53
53
  # Tweet, Tweet! The boid police will bust you for breaking the speed limit.
54
- most = [@vx.abs, @vy.abs, @vz.abs].max
54
+ most = [vel.x.abs, vel.y.abs, vel.z.abs].max
55
55
  return if most < max
56
56
  scale = max / most.to_f
57
- @vx *= scale
58
- @vy *= scale
59
- @vz *= scale
57
+ @vel *= scale
60
58
  end
61
59
 
62
60
  def angle
63
- a = (Math.atan(@vy / @vx) * (180.0 / Math::PI)) + 360.0
64
- a += 180.0 if @vx < 0.0
65
- a
61
+ Vec2D.new(vel.x, vel.y).heading
66
62
  end
67
63
 
68
- def goal(gx, gy, gz, d = 50.0)
64
+ def goal(target, d = 50.0)
69
65
  # Them boids is hungry.
70
- [(gx - x) / d, (gy - y) / d, (gz - z) / d]
66
+ (target - pos) / d
71
67
  end
72
68
  end
73
69
 
74
70
  require 'forwardable'
75
71
 
72
+ # The Boids class
76
73
  class Boids
77
74
  include Enumerable
78
75
  extend Forwardable
79
76
  def_delegators(:@boids, :reject, :<<, :each, :shuffle!, :length, :next)
80
77
 
81
- attr_accessor :boids, :x, :y, :w, :h,
82
- :scattered, :has_goal, :flee
83
-
84
- attr_reader :scatter, :scatter_time, :scatter_i,
85
- :perch, :perch_y, :perch_t, :boids,
86
- :goal_x, :goal_y, :goal_z
78
+ attr_reader :has_goal, :perch, :perch_tm, :perch_y
87
79
 
88
80
  def initialize
89
81
  @boids = []
90
82
  end
91
83
 
92
- def self.flock(n, x, y, w, h)
93
- Boids.new.setup(n, x, y, w, h)
84
+ def self.flock(n:, x:, y:, w:, h:)
85
+ flock = Boids.new.setup(n, x, y, w, h)
86
+ flock.goal(target: Vec3D.new(w / 2, h / 2, 0))
94
87
  end
95
88
 
96
89
  def setup(n, x, y, w, h)
97
90
  n.times do
98
91
  dx, dy = rand(w), rand(h)
99
92
  z = rand(200.0)
100
- self << Boid.new(self, x + dx, y + dy, z)
93
+ self << Boid.new(self, Vec3D.new(x + dx, y + dy, z))
101
94
  end
102
95
  @x, @y, @w, @h = x, y, w, h
103
- init
104
- self
105
- end
106
-
107
- def init
108
96
  @scattered = false
109
97
  @scatter = 0.005
110
98
  @scatter_time = 50.0
111
99
  @scatter_i = 0.0
112
100
  @perch = 1.0 # Lower this number to divebomb.
113
101
  @perch_y = h
114
- @perch_t = -> { rand(25..75.0) }
102
+ @perch_tm = -> { 25.0 + rand(50.0) }
115
103
  @has_goal = false
116
104
  @flee = false
117
- @goal_x = @goal_y = @goal_z = 0.0
105
+ @goal = Vec3D.new
106
+ self
118
107
  end
119
108
 
120
109
  def scatter(chance = 0.005, frames = 50.0)
@@ -127,19 +116,20 @@ class Boids
127
116
  end
128
117
 
129
118
  def perch(ground = nil, chance = 1.0, frames = nil)
130
- frames ||= -> { rand(25..75.0) }
131
- ground ||= h
132
- @perch, @perch_y, @perch_t = chance, ground, frames
119
+ @perch_tm = frames.nil? ? -> { 25.0 + rand(50.0) } : frames
120
+ @perch_y = ground.nil? ? @h : ground
121
+ @perch = chance
133
122
  end
134
123
 
135
124
  def no_perch
136
125
  @perch = 0.0
137
126
  end
138
127
 
139
- def goal(gx, gy, gz, flee = false)
128
+ def goal(target:, flee: false)
140
129
  @has_goal = true
141
130
  @flee = flee
142
- @goal_x, @goal_y, @goal_z = gx, gy, gz
131
+ @goal = target
132
+ self
143
133
  end
144
134
 
145
135
  def no_goal
@@ -148,37 +138,34 @@ class Boids
148
138
 
149
139
  def constrain
150
140
  # Put them boids in a cage.
151
- dx, dy = w * 0.1, h * 0.1
141
+ dx, dy = @w * 0.1, @h * 0.1
152
142
  each do |b|
153
- b.vx += rand(dx) if b.x < x - dx
154
- b.vx += rand(dy) if b.y < y - dy
155
- b.vx -= rand(dx) if b.x > x + w + dx
156
- b.vy -= rand(dy) if b.y > y + h + dy
157
- b.vz += 10.0 if b.z < 0.0
158
- b.vz -= 10.0 if b.z > 100.0
159
- next unless b.y > @perch_y && rand < @perch
160
- b.y = @perch_y
161
- b.vy = -(b.vy.abs) * 0.2
143
+ b.vel.x += rand(dx) if b.pos.x < @x - dx
144
+ b.vel.x += rand(dy) if b.pos.y < @y - dy
145
+ b.vel.x -= rand(dx) if b.pos.x > @x + @w + dx
146
+ b.vel.y -= rand(dy) if b.pos.y > @y + @h + dy
147
+ b.vel.z += 10.0 if b.pos.z < 0.0
148
+ b.vel.z -= 10.0 if b.pos.z > 100.0
149
+ next unless b.pos.y > perch_y && rand < perch
150
+ b.pos.y = perch_y
151
+ b.vel.y = -(b.vel.y.abs) * 0.2
162
152
  b.is_perching = true
163
- @perch_t.respond_to?(:call) ? b.perch_time = @perch_t.call : b.perch_time = @perch_t
153
+ b.perch_time = perch_tm.respond_to?(:call) ? perch_tm.call : perch_tm
164
154
  end
165
155
  end
166
156
 
167
- def update(opts = {}) # Just flutter, little boids ... just flutter away.
168
- options = {
169
- shuffled: true, # Shuffling keeps things flowing smooth.
170
- cohesion: 100.0,
171
- separation: 10.0,
172
- alignment: 5.0,
173
- goal: 20.0,
174
- limit: 30.0
175
- }
176
- options.merge! opts
177
- shuffle! if options[:shuffled]
178
- m1 = 1.0 # cohesion
179
- m2 = 1.0 # separation
180
- m3 = 1.0 # alignment
181
- m4 = 1.0 # goal
157
+ def update(goal: 20.0, limit: 30.0, **args)
158
+ shuffled = args.fetch(:shuffled, true)
159
+ cohesion = args.fetch(:cohesion, 100)
160
+ separation = args.fetch(:separation, 10)
161
+ alignment = args.fetch(:alignment, 5.0)
162
+ # Just flutter, little boids ... just flutter away.
163
+ # Shuffling keeps things flowing smooth.
164
+ shuffle! if shuffled
165
+ m1 = 1.0 # cohesion
166
+ m2 = 1.0 # separation
167
+ m3 = 1.0 # alignment
168
+ m4 = 1.0 # goal
182
169
  @scattered = true if !(@scattered) && rand < @scatter
183
170
  if @scattered
184
171
  m1 = -m1
@@ -189,7 +176,7 @@ class Boids
189
176
  @scattered = false
190
177
  @scatter_i = 0.0
191
178
  end
192
- m4 = 0.0 unless @has_goal
179
+ m4 = 0.0 unless has_goal
193
180
  m4 = -m4 if @flee
194
181
  each do |b|
195
182
  if b.is_perching
@@ -200,17 +187,14 @@ class Boids
200
187
  b.is_perching = false
201
188
  end
202
189
  end
203
- vx1, vy1, vz1 = *b.cohesion(options[:cohesion])
204
- vx2, vy2, vz2 = *b.separation(options[:separation])
205
- vx3, vy3, vz3 = *b.alignment(options[:alignment])
206
- vx4, vy4, vz4 = b.goal(@goal_x, @goal_y, @goal_z, options[:goal])
207
- b.vx += m1 * vx1 + m2 * vx2 + m3 * vx3 + m4 * vx4
208
- b.vy += m1 * vy1 + m2 * vy2 + m3 * vy3 + m4 * vy4
209
- b.vz += m1 * vz1 + m2 * vz2 + m3 * vz3 + m4 * vz4
210
- b.limit(options[:limit])
211
- b.x += b.vx
212
- b.y += b.vy
213
- b.z += b.vz
190
+ v1 = b.cohesion(d: cohesion)
191
+ v2 = b.separation(radius: separation)
192
+ v3 = b.alignment(d: alignment)
193
+ v4 = b.goal(@goal, goal)
194
+ # NB: vector must precede scalar in '*' operation below
195
+ b.vel += (v1 * m1 + v2 * m2 + v3 * m3 + v4 * m4)
196
+ b.limit(max: limit)
197
+ b.pos += b.vel
214
198
  end
215
199
  constrain
216
200
  end
data/vendors/Rakefile CHANGED
@@ -8,8 +8,8 @@ WARNING = <<-EOS
8
8
 
9
9
  EOS
10
10
 
11
- JRUBYC_VERSION = '9.0.1.0'
12
- EXAMPLES = '0.8'
11
+ JRUBYC_VERSION = '9.0.3.0'
12
+ EXAMPLES = '1.0'
13
13
  HOME_DIR = ENV['HOME']
14
14
  MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
15
15
 
@@ -27,7 +27,7 @@ file "jruby-complete-#{JRUBYC_VERSION}.jar" do
27
27
  rescue
28
28
  warn(WARNING)
29
29
  end
30
- check_sha1("jruby-complete-#{JRUBYC_VERSION}.jar", "523f0054455d85cdfc53af6eb8e925228feb9777")
30
+ check_sha1("jruby-complete-#{JRUBYC_VERSION}.jar", "d57e15c1bf3068cecaf0f2dab95affa4072114f6")
31
31
  end
32
32
 
33
33
  directory "../lib/ruby"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby_art
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-09-30 00:00:00.000000000 Z
13
+ date: 2015-10-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement
@@ -70,7 +70,7 @@ dependencies:
70
70
  version: '5.8'
71
71
  description: |2
72
72
  JRubyArt is a ruby wrapper for the processing art framework.
73
- The current version supports processing-3.0b7, and uses jruby-9.0.1.0
73
+ The current version supports processing-3.0, and uses jruby-9.0.3.0
74
74
  as the glue between ruby and java. You can use both processing libraries and ruby
75
75
  gems in your sketches. Features create/run/watch/live modes. The "watch" mode,
76
76
  provides a nice REPL-ish way to work on your processing sketches. Includes:-
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - A decent graphics card
130
130
  - java runtime >= 1.8+
131
- - processing = 3.0b7+
131
+ - processing = 3.0+
132
132
  rubyforge_project:
133
133
  rubygems_version: 2.4.8
134
134
  signing_key: