Skip to content

Instantly share code, notes, and snippets.

View Neurogami's full-sized avatar

Neurogami Neurogami

View GitHub Profile
module Neurogami
module Leap
class BasicListener < LeapMotion::Listener
def onInit controller
puts "#{self.inspect} Initialized with #{controller.inspect}"
end
def onConnect controller
// This goes into the module Neurogami::Leap
class Controller < LeapMotion::Controller
end
class Vector < LeapMotion::Vector
end
class Java::ComLeapmotionLeap::Frame
alias_method :leap_hands, :hands
def hands
leap_hands.to_a
end
end
# Example JRuby LeapMotion program based on the Java example included in the Leap Motion SDK.
#
$:.unshift './jleap-ng'
require 'jleap-ng'
include Neurogami::Leap
class ExampleListener < BasicListener
def onInit controller
def onFrame controller
frame = controller.frame
puts "Frame id: #{ frame.id}, timestamp: #{frame.timestamp}, hands: #{frame.hands.count}, fingers: #{frame.fingers.count} , tools: #{frame.tools.count}"
if !frame.hands.empty?
hand = frame.hands[0]
fingers = hand.fingers
if !fingers.empty?
# Calculate the hand's average finger tip position
class Example
def initialize
listener = ExampleListener.new
controller = Controller.new
controller.add_listener listener
warn "Press Enter to quit..."
begin
@Neurogami
Neurogami / web-socket-server.rb
Created February 19, 2013 05:28
simple lib for using a WebSocket server with a channel
#Thread.abort_on_exception = true # Might want to reserve this option for what code is using this library
require 'em-websocket'
require 'json'
class SocketServer
def initialize port = 8090, host = '127.0.0.1'
@port = port
@host = host
@Neurogami
Neurogami / jleap-ng-snippet-hand.rb
Created February 19, 2013 05:47
hacking the core Leap classes: Hand
class Java::ComLeapmotionLeap::Hand
alias_method :leap_fingers, :fingers
def fingers
leap_fingers.to_a
end
end
@Neurogami
Neurogami / wsForGameDemo.rb
Last active December 13, 2015 22:19
An experiment in code design
# Adjust as needed to get the libraries loaded
$:.unshift '.'
$:.unshift './jleap-ng'
require 'jleap-ng'
require 'web-socket-server'
require 'game-demo-handlers'
require 'json'
require 'osc-ruby'
@Neurogami
Neurogami / game-demo-handlers.rb
Created February 19, 2013 19:48
Leap condition handlers
# The idea is that you Listener class gets an array of ConditionHandler objects and
# in onFrame loops over them, invoking `run` on each one
class ConditionHandler
def initialize &contitions_block
@conditions = contitions_block
end
def run frame
@conditions.call frame
end