-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhue-magick.rb
70 lines (55 loc) · 1.54 KB
/
hue-magick.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
require 'bundler'
Bundler.require
HUE_CHANGE_INTERVAL = 1.0 # [s]
GESTURE_INTERVAL = 2.0 # [s]
EM::run do
# Linda cconnection
url = ENV["LINDA_BASE"] || ARGV.shift || "http://linda.masuilab.org"
space = ENV["LINDA_SPACE"] || "delta"
puts "linda connecting... #{url}"
linda = EM::RocketIO::Linda::Client.new url
ts = linda.tuplespace[space]
linda.io.on :connect do ## RocketIO's "connect" event
puts "linda connected #{url}"
# Leap motion
puts "leap motion connecting..."
leap = LeapMotion.connect :gestures => true
leap.on :connect do
puts "leap motion connected"
end
ges_last = Time.now
leap.on :gestures do |gestures|
gestures.each do |g|
now = Time.now
if g.type == "swipe" && g.state == "stop" && now - ges_last > GESTURE_INTERVAL
if g.direction[1] > 0 #up
ts.write ["hue", "on"]
puts "Up - hue:on #{now}"
else
ts.write ["hue", "off"]
puts "Down - hue:off #{now}"
end
ges_last = now
end
end
end
hue = 0
data_last = 0
leap.on :data do |data|
print "*"
now = data.timestamp
if data.hands.length >= 2 && now - data_last > HUE_CHANGE_INTERVAL * 1000 * 1000
ts.write ["hue", 0, "hsb", hue, 255, 255]
puts "Double Hands - hue:change_colors #{now}"
data_last = now
hue += 5000
hue %= 65536
end
end
leap.on :error do |err|
STDERR.puts err
end
# leap.wait
end
end