Sha256: fa0c40df38f2363617770d4f6ff155239e72f6349bf0a751d04c28abc14a1378

Contents?: true

Size: 1.16 KB

Versions: 25

Compression:

Stored size: 1.16 KB

Contents

%w[xot rays reflex]
  .map  {|s| File.expand_path "../../#{s}/lib", __dir__}
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}

require 'reflex'


Reflex.start name: "Physics" do |app|
  Reflex::Window.show title: app.name, frame: [100, 100, 500, 500] do
    gravity 0, 9.8 * meter
    #debug   true

    add_dynamic = -> x = rand(10..400), y = rand(10..100), size_ = 50 do
      add Reflex::View.new {
        pos        x, y
        size       rand 5..size_
        background [:red, :green, :blue, :yellow, :orange, :pink, :peach].sample
        dynamic    true
        shape      Reflex::EllipseShape.new(density: 1)
      }
    end

    add_static = -> size_ = 50 do
      add Reflex::View.new {
        pos        rand(10..400), rand(200..400)
        size       rand(5..(size_ * 2)), rand(5..size_)
        background :darkgray
        static     true
      }
    end

    50.times {|n| add_dynamic.call}
    5.times  {|n| add_static.call}

    after :draw do |e|
      e.painter.push do
        fill :white
        text "#{e.fps.to_i} FPS", 10, 10
      end
    end

    on :pointer do |e|
      add_dynamic.call *e.pos.to_a if e.down? || e.drag?
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
reflexion-0.3 samples/physics.rb
reflexion-0.2.1 samples/physics.rb
reflexion-0.2 samples/physics.rb
reflexion-0.1.57 samples/physics.rb
reflexion-0.1.56 samples/physics.rb
reflexion-0.1.55 samples/physics.rb
reflexion-0.1.54 samples/physics.rb
reflexion-0.1.53 samples/physics.rb
reflexion-0.1.52 samples/physics.rb
reflexion-0.1.51 samples/physics.rb
reflexion-0.1.50 samples/physics.rb
reflexion-0.1.49 samples/physics.rb
reflexion-0.1.48 samples/physics.rb
reflexion-0.1.47 samples/physics.rb
reflexion-0.1.46 samples/physics.rb
reflexion-0.1.45 samples/physics.rb
reflexion-0.1.44 samples/physics.rb
reflexion-0.1.43 samples/physics.rb
reflexion-0.1.42 samples/physics.rb
reflexion-0.1.41 samples/physics.rb