Permalink
Browse files

update gemspec, mainly style thing

  • Loading branch information...
1 parent 09cb3fc commit 4bdebe63d2075be33e115ab0755b19f3db519cf8 @monkstone monkstone committed Dec 17, 2013
Showing with 83 additions and 82 deletions.
  1. +2 −0 CHANGELOG
  2. +1 −3 Gemfile
  3. +1 −1 lib/ruby-processing/version.rb
  4. +52 −53 library/boids/boids.rb
  5. +27 −25 ruby-processing.gemspec
View
@@ -1,3 +1,5 @@
+v2.4.1 Update gemspec to match modern expectations
+
v2.4.0 Returning to rubygems distribution, by not including any jars
* Use jars from an installed version of vanilla processing-2.0.3 (or version 2.1.0 linux and windows)
* Require an installed jruby (with an optional jruby-complete-1.7.8 post
View
@@ -1,8 +1,6 @@
source 'https://rubygems.org'
+# Specify your gem's dependencies in ruby-processing.gemspec
gemspec
-group :test do
- gem 'minitest'
-end
@@ -1,3 +1,3 @@
module RubyProcessing
- VERSION="2.4.0"
+ VERSION="2.4.1"
end
View
@@ -14,43 +14,43 @@ def initialize(boids, x, y, z)
@perch_time = 0.0
end
- def cohesion(d = 100.0)
+ def cohesion(d = 100.0)
# Boids gravitate towards the center of the flock,
# Which is the averaged position of the rest of the boids.
- vx = vy = vz = 0.0
- @boids.each do |boid|
- vx, vy, vz = vx+boid.x, vy+boid.y, vz+boid.z unless boid.equal? self
+ cvx, cvy, cvz = 0.0, 0.0, 0.0
+ boids.each do |boid|
+ cvx, cvy, cvz = cvx+boid.x, cvy+boid.y, cvz+boid.z unless boid.equal? self
end
- count = @boids.length - 1.0
- vx, vy, vz = vx/count, vy/count, vz/count
- return (vx - @x) / d, (vy - @y) / d, (vz - @z) / d
+ count = boids.length - 1.0
+ cvx, cvy, cvz = cvx/count, cvy/count, cvz/count
+ return (cvx - x) / d, (cvy - y) / d, (cvz - z) / d
end
def separation(radius = 10.0)
# Boids don't like to cuddle.
- vx = vy = vz = 0.0
- @boids.each do |boid|
+ svx, svy, svz = 0.0, 0.0, 0.0
+ boids.each do |boid|
unless boid.equal? self
- dvx, dvy, dvz = @x - boid.x, @y - boid.y, @z - boid.z
- vx += dvx if dvx.abs < radius
- vy += dvy if dvy.abs < radius
- vz += dvz if dvz.abs < radius
+ dvx, dvy, dvz = x - boid.x, y - boid.y, z - boid.z
+ svx += dvx if dvx.abs < radius
+ svy += dvy if dvy.abs < radius
+ svz += dvz if dvz.abs < radius
end
end
- return vx, vy, vz
+ return svx, svy, svz
end
def alignment(d = 5.0)
# Boids like to fly at the speed of traffic.
- vx = vy = vz = 0.0
- @boids.each do |boid|
+ avx, avy, avz = 0.0, 0.0, 0.0
+ boids.each do |boid|
unless boid.equal? self
- vx, vy, vz = vx+boid.vx, vy+boid.vy, vz+boid.vz
+ avx, avy, avz = avx+boid.vx, avy+boid.vy, avz+boid.vz
end
end
- count = @boids.length - 1.0
- vx, vy, vz = vx / count, vy / count, vz / count
- return (vx - @vx) / d, (vy - @vy) / d, (vz - @vz) / d
+ count = boids.length - 1.0
+ avx, avy, avz = avx / count, avy / count, avz / count
+ return (avx - vx) / d, (avy - vy) / d, (avz - vz) / d
end
def limit(max=30.0)
@@ -69,28 +69,28 @@ def angle
return a
end
- def goal(x, y, z, d = 50.0)
+ def goal(gx, gy, gz, d = 50.0)
# Them boids is hungry.
- return (x - @x) / d, (y - @y) / d, (z - @z) / d
+ return (gx - x)/d, (gy - y)/d, (gz - z)/d
end
end
-class Boids
- extend Enumerable
-
+class Boids
+ extend Enumerable
+
attr_accessor :boids, :x, :y, :w, :h,
:scattered, :has_goal, :flee
attr_reader :scatter, :scatter_time, :scatter_i,
- :perch, :perch_y, :perch_t,
+ :perch, :perch_y, :perch_t, :boids,
:goal_x, :goal_y, :goal_z
-
+
def initialize
@boids = []
end
-
+
def each &block
boids.each &block
end
@@ -106,7 +106,7 @@ def << obj
def length
boids.length
end
-
+
def self.flock(n, x, y, w, h)
return Boids.new.setup(n, x, y, w, h)
end
@@ -123,8 +123,8 @@ def setup(n, x, y, w, h)
@scatter_time = 50.0
@scatter_i = 0.0
@perch = 1.0 # Lower this number to divebomb.
- @perch_y = @h
- @perch_time = -> {rand(25.0 .. 75.0)} # so we can call perch_time
+ @perch_y = h
+ @perch_t = -> {rand(25..75.0)}
@has_goal = false
@flee = false
@goal_x = @goal_y = @goal_z = 0.0
@@ -140,20 +140,20 @@ def no_scatter
@scatter = 0.0
end
- # def perch(ground = nil, chance = 1.0, frames = nil)
- # frames ||= -> {rand(25.0 .. 75.0)}
- # ground ||= @h
- # @perch, @perch_y, @perch_time = chance, ground, frames
- # end
+ def perch(ground = nil, chance = 1.0, frames = nil)
+ frames ||= -> {rand(25..75.0)}
+ ground ||= h
+ @perch, @perch_y, @perch_t = chance, ground, frames
+ end
def no_perch
@perch = 0.0
end
- def goal(x, y, z, flee = false)
+ def goal(gx, gy, gz, flee = false)
@has_goal = true
@flee = flee
- @goal_x, @goal_y, @goal_z = x, y, z
+ @goal_x, @goal_y, @goal_z = gx, gy, gz
end
def no_goal
@@ -162,34 +162,33 @@ def no_goal
def constrain
# Put them boids in a cage.
- dx, dy = @w * 0.1, @h * 0.1
+ dx, dy = w * 0.1, h * 0.1
self.each do |b|
- b.vx += rand(dx) if b.x < @x - dx
- b.vx += rand(dy) if b.y < @y - dy
- b.vx -= rand(dx) if b.x > @x + @w + dx
- b.vy -= rand(dy) if b.y > @y + @h + dy
+ b.vx += rand(dx) if b.x < x - dx
+ b.vx += rand(dy) if b.y < y - dy
+ b.vx -= rand(dx) if b.x > x + w + dx
+ b.vy -= rand(dy) if b.y > y + h + dy
b.vz += 10.0 if b.z < 0.0
b.vz -= 10.0 if b.z > 100.0
if b.y > @perch_y && rand < @perch
b.y = @perch_y
b.vy = -(b.vy.abs) * 0.2
b.is_perching = true
- @perch_time.respond_to?(:call) ? b.perch_time = @perch_time.call : b.perch_time = @perch
+ @perch_t.respond_to?(:call) ? b.perch_time = @perch_t.call : b.perch_time = @perch_t
end
end
end
-
-
+
def update(opts={})
# Just flutter, little boids ... just flutter away.
# Shuffling keeps things flowing smooth.
- options = {shuffled: true,
- cohesion: 100.0,
- separation: 10.0,
- alignment: 5.0,
- goal: 20.0,
- limit: 30.0}
+ options = {:shuffled => true,
+ :cohesion => 100.0,
+ :separation => 10.0,
+ :alignment => 5.0,
+ :goal => 20.0,
+ :limit => 30.0}
options.merge! opts
self.shuffle! if options[:shuffled]
@@ -241,4 +240,4 @@ def update(opts={})
end
end
-
+
@@ -1,30 +1,16 @@
-require 'rake'
-require "./lib/ruby-processing"
-
-Gem::Specification.new do |s|
- s.name = "ruby-processing"
- s.version = RubyProcessing::VERSION
- s.authors = ["Jeremy Ashkenas", "Peter Gassner", "Martin Stannard", "Andrew Nanton",
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'ruby-processing/version'
+
+Gem::Specification.new do |spec|
+ spec.name = "ruby-processing"
+ spec.version = RubyProcessing::VERSION
+ spec.authors = ["Jeremy Ashkenas", "Peter Gassner", "Martin Stannard", "Andrew Nanton",
"Marc Chung", "Peter Krenn", "Florian Jenett", "Andreas Haller",
"Juris Galang", "Guillaume Pierronnet", "Martin Prout"]
- s.date = "2013-11-06"
- s.default_executable = "rp5"
- s.email = "jeremy@ashkenas.com"
- s.executables = ["rp5", "install_jruby_complete"]
- s.license = 'MIT'
- s.files = FileList['bin/**/*', 'lib/**/*', 'library/**/*', 'samples/**/*', 'vendors/*'].to_a
- s.platform = Gem::Platform::RUBY
- s.homepage = "http://wiki.github.com/jashkenas/ruby-processing"
- s.required_ruby_version = '>= 1.9.3'
- s.require_paths = ["lib"]
- s.rubyforge_project = "ruby-processing"
- s.requirements << 'A decent graphics card'
- s.requirements << 'java runtime >= 1.6+'
- s.requirements << 'processing = 2.0.3 or greater if not on a Mac'
- s.add_development_dependency 'minitest'
- s.add_development_dependency 'rake'
- s.summary = "Code as Art, Art as Code. Processing and Ruby are meant for each other."
- s.description = <<-EOS
+ spec.email = "jeremy@ashkenas.com"
+ spec.description = <<-EOS
Ruby-Processing is a Ruby wrapper for the Processing code art framework. It's
this thin little shim that squeezes between Processing and JRuby, passing
@@ -48,5 +34,21 @@ Gem::Specification.new do |s|
to work on your Processing sketches.
EOS
+ spec.summary = %q{Code as Art, Art as Code. Processing and Ruby are meant for each other.}
+ spec.homepage = "http://wiki.github.com/jashkenas/ruby-processing"
+ spec.executables = ["rp5", "install_jruby_complete"]
+ spec.license = 'MIT'
+
+ spec.files = `git ls-files`.split($/)
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
+
+ spec.add_development_dependency "bundler", "~> 1.3"
+ spec.add_development_dependency "rake"
+ spec.add_development_dependency 'minitest'
+ spec.requirements << 'A decent graphics card'
+ spec.requirements << 'java runtime >= 1.6+'
+ spec.requirements << 'processing = 2.0.3+'
+
end

0 comments on commit 4bdebe6

Please sign in to comment.