Sha256: 69d883b916ae31ce9ac6f4129e48d251336a3923c8a45acc19fb28225ebf753a

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

# -*- coding: utf-8 -*-


%w[xot rays reflex]
  .map  {|s| File.expand_path "../../../#{s}/lib", __FILE__}
  .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

16 entries across 16 versions & 1 rubygems

Version Path
reflexion-0.1.29 samples/physics.rb
reflexion-0.1.28 samples/physics.rb
reflexion-0.1.27 samples/physics.rb
reflexion-0.1.26 samples/physics.rb
reflexion-0.1.25 samples/physics.rb
reflexion-0.1.24 samples/physics.rb
reflexion-0.1.23 samples/physics.rb
reflexion-0.1.22 samples/physics.rb
reflexion-0.1.21 samples/physics.rb
reflexion-0.1.20 samples/physics.rb
reflexion-0.1.19 samples/physics.rb
reflexion-0.1.17 samples/physics.rb
reflexion-0.1.16 samples/physics.rb
reflexion-0.1.15 samples/physics.rb
reflexion-0.1.14 samples/physics.rb
reflexion-0.1.13 samples/physics.rb