Module: Blink::Patterns

Defined in:
lib/blink1-patterns.rb,
lib/blink1-patterns/version.rb

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.breath(hex_color = "#0000ff", length = 5, depth = 0.3) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/blink1-patterns.rb', line 6

def self.breath(hex_color = "#0000ff", length = 5, depth = 0.3) 
  brightness = [0.0000, 0.0293, 0.1427, 0.4128, 0.8459, 1.0000, 0.8336, 0.5159, 0.2334, 0.0574, 0.0141, 0.0000]
  interval   = [1.5,    1.0,    1.0,    1.0,    1.2,    1.5,    1.2,    1.2,    1.2,    1.2,    1.2,    0.0]
  stretch    = length / interval.inject(:+) 

  Blink1.open do |blink|
    (0..11).each do |pos|
      color    = Blink::Patterns.darken(hex_color, (1 - brightness[pos]) * depth)
      duration = (stretch * interval[pos] * 1000).to_i
      blink.write_pattern_line(duration, *color, pos)
    end
    blink.play(0)
  end
end

.darken(hex_color, amount = 0.4) ⇒ Object



49
50
51
# File 'lib/blink1-patterns.rb', line 49

def self.darken(hex_color, amount=0.4)
  to_rgb(hex_color).map { |c| (c * (1 - amount)).round }
end

.offObject



39
40
41
42
43
# File 'lib/blink1-patterns.rb', line 39

def self.off
  Blink1.open do |blink|
    blink.off
  end
end

.policeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/blink1-patterns.rb', line 21

def self.police
  Blink1.open do |blink|
    blink.write_pattern_line(500, *Blink::Patterns.to_rgb("#000000"), 0)
    blink.write_pattern_line(100, *Blink::Patterns.to_rgb("#ff0000"), 1)
    blink.write_pattern_line(500, *Blink::Patterns.to_rgb("#000000"), 2)
    blink.write_pattern_line(100, *Blink::Patterns.to_rgb("#0000ff"), 3)
    blink.write_pattern_line(0, 0, 0, 0, 4)
    blink.write_pattern_line(0, 0, 0, 0, 5)
    blink.write_pattern_line(0, 0, 0, 0, 6)
    blink.write_pattern_line(0, 0, 0, 0, 7)
    blink.write_pattern_line(0, 0, 0, 0, 8)
    blink.write_pattern_line(0, 0, 0, 0, 9)
    blink.write_pattern_line(0, 0, 0, 0, 10)
    blink.write_pattern_line(0, 0, 0, 0, 11)
    blink.play(0)
  end 
end

.to_rgb(hex_color) ⇒ Object



45
46
47
# File 'lib/blink1-patterns.rb', line 45

def self.to_rgb(hex_color)
  hex_color.gsub('#','').scan(/../).map {|color| color.hex}
end