Sha256: f21da2f53860fca4b4fadb7c3db0473dccdf51400d91fa265d4aa2df65a66600

Contents?: true

Size: 928 Bytes

Versions: 5

Compression:

Stored size: 928 Bytes

Contents

require 'forwardable'

module Runnable
  def run
    reject!(&:dead?)
    each(&:display)
  end
end

class RainDrops
  include Enumerable, Runnable
  extend Forwardable
  
  def_delegators(:@drops, :<<, :each, :reject!,  :size)

  attr_reader :drops, :width, :height #, :weight

  def initialize(width, height)
    @drops = []
    @width = width
    @height = height
  end
  
  def fill_up(weight)
    # @weight = weight
    drops << Drop.new(rand(width), rand(height / 2) - height / 2, weight) 
  end
end

class Drop
  include Propane::Proxy
  attr_reader :weight, :x, :y
  
  def initialize(x, y, weight = nil)
    @weight = weight || 10
    @x, @y = x, y
  end
  
  def render
    fill(100, 100, 200)
    no_stroke
    bezier(x, y,  x - (weight / 2), y + weight, x + (weight / 2), y + weight, x, y)
  end
  
  def dead?
    @y > height
  end
  
  def display
    @y = y + weight
    @x = x - rand(-3..3)
    render
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
propane-0.8.0-java examples/regular/lib/rain_drops.rb
propane-0.7.0-java examples/regular/lib/rain_drops.rb
propane-0.6.0-java examples/regular/lib/rain_drops.rb
propane-0.5.0-java examples/regular/lib/rain_drops.rb
propane-0.4.0.pre-java examples/regular/lib/rain_drops.rb