Sha256: 6435149768cb629463c00c9dc670255d7c4c9d7cf7c458b20d66ff1307a2c8f7

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

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


%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

6 entries across 6 versions & 1 rubygems

Version Path
reflexion-0.1.35 samples/physics.rb
reflexion-0.1.34 samples/physics.rb
reflexion-0.1.33 samples/physics.rb
reflexion-0.1.32 samples/physics.rb
reflexion-0.1.31 samples/physics.rb
reflexion-0.1.30 samples/physics.rb