Sha256: 6f26ab8a9f032b9f9a882f5f8a2aa0c6fac7c6b0946d44d8a799023603a2e470

Contents?: true

Size: 956 Bytes

Versions: 5

Compression:

Stored size: 956 Bytes

Contents

require 'propane'
require 'pbox2d'
require_relative 'lib/particle_system'
require_relative 'lib/boundary'

Vect = Struct.new(:x, :y)

class Liquidy < Propane::App
  attr_reader :box2d, :boundaries, :systems
  
  def setup
    size(400, 300)
    @box2d = WorldBuilder.build(app: self, gravity: [0, -20])
    @systems = []
    @boundaries = [
    Boundary.new(box2d, Vect.new(50, 100), Vect.new(300, 5), -0.3),
    Boundary.new(box2d, Vect.new(250, 175), Vect.new(300, 5), 0.5)
    ]
  end
  
  def draw
    background(255)
    # Run all the particle systems
    if systems.size > 0
      systems.each do |system|
        system.run
        system.add_particles(box2d, rand(0..2))
      end
    end
    # Display all the boundaries
    boundaries.each(&:display)
  end
  
  def mouse_pressed
    # Add a new Particle System whenever the mouse is clicked
    systems << ParticleSystem.new(box2d, 0, mouse_x, mouse_y)
  end  
end

Liquidy.new title: 'Liquidy'

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
propane-0.7.0-java examples/regular/liquidy.rb
propane-0.6.0-java examples/regular/liquidy.rb
propane-0.5.0-java examples/regular/liquidy.rb
propane-0.4.0.pre-java examples/regular/liquidy.rb
propane-0.3.0.pre-java examples/regular/liquidy.rb