cheeky-dreams 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +4 -0
- data/VERSION +1 -1
- data/cheeky-dreams.gemspec +2 -2
- data/lib/cheeky-dreams.rb +90 -49
- data/{spec/small-test.rb → samples/fade-to-throb.rb} +4 -7
- data/spec/cheeky-dreams_spec.rb +112 -96
- data/spec/support/collecting_auditor.rb +2 -3
- data/spec/support/stub_effect.rb +16 -5
- metadata +11 -11
data/README.rdoc
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.6
|
data/cheeky-dreams.gemspec
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "cheeky-dreams"
|
|
8
|
-
s.version = "0.0.
|
|
8
|
+
s.version = "0.0.6"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["simon"]
|
|
@@ -27,9 +27,9 @@ Gem::Specification.new do |s|
|
|
|
27
27
|
"VERSION",
|
|
28
28
|
"cheeky-dreams.gemspec",
|
|
29
29
|
"lib/cheeky-dreams.rb",
|
|
30
|
+
"samples/fade-to-throb.rb",
|
|
30
31
|
"spec/cheeky-dreams_spec.rb",
|
|
31
32
|
"spec/off.rb",
|
|
32
|
-
"spec/small-test.rb",
|
|
33
33
|
"spec/spec_helper.rb",
|
|
34
34
|
"spec/support/collecting_auditor.rb",
|
|
35
35
|
"spec/support/stub_driver.rb",
|
data/lib/cheeky-dreams.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'thread'
|
|
2
|
+
require 'set'
|
|
2
3
|
|
|
3
4
|
module CheekyDreams
|
|
4
5
|
|
|
@@ -47,13 +48,13 @@ module CheekyDreams
|
|
|
47
48
|
end
|
|
48
49
|
end
|
|
49
50
|
|
|
50
|
-
class
|
|
51
|
-
def initialize
|
|
52
|
-
@
|
|
51
|
+
class ForwardingAuditor
|
|
52
|
+
def initialize rules
|
|
53
|
+
@rules = rules
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
def audit type, message
|
|
56
|
-
@
|
|
57
|
+
@rules[type].audit(type, message) if @rules.has_key?(type)
|
|
57
58
|
end
|
|
58
59
|
end
|
|
59
60
|
|
|
@@ -72,8 +73,28 @@ module CheekyDreams
|
|
|
72
73
|
end
|
|
73
74
|
end
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
AuditEvent = Struct.new(:type, :message)
|
|
77
|
+
|
|
78
|
+
class SuppressDuplicatesAuditor
|
|
79
|
+
def initialize auditor
|
|
80
|
+
@auditor, @audits = auditor, Set.new
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def audit type, message
|
|
84
|
+
event = AuditEvent.new type, message
|
|
85
|
+
unless @audits.include?(event)
|
|
86
|
+
@auditor.audit(type, message)
|
|
87
|
+
@audits << event
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def suppress_duplicates auditor
|
|
93
|
+
SuppressDuplicatesAuditor.new auditor
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def forward rules
|
|
97
|
+
ForwardingAuditor.new rules
|
|
77
98
|
end
|
|
78
99
|
|
|
79
100
|
def audit_to *auditors
|
|
@@ -136,17 +157,30 @@ module CheekyDreams
|
|
|
136
157
|
Effects::FadeTo.new to, steps, freq
|
|
137
158
|
end
|
|
138
159
|
|
|
139
|
-
def func
|
|
140
|
-
Effects::Func.new
|
|
160
|
+
def func &block
|
|
161
|
+
Effects::Func.new &block
|
|
141
162
|
end
|
|
142
163
|
|
|
143
164
|
def throb freq, from, to
|
|
144
165
|
Effects::Throb.new freq, from, to
|
|
145
166
|
end
|
|
146
167
|
|
|
147
|
-
def
|
|
168
|
+
def throbbing colour, freq = 10
|
|
169
|
+
rgb_colour = rgb(colour)
|
|
170
|
+
Effects::Throb.new freq, rgb_colour, [max(rgb_colour[0] - 200, 0), max(rgb_colour[1] - 200, 0), max(rgb_colour[2] - 200, 0)]
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def max a, b
|
|
174
|
+
a > b ? a : b
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def crazy freq = 10, new_effect_freq = 10
|
|
148
178
|
Effects::Crazy.new(freq, new_effect_freq)
|
|
149
179
|
end
|
|
180
|
+
|
|
181
|
+
def light_show *effects
|
|
182
|
+
Effects::LightShow.new effects
|
|
183
|
+
end
|
|
150
184
|
|
|
151
185
|
module Dev
|
|
152
186
|
class Null
|
|
@@ -190,24 +224,36 @@ module CheekyDreams
|
|
|
190
224
|
class Effect
|
|
191
225
|
include CheekyDreams
|
|
192
226
|
include Math
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
class LightShow < Effect
|
|
230
|
+
def initialize effects
|
|
231
|
+
@effects, @current, @last_freq = effects, nil, nil
|
|
232
|
+
end
|
|
193
233
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
234
|
+
def next current_colour = nil
|
|
235
|
+
@current = @effects.delete_at(0) unless @current
|
|
236
|
+
colour, freq = @current.next current_colour
|
|
237
|
+
if (freq == 0 && !@effects.empty?)
|
|
238
|
+
@current = @effects.delete_at(0)
|
|
239
|
+
elsif (freq == 0 && @effects.empty?)
|
|
240
|
+
@last_freq = 0
|
|
241
|
+
else
|
|
242
|
+
@last_freq = freq
|
|
243
|
+
end
|
|
244
|
+
[colour, @last_freq]
|
|
198
245
|
end
|
|
199
246
|
end
|
|
200
247
|
|
|
201
248
|
class Throb2 < Effect
|
|
202
249
|
def initialize freq, amplitude, centre
|
|
203
|
-
|
|
204
|
-
@amplitude, @centre, @count = amplitude, centre, 1
|
|
250
|
+
@freq, @amplitude, @centre, @count = freq, amplitude, centre, 1
|
|
205
251
|
end
|
|
206
252
|
|
|
207
253
|
def next current_colour
|
|
208
|
-
x = freq * (@count += 1)
|
|
254
|
+
x = @freq * (@count += 1)
|
|
209
255
|
v = sin(x) * @amplitude + @centre
|
|
210
|
-
[v, 0, 0]
|
|
256
|
+
[[v, 0, 0], @freq]
|
|
211
257
|
end
|
|
212
258
|
end
|
|
213
259
|
|
|
@@ -215,7 +261,7 @@ module CheekyDreams
|
|
|
215
261
|
attr_reader :r_amp, :r_centre, :g_amp, :g_centre, :b_amp, :b_centre
|
|
216
262
|
|
|
217
263
|
def initialize freq, from, to
|
|
218
|
-
|
|
264
|
+
@freq = freq
|
|
219
265
|
@r_centre, @r_amp = centre_and_amp from[0], to[0]
|
|
220
266
|
@g_centre, @g_amp = centre_and_amp from[1], to[1]
|
|
221
267
|
@b_centre, @b_amp = centre_and_amp from[2], to[2]
|
|
@@ -233,7 +279,7 @@ module CheekyDreams
|
|
|
233
279
|
# [v, 0, 0]
|
|
234
280
|
|
|
235
281
|
@count += 1
|
|
236
|
-
[r.floor, g.floor, b.floor]
|
|
282
|
+
[[r.floor, g.floor, b.floor], @freq]
|
|
237
283
|
end
|
|
238
284
|
|
|
239
285
|
private
|
|
@@ -242,65 +288,57 @@ module CheekyDreams
|
|
|
242
288
|
centre = max(from, to) - amp
|
|
243
289
|
[centre, amp]
|
|
244
290
|
end
|
|
245
|
-
|
|
246
|
-
def max a, b
|
|
247
|
-
a > b ? a : b
|
|
248
|
-
end
|
|
249
291
|
end
|
|
250
292
|
|
|
251
293
|
class Crazy < Effect
|
|
252
294
|
def initialize freq, new_effect_freq
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
@count, @effect = 0, nil
|
|
295
|
+
@freq, @new_effect_freq = freq, new_effect_freq
|
|
296
|
+
@count, @fade = 0, nil
|
|
256
297
|
end
|
|
257
298
|
|
|
258
299
|
def next current_colour
|
|
259
300
|
if @count % @new_effect_freq == 0
|
|
260
|
-
@
|
|
301
|
+
@fade = FadeTo.new([rand(255), rand(255), rand(255)], @new_effect_freq, @freq)
|
|
261
302
|
end
|
|
262
303
|
@count += 1
|
|
263
|
-
@
|
|
304
|
+
[@fade.next(current_colour)[0], @freq]
|
|
264
305
|
end
|
|
265
306
|
end
|
|
266
307
|
|
|
267
308
|
class Func < Effect
|
|
268
|
-
def initialize
|
|
269
|
-
super freq
|
|
309
|
+
def initialize &block
|
|
270
310
|
@block = block
|
|
271
311
|
end
|
|
272
312
|
|
|
273
313
|
def next current_colour = nil
|
|
274
|
-
|
|
314
|
+
colour, freq = @block.yield(current_colour)
|
|
315
|
+
[rgb(colour), freq]
|
|
275
316
|
end
|
|
276
317
|
end
|
|
277
318
|
|
|
278
319
|
class Solid < Effect
|
|
279
320
|
def initialize colour
|
|
280
|
-
super 0.1
|
|
281
321
|
@rgb = rgb(colour)
|
|
282
322
|
end
|
|
283
323
|
|
|
284
324
|
def next current_colour = nil
|
|
285
|
-
@rgb
|
|
325
|
+
[@rgb, 0]
|
|
286
326
|
end
|
|
287
327
|
end
|
|
288
328
|
|
|
289
329
|
class Cycle < Effect
|
|
290
330
|
def initialize colours, freq
|
|
291
|
-
|
|
292
|
-
@cycle = colours.cycle
|
|
331
|
+
@freq, @cycle = freq, colours.cycle
|
|
293
332
|
end
|
|
294
333
|
|
|
295
334
|
def next current_colour = nil
|
|
296
|
-
rgb(@cycle.next)
|
|
335
|
+
[rgb(@cycle.next), @freq]
|
|
297
336
|
end
|
|
298
337
|
end
|
|
299
338
|
|
|
300
339
|
class Fade < Effect
|
|
301
340
|
def initialize from, to, steps, freq
|
|
302
|
-
|
|
303
|
-
@rgb_from, @rgb_to = rgb(from), rgb(to)
|
|
341
|
+
@freq, @rgb_from, @rgb_to = freq, rgb(from), rgb(to)
|
|
304
342
|
@fade = [@rgb_from]
|
|
305
343
|
(1..(steps-1)).each { |i| @fade << rgb_between(@rgb_from, @rgb_to, i / steps.to_f) }
|
|
306
344
|
@fade << @rgb_to
|
|
@@ -308,23 +346,22 @@ module CheekyDreams
|
|
|
308
346
|
end
|
|
309
347
|
|
|
310
348
|
def next current_colour = nil
|
|
311
|
-
return @rgb_to if @index >= @fade.length
|
|
349
|
+
return [@rgb_to, 0] if @index >= @fade.length
|
|
312
350
|
next_colour = @fade[@index]
|
|
313
351
|
@index += 1
|
|
314
|
-
next_colour
|
|
352
|
+
[next_colour, next_colour == @rgb_to ? 0 : @freq]
|
|
315
353
|
end
|
|
316
354
|
end
|
|
317
355
|
|
|
318
356
|
class FadeTo < Effect
|
|
319
357
|
def initialize to, steps, freq
|
|
320
|
-
|
|
321
|
-
@to, @steps = to, steps
|
|
358
|
+
@freq, @to, @steps = freq, to, steps
|
|
322
359
|
@fade = nil
|
|
323
360
|
end
|
|
324
361
|
|
|
325
362
|
def next current_colour
|
|
326
|
-
@fade = Fade.new(current_colour, @to, @steps, freq) unless @fade
|
|
327
|
-
@fade.next
|
|
363
|
+
@fade = Fade.new(current_colour, @to, @steps, @freq) unless @fade
|
|
364
|
+
@fade.next(current_colour)
|
|
328
365
|
end
|
|
329
366
|
end
|
|
330
367
|
end
|
|
@@ -365,21 +402,25 @@ class Light
|
|
|
365
402
|
|
|
366
403
|
private
|
|
367
404
|
def turn_on
|
|
368
|
-
@on
|
|
405
|
+
@on = true
|
|
369
406
|
@run_thread = Thread.new do
|
|
370
|
-
last_colour = COLOURS[:off]
|
|
407
|
+
last_colour, current_effect, freq = COLOURS[:off], nil, nil
|
|
371
408
|
while @on
|
|
372
409
|
start = Time.now
|
|
373
410
|
@lock.synchronize { current_effect = @effect }
|
|
374
411
|
begin
|
|
375
|
-
new_colour = current_effect.next last_colour
|
|
412
|
+
new_colour, freq = current_effect.next last_colour
|
|
376
413
|
@driver.go new_colour
|
|
377
414
|
@auditor.audit :colour_change, new_colour.to_s
|
|
378
415
|
last_colour = new_colour
|
|
379
416
|
rescue => e
|
|
380
|
-
auditor.audit :error, e.message
|
|
417
|
+
auditor.audit :error, "#{e.message}"
|
|
418
|
+
end
|
|
419
|
+
if freq > 0
|
|
420
|
+
sleep_until (start + (1 / freq.to_f))
|
|
421
|
+
else
|
|
422
|
+
sleep
|
|
381
423
|
end
|
|
382
|
-
sleep_until (start + (1 / current_effect.freq.to_f))
|
|
383
424
|
end
|
|
384
425
|
end
|
|
385
426
|
end
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
|
-
require 'rspec'
|
|
4
3
|
require 'cheeky-dreams'
|
|
5
4
|
|
|
6
|
-
require 'rainbow'
|
|
7
|
-
# http://www.krazydad.com/makecolors.php
|
|
8
5
|
include CheekyDreams
|
|
9
6
|
|
|
10
7
|
light = Light.new ansi_driver
|
|
11
|
-
|
|
12
|
-
light.go
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
light.auditor = forward(:error => suppress_duplicates(stdio_audit))
|
|
9
|
+
light.go crazy
|
|
10
|
+
sleep 10
|
|
11
|
+
light.go(light_show(fade_to(:red), throbbing(:red)))
|
|
15
12
|
sleep 100
|
|
16
13
|
|
data/spec/cheeky-dreams_spec.rb
CHANGED
|
@@ -117,9 +117,9 @@ describe CheekyDreams do
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
it "should return [0,0,0] every time called" do
|
|
120
|
-
@off.next.should == COLOURS[:off]
|
|
121
|
-
@off.next.should == COLOURS[:off]
|
|
122
|
-
@off.next.should == COLOURS[:off]
|
|
120
|
+
@off.next.should == [COLOURS[:off], 0]
|
|
121
|
+
@off.next.should == [COLOURS[:off], 0]
|
|
122
|
+
@off.next.should == [COLOURS[:off], 0]
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
125
|
|
|
@@ -130,9 +130,9 @@ describe CheekyDreams do
|
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
it "should return rgb every time called" do
|
|
133
|
-
@solid.next.should == COLOURS[:purple]
|
|
134
|
-
@solid.next.should == COLOURS[:purple]
|
|
135
|
-
@solid.next.should == COLOURS[:purple]
|
|
133
|
+
@solid.next.should == [COLOURS[:purple], 0]
|
|
134
|
+
@solid.next.should == [COLOURS[:purple], 0]
|
|
135
|
+
@solid.next.should == [COLOURS[:purple], 0]
|
|
136
136
|
end
|
|
137
137
|
end
|
|
138
138
|
|
|
@@ -142,9 +142,9 @@ describe CheekyDreams do
|
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
it "should return rgb every time called" do
|
|
145
|
-
@solid.next.should == [123, 123, 123]
|
|
146
|
-
@solid.next.should == [123, 123, 123]
|
|
147
|
-
@solid.next.should == [123, 123, 123]
|
|
145
|
+
@solid.next.should == [[123, 123, 123], 0]
|
|
146
|
+
@solid.next.should == [[123, 123, 123], 0]
|
|
147
|
+
@solid.next.should == [[123, 123, 123], 0]
|
|
148
148
|
end
|
|
149
149
|
end
|
|
150
150
|
end
|
|
@@ -154,22 +154,18 @@ describe CheekyDreams do
|
|
|
154
154
|
@cycle = cycle [:red, :blue, [211, 192, 101]], 22
|
|
155
155
|
end
|
|
156
156
|
|
|
157
|
-
it "should have a frequency" do
|
|
158
|
-
@cycle.freq.should == 22
|
|
159
|
-
end
|
|
160
|
-
|
|
161
157
|
it "should cycle through the colours as rgb" do
|
|
162
|
-
@cycle.next.should == [255, 0, 0]
|
|
163
|
-
@cycle.next.should == [ 0, 0, 255]
|
|
164
|
-
@cycle.next.should == [211, 192, 101]
|
|
158
|
+
@cycle.next.should == [[255, 0, 0], 22]
|
|
159
|
+
@cycle.next.should == [[ 0, 0, 255], 22]
|
|
160
|
+
@cycle.next.should == [[211, 192, 101], 22]
|
|
165
161
|
|
|
166
|
-
@cycle.next.should == [255, 0, 0]
|
|
167
|
-
@cycle.next.should == [ 0, 0, 255]
|
|
168
|
-
@cycle.next.should == [211, 192, 101]
|
|
162
|
+
@cycle.next.should == [[255, 0, 0], 22]
|
|
163
|
+
@cycle.next.should == [[ 0, 0, 255], 22]
|
|
164
|
+
@cycle.next.should == [[211, 192, 101], 22]
|
|
169
165
|
|
|
170
|
-
@cycle.next.should == [255, 0, 0]
|
|
171
|
-
@cycle.next.should == [ 0, 0, 255]
|
|
172
|
-
@cycle.next.should == [211, 192, 101]
|
|
166
|
+
@cycle.next.should == [[255, 0, 0], 22]
|
|
167
|
+
@cycle.next.should == [[ 0, 0, 255], 22]
|
|
168
|
+
@cycle.next.should == [[211, 192, 101], 22]
|
|
173
169
|
end
|
|
174
170
|
end
|
|
175
171
|
|
|
@@ -179,15 +175,11 @@ describe CheekyDreams do
|
|
|
179
175
|
@fade = fade :blue, :green, 1, 5
|
|
180
176
|
end
|
|
181
177
|
|
|
182
|
-
it "should
|
|
183
|
-
@fade.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
@fade.next.should == [ 0, 0, 255]
|
|
188
|
-
@fade.next.should == [ 0, 255, 0]
|
|
189
|
-
@fade.next.should == [ 0, 255, 0]
|
|
190
|
-
@fade.next.should == [ 0, 255, 0]
|
|
178
|
+
it "should be able to fade to green and then have no frequency" do
|
|
179
|
+
@fade.next.should == [[ 0, 0, 255], 5]
|
|
180
|
+
@fade.next.should == [[ 0, 255, 0], 0]
|
|
181
|
+
@fade.next.should == [[ 0, 255, 0], 0]
|
|
182
|
+
@fade.next.should == [[ 0, 255, 0], 0]
|
|
191
183
|
end
|
|
192
184
|
end
|
|
193
185
|
|
|
@@ -196,25 +188,21 @@ describe CheekyDreams do
|
|
|
196
188
|
@fade = fade [100, 100, 100], [110, 90, 0], 10, 2
|
|
197
189
|
end
|
|
198
190
|
|
|
199
|
-
it "should
|
|
200
|
-
@fade.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
@fade.next.should == [
|
|
205
|
-
@fade.next.should == [
|
|
206
|
-
@fade.next.should == [
|
|
207
|
-
@fade.next.should == [
|
|
208
|
-
@fade.next.should == [
|
|
209
|
-
@fade.next.should == [
|
|
210
|
-
@fade.next.should == [
|
|
211
|
-
@fade.next.should == [107, 93, 30]
|
|
212
|
-
@fade.next.should == [108, 92, 20]
|
|
213
|
-
@fade.next.should == [109, 91, 10]
|
|
214
|
-
@fade.next.should == [110, 90, 0]
|
|
191
|
+
it "should be able to fade to 110,90,0 and then have no frequency" do
|
|
192
|
+
@fade.next.should == [[100, 100, 100], 2]
|
|
193
|
+
@fade.next.should == [[101, 99, 90], 2]
|
|
194
|
+
@fade.next.should == [[102, 98, 80], 2]
|
|
195
|
+
@fade.next.should == [[103, 97, 70], 2]
|
|
196
|
+
@fade.next.should == [[104, 96, 60], 2]
|
|
197
|
+
@fade.next.should == [[105, 95, 50], 2]
|
|
198
|
+
@fade.next.should == [[106, 94, 40], 2]
|
|
199
|
+
@fade.next.should == [[107, 93, 30], 2]
|
|
200
|
+
@fade.next.should == [[108, 92, 20], 2]
|
|
201
|
+
@fade.next.should == [[109, 91, 10], 2]
|
|
202
|
+
@fade.next.should == [[110, 90, 0], 0]
|
|
215
203
|
# and then continue to provide the same colour
|
|
216
|
-
@fade.next.should == [110, 90, 0]
|
|
217
|
-
@fade.next.should == [110, 90, 0]
|
|
204
|
+
@fade.next.should == [[110, 90, 0], 0]
|
|
205
|
+
@fade.next.should == [[110, 90, 0], 0]
|
|
218
206
|
end
|
|
219
207
|
end
|
|
220
208
|
end
|
|
@@ -225,23 +213,20 @@ describe CheekyDreams do
|
|
|
225
213
|
@fade_to = fade_to :green, 11, 2
|
|
226
214
|
end
|
|
227
215
|
|
|
228
|
-
it "should
|
|
229
|
-
@fade_to.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
@fade_to.next([0,
|
|
234
|
-
@fade_to.next([0,
|
|
235
|
-
@fade_to.next([0,
|
|
236
|
-
@fade_to.next([0,
|
|
237
|
-
@fade_to.next([0,
|
|
238
|
-
@fade_to.next([0,
|
|
239
|
-
@fade_to.next([0,
|
|
240
|
-
@fade_to.next([0,
|
|
241
|
-
@fade_to.next([0,
|
|
242
|
-
@fade_to.next([0, 225, 0]).should == [0, 235, 0]
|
|
243
|
-
@fade_to.next([0, 235, 0]).should == [0, 245, 0]
|
|
244
|
-
@fade_to.next([0, 245, 0]).should == [0, 255, 0]
|
|
216
|
+
it "should be able to fade to :green and then have no frequency" do
|
|
217
|
+
@fade_to.next([0, 145, 0]).should == [[0, 145, 0], 2]
|
|
218
|
+
@fade_to.next([0, 155, 0]).should == [[0, 155, 0], 2]
|
|
219
|
+
@fade_to.next([0, 165, 0]).should == [[0, 165, 0], 2]
|
|
220
|
+
@fade_to.next([0, 165, 0]).should == [[0, 175, 0], 2]
|
|
221
|
+
@fade_to.next([0, 175, 0]).should == [[0, 185, 0], 2]
|
|
222
|
+
@fade_to.next([0, 185, 0]).should == [[0, 195, 0], 2]
|
|
223
|
+
@fade_to.next([0, 195, 0]).should == [[0, 205, 0], 2]
|
|
224
|
+
@fade_to.next([0, 205, 0]).should == [[0, 215, 0], 2]
|
|
225
|
+
@fade_to.next([0, 215, 0]).should == [[0, 225, 0], 2]
|
|
226
|
+
@fade_to.next([0, 225, 0]).should == [[0, 235, 0], 2]
|
|
227
|
+
@fade_to.next([0, 235, 0]).should == [[0, 245, 0], 2]
|
|
228
|
+
@fade_to.next([0, 245, 0]).should == [[0, 255, 0], 0]
|
|
229
|
+
@fade_to.next([0, 255, 0]).should == [[0, 255, 0], 0]
|
|
245
230
|
end
|
|
246
231
|
end
|
|
247
232
|
|
|
@@ -250,15 +235,11 @@ describe CheekyDreams do
|
|
|
250
235
|
@fade_to = fade_to [130, 80, 170], 3, 20
|
|
251
236
|
end
|
|
252
237
|
|
|
253
|
-
it "should have a freq of 20" do
|
|
254
|
-
@fade_to.freq.should == 20
|
|
255
|
-
end
|
|
256
|
-
|
|
257
238
|
it "should be able to gradually go to colour when asked" do
|
|
258
|
-
@fade_to.next([190, 77, 140]).should == [190, 77, 140]
|
|
259
|
-
@fade_to.next([190, 77, 140]).should == [170, 78, 150]
|
|
260
|
-
@fade_to.next([170, 78, 150]).should == [150, 79, 160]
|
|
261
|
-
@fade_to.next([150, 79, 160]).should == [130, 80, 170]
|
|
239
|
+
@fade_to.next([190, 77, 140]).should == [[190, 77, 140], 20]
|
|
240
|
+
@fade_to.next([190, 77, 140]).should == [[170, 78, 150], 20]
|
|
241
|
+
@fade_to.next([170, 78, 150]).should == [[150, 79, 160], 20]
|
|
242
|
+
@fade_to.next([150, 79, 160]).should == [[130, 80, 170], 0]
|
|
262
243
|
end
|
|
263
244
|
end
|
|
264
245
|
end
|
|
@@ -266,25 +247,21 @@ describe CheekyDreams do
|
|
|
266
247
|
describe CheekyDreams::Effects::Func do
|
|
267
248
|
describe "when the block return rgb values" do
|
|
268
249
|
before :each do
|
|
269
|
-
@func = func
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
it "should have a freq of 22" do
|
|
273
|
-
@func.freq.should == 22
|
|
250
|
+
@func = func { |current_colour| [[current_colour[0] + 1, current_colour[1] + 1, current_colour[2] + 1], 191] }
|
|
274
251
|
end
|
|
275
252
|
|
|
276
253
|
it "should return the given rgb plus 1 to each of r, g, and b" do
|
|
277
|
-
@func.next([2, 5, 6]).should == [3, 6, 7]
|
|
254
|
+
@func.next([2, 5, 6]).should == [[3, 6, 7], 191]
|
|
278
255
|
end
|
|
279
256
|
end
|
|
280
257
|
|
|
281
|
-
describe "when the block
|
|
258
|
+
describe "when the block returns symbol" do
|
|
282
259
|
before :each do
|
|
283
|
-
@func = func
|
|
260
|
+
@func = func { |current_colour| [:purple, 246] }
|
|
284
261
|
end
|
|
285
262
|
|
|
286
263
|
it "should return the rgb for the symbol" do
|
|
287
|
-
@func.next([2, 5, 6]).should == COLOURS[:purple]
|
|
264
|
+
@func.next([2, 5, 6]).should == [COLOURS[:purple], 246]
|
|
288
265
|
end
|
|
289
266
|
end
|
|
290
267
|
end
|
|
@@ -318,24 +295,63 @@ describe CheekyDreams do
|
|
|
318
295
|
@throb.b_centre.should == 50
|
|
319
296
|
end
|
|
320
297
|
end
|
|
298
|
+
|
|
299
|
+
describe CheekyDreams::Effects::LightShow do
|
|
300
|
+
before :each do
|
|
301
|
+
@effect1 = PreStuffedEffect.new([[1, 1, 1], 11], [[2, 2, 2], 0])
|
|
302
|
+
@effect2 = PreStuffedEffect.new([[3, 3, 3], 0])
|
|
303
|
+
@effect3 = PreStuffedEffect.new([[4, 4, 4], 12], [[5, 5, 5], 0])
|
|
304
|
+
@light_show = light_show @effect1, @effect2, @effect3
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
it 'should go through effects' do
|
|
308
|
+
@light_show.next.should == [[1, 1, 1], 11]
|
|
309
|
+
@light_show.next.should == [[2, 2, 2], 11]
|
|
310
|
+
@light_show.next.should == [[3, 3, 3], 11]
|
|
311
|
+
@light_show.next.should == [[4, 4, 4], 12]
|
|
312
|
+
@light_show.next.should == [[5, 5, 5], 0]
|
|
313
|
+
end
|
|
314
|
+
end
|
|
321
315
|
end
|
|
322
316
|
end
|
|
323
317
|
|
|
324
318
|
module CheekyDreams
|
|
325
|
-
describe
|
|
319
|
+
describe SuppressDuplicatesAuditor do
|
|
326
320
|
before :each do
|
|
327
321
|
@delegate = mock('delegate auditor')
|
|
328
|
-
@auditor =
|
|
322
|
+
@auditor = SuppressDuplicatesAuditor.new @delegate
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
it 'should not send duplicate messages through to delegate' do
|
|
326
|
+
@delegate.should_receive(:audit).with(:type1, 'message1')
|
|
327
|
+
@delegate.should_receive(:audit).with(:type2, 'message2')
|
|
328
|
+
@delegate.should_receive(:audit).with(:type3, 'message3')
|
|
329
|
+
@auditor.audit :type1, 'message1'
|
|
330
|
+
@auditor.audit :type2, 'message2'
|
|
331
|
+
@auditor.audit :type1, 'message1'
|
|
332
|
+
@auditor.audit :type3, 'message3'
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
describe ForwardingAuditor do
|
|
337
|
+
before :each do
|
|
338
|
+
@errors, @blahs = mock('errors auditor'), mock('blahs auditor')
|
|
339
|
+
@auditor = ForwardingAuditor.new :error => @errors, :blah => @blahs
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
it 'should forward audits of type :error' do
|
|
343
|
+
@errors.should_receive(:audit).with(:error, 'errors here')
|
|
344
|
+
@auditor.audit :error, 'errors here'
|
|
329
345
|
end
|
|
330
346
|
|
|
331
|
-
it 'should
|
|
332
|
-
@
|
|
333
|
-
@auditor.audit :
|
|
347
|
+
it 'should forward audits of type :blah' do
|
|
348
|
+
@blahs.should_receive(:audit).with(:blah, 'blahs here')
|
|
349
|
+
@auditor.audit :blah, 'blahs here'
|
|
334
350
|
end
|
|
335
351
|
|
|
336
352
|
it 'should not allow through other random audits' do
|
|
337
|
-
@auditor.audit :error1, '
|
|
338
|
-
@auditor.audit :
|
|
353
|
+
@auditor.audit :error1, 'oh'
|
|
354
|
+
@auditor.audit :blah2, 'no'
|
|
339
355
|
end
|
|
340
356
|
end
|
|
341
357
|
|
|
@@ -478,7 +494,7 @@ describe Light do
|
|
|
478
494
|
@driver = StubDriver.new
|
|
479
495
|
@light = Light.new @driver
|
|
480
496
|
@collecting_auditor = CollectingAuditor.new
|
|
481
|
-
@audit_errors =
|
|
497
|
+
@audit_errors = forward(:error => stdio_audit)
|
|
482
498
|
@light.auditor = audit_to @audit_errors, @collecting_auditor
|
|
483
499
|
end
|
|
484
500
|
|
|
@@ -490,7 +506,7 @@ describe Light do
|
|
|
490
506
|
before :each do
|
|
491
507
|
@error_message = "On purpose error"
|
|
492
508
|
@error = RuntimeError.new @error_message
|
|
493
|
-
@effect = StubEffect.new
|
|
509
|
+
@effect = StubEffect.new { raise @error }
|
|
494
510
|
@light.auditor = @collecting_auditor
|
|
495
511
|
end
|
|
496
512
|
|
|
@@ -503,7 +519,7 @@ describe Light do
|
|
|
503
519
|
describe "frequency of effect" do
|
|
504
520
|
describe 'when frequency is 1' do
|
|
505
521
|
before :each do
|
|
506
|
-
@effect = StubEffect.new 1
|
|
522
|
+
@effect = StubEffect.new { [[0, 0, 0], 1] }
|
|
507
523
|
end
|
|
508
524
|
|
|
509
525
|
it 'should call the effect almost immediately, and then about 1 second later' do
|
|
@@ -517,7 +533,7 @@ describe Light do
|
|
|
517
533
|
|
|
518
534
|
describe 'when frequency is 10' do
|
|
519
535
|
before :each do
|
|
520
|
-
@effect = StubEffect.new 10
|
|
536
|
+
@effect = StubEffect.new { [[0,0,0], 10] }
|
|
521
537
|
end
|
|
522
538
|
|
|
523
539
|
it 'should call the effect between 9 and 11 times in the next second' do
|
|
@@ -531,7 +547,7 @@ describe Light do
|
|
|
531
547
|
|
|
532
548
|
describe 'when frequency is 5' do
|
|
533
549
|
before :each do
|
|
534
|
-
@effect = StubEffect.new 5
|
|
550
|
+
@effect = StubEffect.new { [[0, 0, 0], 5] }
|
|
535
551
|
end
|
|
536
552
|
|
|
537
553
|
it 'should call the effect 5 times in the next second' do
|
|
@@ -622,7 +638,7 @@ describe Light do
|
|
|
622
638
|
|
|
623
639
|
it "should be able to go different colours based on a function" do
|
|
624
640
|
cycle = [:blue, :red, :green, :purple, :grey, :aqua].cycle
|
|
625
|
-
@light.go func
|
|
641
|
+
@light.go func { [cycle.next, 10] }
|
|
626
642
|
@driver.should_become :blue
|
|
627
643
|
@driver.should_become :red
|
|
628
644
|
@driver.should_become :green
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
AuditEvent = Struct.new(:type, :message)
|
|
2
1
|
|
|
3
2
|
class CollectingAuditor
|
|
4
3
|
|
|
@@ -9,10 +8,10 @@ class CollectingAuditor
|
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
def audit type, message
|
|
12
|
-
@events << AuditEvent.new(type, message)
|
|
11
|
+
@events << CheekyDreams::AuditEvent.new(type, message)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
def has_received? type, message
|
|
16
|
-
@events.include? AuditEvent.new(type, message)
|
|
15
|
+
@events.include? CheekyDreams::AuditEvent.new(type, message)
|
|
17
16
|
end
|
|
18
17
|
end
|
data/spec/support/stub_effect.rb
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
+
class PreStuffedEffect < CheekyDreams::Effects::Effect
|
|
2
|
+
def initialize *results
|
|
3
|
+
@results = results
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def next last_colour = nil
|
|
7
|
+
result = @results.delete_at 0
|
|
8
|
+
raise 'no more results in the prestuff effect!' unless result
|
|
9
|
+
result
|
|
10
|
+
end
|
|
11
|
+
end
|
|
1
12
|
|
|
2
13
|
class StubEffect < CheekyDreams::Effects::Effect
|
|
3
14
|
|
|
4
|
-
attr_reader :
|
|
15
|
+
attr_reader :asked_for_colour_count
|
|
5
16
|
|
|
6
|
-
def initialize
|
|
7
|
-
@
|
|
17
|
+
def initialize &block
|
|
18
|
+
@asked_for_colour_count = 0
|
|
8
19
|
if block
|
|
9
20
|
@block = block
|
|
10
21
|
else
|
|
11
|
-
@block = proc { [0,0,0] }
|
|
22
|
+
@block = proc { [[0,0,0], 1] }
|
|
12
23
|
end
|
|
13
24
|
end
|
|
14
25
|
|
|
15
|
-
def next last_colour
|
|
26
|
+
def next last_colour = nil
|
|
16
27
|
@asked_for_colour_count += 1
|
|
17
28
|
@block.yield
|
|
18
29
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cheeky-dreams
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -13,7 +13,7 @@ date: 2011-11-17 00:00:00.000000000Z
|
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &2168537340 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: 2.3.0
|
|
22
22
|
type: :development
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *2168537340
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: bundler
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &2168536860 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ~>
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: 1.0.0
|
|
33
33
|
type: :development
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *2168536860
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: jeweler
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &2168536380 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ~>
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: 1.6.4
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *2168536380
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: rcov
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &2168535900 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ! '>='
|
|
@@ -54,7 +54,7 @@ dependencies:
|
|
|
54
54
|
version: '0'
|
|
55
55
|
type: :development
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *2168535900
|
|
58
58
|
description: For controlling dream cheeky usb light
|
|
59
59
|
email: simojenki@gmail.com
|
|
60
60
|
executables: []
|
|
@@ -73,9 +73,9 @@ files:
|
|
|
73
73
|
- VERSION
|
|
74
74
|
- cheeky-dreams.gemspec
|
|
75
75
|
- lib/cheeky-dreams.rb
|
|
76
|
+
- samples/fade-to-throb.rb
|
|
76
77
|
- spec/cheeky-dreams_spec.rb
|
|
77
78
|
- spec/off.rb
|
|
78
|
-
- spec/small-test.rb
|
|
79
79
|
- spec/spec_helper.rb
|
|
80
80
|
- spec/support/collecting_auditor.rb
|
|
81
81
|
- spec/support/stub_driver.rb
|
|
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
97
97
|
version: '0'
|
|
98
98
|
segments:
|
|
99
99
|
- 0
|
|
100
|
-
hash:
|
|
100
|
+
hash: 3090143854865430648
|
|
101
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
none: false
|
|
103
103
|
requirements:
|