Sha256: 617026f9b537644f9985a6ed025f9a89dc3faef72591985437f578af7a738c59

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

require 'pbox2d'
require_relative 'lib/particle_system'
require_relative 'lib/boundary'
attr_reader :box2d, :boundaries, :systems

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

def setup
  sketch_title 'Liquidy'
  @box2d = Box2D.new(self)
  box2d.init_options(gravity: [0, -20])
  box2d.create_world
  @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

def settings
  size(400,300)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pbox2d-0.5.0-java examples/liquidy.rb