Class: CheekyDreams::Effects::Throb

Inherits:
Effect
  • Object
show all
Defined in:
lib/cheeky-dreams.rb

Constant Summary

Constants included from CheekyDreams

COLOURS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CheekyDreams

#ansi_driver, #audit_to, #crazy, #cycle, #dev_null, #fade, #fade_to, #find_dream_cheeky_usb_device, #forward, #func, #light_show, #max, #off, #position_between, #rgb, #rgb_between, #sleep_until, #solid, #stdio_audit, #stdout_driver, #suppress_duplicates, #throb, #throbbing

Constructor Details

#initialize(freq, from, to) ⇒ Throb

Returns a new instance of Throb.



268
269
270
271
272
273
274
275
# File 'lib/cheeky-dreams.rb', line 268

def initialize freq, from, to
  @freq = freq
  @r_centre, @r_amp = centre_and_amp from[0], to[0]
  @g_centre, @g_amp = centre_and_amp from[1], to[1]
  @b_centre, @b_amp = centre_and_amp from[2], to[2]
  @sin_freq = 3.14 / freq.to_f
  @count = (1.57 / @sin_freq).floor
end

Instance Attribute Details

#b_ampObject (readonly)

Returns the value of attribute b_amp.



266
267
268
# File 'lib/cheeky-dreams.rb', line 266

def b_amp
  @b_amp
end

#b_centreObject (readonly)

Returns the value of attribute b_centre.



266
267
268
# File 'lib/cheeky-dreams.rb', line 266

def b_centre
  @b_centre
end

#g_ampObject (readonly)

Returns the value of attribute g_amp.



266
267
268
# File 'lib/cheeky-dreams.rb', line 266

def g_amp
  @g_amp
end

#g_centreObject (readonly)

Returns the value of attribute g_centre.



266
267
268
# File 'lib/cheeky-dreams.rb', line 266

def g_centre
  @g_centre
end

#r_ampObject (readonly)

Returns the value of attribute r_amp.



266
267
268
# File 'lib/cheeky-dreams.rb', line 266

def r_amp
  @r_amp
end

#r_centreObject (readonly)

Returns the value of attribute r_centre.



266
267
268
# File 'lib/cheeky-dreams.rb', line 266

def r_centre
  @r_centre
end

Instance Method Details

#next(current_colour) ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/cheeky-dreams.rb', line 277

def next current_colour
  x = sin(@sin_freq * @count)
  r = x * r_amp + r_centre
  g = x * g_amp + g_centre
  b = x * b_amp + b_centre
  # x = freq * (@count += 1)
  # v = sin(x) * @amplitude + @centre
  # [v, 0, 0]
  
  @count += 1
  [[r.floor, g.floor, b.floor], @freq]
end