Skip to content

Commit

Permalink
new app - rebound, a monomer version of pixelmechanic's boiingg :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
samaaron committed Jun 25, 2008
1 parent 0bd10e0 commit 032e809
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
50 changes: 50 additions & 0 deletions apps/pixelmechanic/rebound.rb
@@ -0,0 +1,50 @@
#!/usr/bin/env jruby -wKU

#monomer version of pixelmechanic's boiingg: http://docs.monome.org/doku.php?id=app:boiingg

require File.dirname(__FILE__) + '/../../lib/monomer'

class Rebound < Monomer::Listener

before_start do
@midi = Monomer::MidiOut.new
@position = [0] * monome.row_size
@direction = [0] * monome.row_size
@range = [0] * monome.row_size
end

on_start do
timely_repeat(0.14) do
update_patterns
send_midi_and_light_monome
end
end

on_key_down do |x,y|
@range[x] = y
@direction[x]= -1
@position[x] = y
end

def self.update_patterns
@range.each_with_index do |range, index|
if range != 0
@position[index] += @direction[index]
@direction[index] *= -1 if @position[index] == 0 || @position[index] == range
end
end
end

def self.send_midi_and_light_monome
@position.each_with_index do |position, index|
monome.clear_column(index)
if @range[index] != 0
monome.led_on(index, position)
@midi.on(40 + index) if position == 0
end
end
end

end

Monomer::Monome.create.with_listeners(Rebound).start if $0 == __FILE__
3 changes: 2 additions & 1 deletion lib/monomer/monome.rb
Expand Up @@ -87,7 +87,8 @@ def toggle_led(x,y)
end

def clear_column(col)
light_column(col, 0,0,0,0,0,0,0,0)
col__light_pattern = (0..max_y).map{|y|led_off(col,y)}.map{|need_to_turn_off| need_to_turn_off ? 0 : 1}
light_column(col, *col__light_pattern)
end

def light_column(col, *pattern)
Expand Down

0 comments on commit 032e809

Please sign in to comment.