Sha256: 1969e7e5f34bbfdc1194166cb34f74466da93f872ecb21a94564a6f428285f87
Contents?: true
Size: 873 Bytes
Versions: 2
Compression:
Stored size: 873 Bytes
Contents
require 'pbox2d' require_relative 'lib/particle_system' attr_reader :box2d, :boundaries, :systems def setup size(400, 300) @box2d = Box2D.new(self) box2d.init_options(gravity: [0, -20]) box2d.create_world # to set a custom gravity otherwise # box2d.gravity([0, -20]) # Create Arrays @systems = [] @boundaries = [] # Add a bunch of fixed boundaries boundaries << Boundary.new(self, 50, 100, 5, -0.3) boundaries << Boundary.new(self, 250, 175, 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(self, 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(self, 0, mouse_x, mouse_y) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pbox2d-0.4.1-java | examples/liquidy.rb |
pbox2d-0.4.0-java | examples/liquidy.rb |