-
Notifications
You must be signed in to change notification settings - Fork 1
/
random.rb
38 lines (31 loc) · 804 Bytes
/
random.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
require 'artoo'
require 'byebug'
connection :sphero, :adaptor => :sphero, :port => '/dev/tty.Sphero-YBB-AMP-SPP'
device :sphero, :driver => :sphero
connection :keyboard, adaptor: :keyboard
device :keyboard, driver: :keyboard, connection: :keyboard
def keypress(sender, key)
case key
when 'q'
exit
end
end
def contact(str, coll)
$direction = $direction + Random.new.rand(45..90)
$direction = $direction % 360
end
work do
on keyboard, :key => :keypress
on sphero, :collision => :contact
$direction = Random.new.rand(0..360)
@count = 1
every(3.seconds) do
r = Random.new.rand(0..255)
g = Random.new.rand(0..255)
b = Random.new.rand(0..255)
sphero.set_color(r,g,b)
puts 'direction' + $direction.to_s
@count += 1
sphero.roll 75, $direction
end
end