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 +4 -4
- data/lib/jruby_art/creators/creator.rb +4 -2
- data/lib/jruby_art/version.rb +1 -1
- data/lib/rpextras.jar +0 -0
- data/library/boids/boids.rb +82 -98
- data/vendors/Rakefile +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a6cd608ad55dfa06a0d23d02cd9f8d211f628e4
|
4
|
+
data.tar.gz: 6771e86dee627b35774d39b42fd4076681be5454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
45
|
+
size %s, %s
|
46
|
+
# pixel_density(2) # here for hi-dpi displays only
|
45
47
|
# smooth # here
|
46
48
|
end
|
47
49
|
end
|
data/lib/jruby_art/version.rb
CHANGED
data/lib/rpextras.jar
CHANGED
Binary file
|
data/library/boids/boids.rb
CHANGED
@@ -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
|
-
#
|
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, :
|
7
|
+
attr_accessor :boids, :pos, :vel, :is_perching, :perch_time
|
8
8
|
|
9
|
-
def initialize(boids,
|
9
|
+
def initialize(boids, pos)
|
10
10
|
@boids, @flock = boids, boids
|
11
|
-
@
|
12
|
-
@
|
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
|
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
|
-
|
21
|
-
boids.
|
22
|
-
|
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
|
-
|
26
|
-
|
24
|
+
count = @boids.length - 1.0
|
25
|
+
vect /= count
|
26
|
+
(vect - pos) / d
|
27
27
|
end
|
28
28
|
|
29
|
-
def separation(radius
|
29
|
+
def separation(radius:)
|
30
30
|
# Boids don't like to cuddle.
|
31
|
-
|
32
|
-
boids.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
38
|
+
vect
|
39
39
|
end
|
40
40
|
|
41
|
-
def alignment(d
|
41
|
+
def alignment(d:)
|
42
42
|
# Boids like to fly at the speed of traffic.
|
43
|
-
|
44
|
-
boids.
|
45
|
-
|
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
|
-
|
49
|
-
|
47
|
+
count = @boids.length - 1.0
|
48
|
+
vect /= count
|
49
|
+
(vect - vel) / d
|
50
50
|
end
|
51
51
|
|
52
|
-
def limit(max
|
52
|
+
def limit(max:)
|
53
53
|
# Tweet, Tweet! The boid police will bust you for breaking the speed limit.
|
54
|
-
most = [
|
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
|
-
@
|
58
|
-
@vy *= scale
|
59
|
-
@vz *= scale
|
57
|
+
@vel *= scale
|
60
58
|
end
|
61
59
|
|
62
60
|
def angle
|
63
|
-
|
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(
|
64
|
+
def goal(target, d = 50.0)
|
69
65
|
# Them boids is hungry.
|
70
|
-
|
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
|
-
|
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
|
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
|
-
@
|
102
|
+
@perch_tm = -> { 25.0 + rand(50.0) }
|
115
103
|
@has_goal = false
|
116
104
|
@flee = false
|
117
|
-
@
|
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
|
131
|
-
ground
|
132
|
-
@perch
|
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(
|
128
|
+
def goal(target:, flee: false)
|
140
129
|
@has_goal = true
|
141
130
|
@flee = flee
|
142
|
-
@
|
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.
|
154
|
-
b.
|
155
|
-
b.
|
156
|
-
b.
|
157
|
-
b.
|
158
|
-
b.
|
159
|
-
next unless b.y >
|
160
|
-
b.y =
|
161
|
-
b.
|
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
|
-
|
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(
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
b.
|
209
|
-
b.
|
210
|
-
b.
|
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.
|
12
|
-
EXAMPLES = '0
|
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", "
|
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.
|
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-
|
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.
|
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.
|
131
|
+
- processing = 3.0+
|
132
132
|
rubyforge_project:
|
133
133
|
rubygems_version: 2.4.8
|
134
134
|
signing_key:
|