Sha256: ec80a74607aa5461decaff56bb2c5630b520d80d13fc8ad9af9569f62d0d9ebf

Contents?: true

Size: 622 Bytes

Versions: 11

Compression:

Stored size: 622 Bytes

Contents

require 'toxiclibs'
require_relative 'attractor'
require_relative 'particle'

attr_reader :particles, :attractor, :physics

def settings
  size 640, 360
end

def setup
  sketch_title "Attract Repel"
  @physics = Physics::VerletPhysics2D.new
  physics.setDrag(0.01)
  @particles = (0..50).map { Particle.new(TVec2D.new(rand(width), rand(height))) }
  @attractor = Attractor.new(TVec2D.new(width / 2, height / 2))
end

def draw
  background(255)
  physics.update
  attractor.display
  particles.each(&:display)
  if mouse_pressed?
    attractor.lock
    attractor.set(mouse_x, mouse_y)
  else
    attractor.unlock
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
toxiclibs-2.1.0 examples/attract_repel/attract_repel.rb
toxiclibs-2.0.0 examples/attract_repel/attract_repel.rb
toxiclibs-1.0.0 examples/attract_repel/attract_repel.rb
toxiclibs-0.9.3 examples/attract_repel/attract_repel.rb
toxiclibs-0.9.2 examples/attract_repel/attract_repel.rb
toxiclibs-0.9.1 examples/attract_repel/attract_repel.rb
toxiclibs-0.9.0 examples/attract_repel/attract_repel.rb
toxiclibs-0.8.0 examples/attract_repel/attract_repel.rb
toxiclibs-0.6.0-java examples/attract_repel/attract_repel.rb
toxiclibs-0.5.1-java examples/attract_repel/attract_repel.rb
toxiclibs-0.5.0-java examples/attract_repel/attract_repel.rb