Jay McGavren's Journal

2009-08-20

Physics...

Video here.

    set_manager :physics, create_game_object(:BasicPhysicsManager)

    spawner = create :GameObject, :ReceivesEvents
    load_keymap :MouseKeymap
    spawner.handle_event :mouse_pressed do |message|
      object = create :GameObject, :Physical
      object.set_physical_debug_mode true
      case rand(2)
      when 0
        object.set_shape :Box, 10, 5
      when 1
        object.set_shape :Circle, 10
      end
      object.body_position = message.value.pointer
    end

Read more...
2009-08-19

Logan put together a pretty impressive container for Jemini (note the rename for Google-ability) demos. Just pick from a menu to load a state. Showing a description? One line. Offering running updates on a variable’s value? One line.

class AudibleState < Gemini::BaseState

  def create_ui
    text "Click in different places in the window to emit a sound at different pitches and volumes."
    watch('Pitch') { @pitch }
    watch('Volume') { @volume }
  end

  def load
    
    set_manager :sound, create(:SoundManager)

    audible = create :GameObject, :Audible, :ReceivesEvents
    
    audible.load_sound :boom, "boom.wav"
    
    load_keymap :MouseKeymap
    
    audible.handle_event :mouse_pressed do |message|
      @pitch = message.value.pointer.x / 100.0
      @volume = message.value.pointer.y / 100.0
      audible.emit_sound :boom, @volume, @pitch
    end
    
  end
end

Read more...
2009-08-19

:)

Aquarius lyrics Artist: Boards of Canada

yeah thats right

ORANGE

yeah thats right

ORANGE

giggle

one ORANGE (Just Fantasize) two three

Read more...
2009-08-15

MIDIator...

Well, that was easy. Heard about MIDIator (a MIDI event generator for Ruby) on a Confreaks talk, and since I already had MIDI Patchbay and SimpleSynth installed from prior attempts to get things working, I gave it a shot.

Here’s some code that hooks it into a Rinda tuplespace:

require 'rinda/rinda'
require 'rubygems'
require 'midiator'

MY_URI = ARGV[0] || "druby://127.0.0.1:9999"
DRb.start_service
space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, MY_URI))

midi = MIDIator::Interface.new
midi.autodetect_driver

loop do
  key, value = space.take([/Integer/, Integer])
  midi.play value, 0.01
end

And here’s what it sounds like in action. I’m sure a better/more skilled controller would make it sound less, uh, horrible. :) Boy, it sure processes those events fast…

Read more...
2009-08-08

Ooh, purty...

mouse_client.rb:

require 'rubygems'
require 'wx'
require 'rinda/rinda'

MY_URI = "druby://127.0.0.1:9999"
TIME_TO_LIVE = 10

class MouseClient  [800, 600],
      :title => "Click and Drag"
    )
    frame.evt_close {exit}
    frame.evt_motion {|event| on_mouse_motion(event)}
    frame.evt_left_down {|event| on_mouse_press(event)}
    frame.evt_left_up {|event| on_mouse_release(event)}
    frame.show
  end

  def on_mouse_motion(event)
    return unless event.dragging
    space.write ["Integer:x", event.x], TIME_TO_LIVE
    space.write ["Integer:y", event.y], TIME_TO_LIVE
  end

  def on_mouse_press(event); end
  def on_mouse_release(event); end

end

client = MouseClient.new

DRb.start_service
client.space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, MY_URI))
client.main_loop

string_length_agent.rb:

require 'rinda/rinda'
MY_URI = ARGV[0] || "druby://127.0.0.1:9999"
DRb.start_service
space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, MY_URI))

def scale(value)
  @largest_seen = value if @largest_seen == nil or value > @largest_seen
  value.to_f / @largest_seen
end

loop do
  key, value = space.take([/Integer/, nil])
  puts "#{key}: #{'|' * (scale(value) * 68.0)}"
end

The result:

Read more...