-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunwayControl.py
More file actions
1124 lines (989 loc) · 28 KB
/
RunwayControl.py
File metadata and controls
1124 lines (989 loc) · 28 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import math
import time
import random
#physical
nodeMap = []
nodeStates = []
nodeCount = 0
lightNodesAll = []
flameNodesAll = []
lightNodesLeft = []
lightNodesRight = []
lightNodesPerSide = 0
flameNodesLeft = []
flameNodesRight = []
flameNodesPerSide = 0
#logical
lightsAll = []
lightsLeft = []
lightsRight = []
lightsPerSide = 0
lightColorsAll = []
lightColorsLeft = []
lightColorsRight = []
lightsAndFire = []
lightsAndFireLeft = []
lightsAndFireRight = []
#logging
events = []
#globals
rcTick1 = 0.01666666666667
rcNextTick1 = 0
rcTick2 = 0.01666666666667
rcNextTick2 = 0
rcLightDuration = 0.05
rcFlameDuration = 0.05
rcLightFadeInTime = 0
rcLightFadeOutTime = 0.5
rcBool1 = False
rcBool2 = False
rcIndex1 = 0
rcIndex2 = 0
rcIndex3 = 0
rcIndex4 = 0
rcNextEvent1 = 0
rcColorMapEnabled = False
rcRainbowMode = False
rcAllowFire = False
pixelBuffer = []
#colors
pixelWhite = [255,255,255]
pixelBlue = [0,255,0]
pixelHalfBlue = [0,128,0]
pixelPink = [255,255,0]
pixelYellow = [255,0,255]
pixelRed = [255,0,0]
pixelGreen = [0,0,255]
pixelOff = [0,0,0]
pixelFlame = [255,0,0]
pixelOn = pixelBlue
def log_event(msg):
events.append(msg)
def create(ledStrip):
log_event('creating node array [{0} nodes total]'.format(ledStrip.nLeds))
#first node
nodeMap.append('N')
#intro
nodeMap.extend("123123123")
#side 1
for i in range(0,19):
nodeMap.extend("F123123")
#end of side 1
nodeMap.extend("F123")
#start side 2
nodeMap.extend("123123F")
#rest of side 2
for i in range(0,19):
nodeMap.extend("123123F")
#outro
nodeMap.extend("123123")
#last node
nodeMap.append('N')
sharedCreate(ledStrip)
return events
def createCamTestRig(ledStrip):
log_event('WARNING: This is Cam\'s test rig mode!')
log_event('creating node array [{0} nodes total]'.format(ledStrip.nLeds))
#first node
nodeMap.append('N')
#intro
nodeMap.extend("123123123")
#side 1
for i in range(0,8):
nodeMap.extend("F123123")
#start side 2
nodeMap.extend("123F")
#rest of side 2
for i in range(0,7):
nodeMap.extend("123123F")
#outro
nodeMap.extend("123123")
#last node
nodeMap.append('N')
sharedCreate(ledStrip)
return events
def sharedCreate(ledStrip):
#print "nodeMap: ({0})".format(len(nodeMap))
#print nodeMap
#light addresses
for i in range(0,len(nodeMap)):
if nodeMap[i] in ['1', '2', '3']:
lightNodesAll.append(i)
#flame addresses
for i in range(0,len(nodeMap)):
if nodeMap[i] == 'F':
flameNodesAll.append(i)
#log_event("Map contains {0} light nodes...".format(len(lightNodesAll)))
#print '\nlightNodesAll:'
#print lightNodesAll
#log_event("Map contains {0} flame nodes...".format(len(flameNodesAll)))
#print '\nflameNodesAll:'
#print flameNodesAll
#logical lights
for i in range(0, len(lightNodesAll), 3):
lightsAll.append([lightNodesAll[i],lightNodesAll[i+1],lightNodesAll[i+2]])
#print '\nlightsAll ({0}):'.format(len(lightsAll))
#for i in range(0, len(lightsAll)):
#print 'Light {0}: '.format(i + 1) + str(lightsAll[i])
#print lightsAll[i]
#left and right side lights
global lightNodesPerSide, lightsPerSide
lightNodesPerSide = len(lightNodesAll)/2
lightsPerSide = lightNodesPerSide/3
#print '\nlightNodesPerSide = {0} nodes'.format(lightNodesPerSide)
#print '\nlightsPerSide = {0} lights'.format(lightsPerSide)
for i in range(0,lightNodesPerSide):
lightNodesLeft.append(lightNodesAll[i])
for i in range(0, lightNodesPerSide):
lightNodesRight.append(lightNodesAll[i+lightNodesPerSide])
lightNodesRight.reverse()
#log_event("Left side has {0} light nodes...".format(len(lightNodesLeft)))
#print '\nlightNodesLeft:'
#print lightNodesLeft
#log_event("Right side has {0} light nodes...".format(len(lightNodesRight)))
#print '\nlightNodesRight:'
#print lightNodesRight
#left and right side flames
global flameNodesPerSide, flamesPerSide
flameNodesPerSide = len(flameNodesAll)/2
#print '\nflameNodesPerSide = {0} nodes'.format(flameNodesPerSide)
for i in range(0,flameNodesPerSide):
flameNodesLeft.append(flameNodesAll[i])
for i in range(0, flameNodesPerSide):
flameNodesRight.append(flameNodesAll[i+flameNodesPerSide])
flameNodesRight.reverse()
#log_event("Left side has {0} flame nodes...".format(len(flameNodesLeft)))
#print '\nflameNodesLeft:'
#print flameNodesLeft
#log_event("Right side has {0} flame nodes...".format(len(flameNodesRight)))
#print '\nflameNodesRight:'
#print flameNodesRight
constructLightsAndFireArrays()
#init nodeStates
for i in range(0, len(nodeMap)):
nodeStates.append(0)
setColorMap("eq")
#init pixel buffer
for i in range(0, len(nodeMap)):
pixelBuffer.append(pixelOff)
def constructLightsAndFireArrays():
global lightsAndFire, lightsAndFireLeft, lightsAndFireRight
lightIndex = 0
fireIndex = 0
for c in nodeMap:
if c == '1':
lightsAndFire.append(['L', lightIndex])
lightIndex += 1
elif c == 'F':
lightsAndFire.append(['F', fireIndex])
fireIndex += 1
else:
pass
#print '\nlightsAndFire ({0}):'.format(len(lightsAndFire))
#print lightsAndFire
for i in range(0, len(lightsAndFire)):
if i < len(lightsAndFire) / 2:
lightsAndFireLeft.append(lightsAndFire[i])
else:
lightsAndFireRight.append(lightsAndFire[i])
lightsAndFireRight.reverse()
#print '\nlightsAndFireLeft ({0}):'.format(len(lightsAndFireLeft))
#print lightsAndFireLeft
#print '\nlightsAndFireRight ({0}):'.format(len(lightsAndFireRight))
#print lightsAndFireRight
def setColorMap(s):
#print 'RunwayControl - setting color map to: ' + s
global lightColorsAll, lightColorsLeft, lightColorsRight
lightColorsAll = []
lightColorsLeft = []
lightColorsRight = []
b = False
for i in range(0, len(lightsAll) / 2):
if s == "eq":
segmentLength = (len(lightsAll) / 2) / 3
if i < segmentLength:
##print '{0} - segment 1'.format(i)
lightColorsLeft.append(pixelGreen)
lightColorsRight.append(pixelGreen)
elif i <= (segmentLength * 2):
##print '{0} - segment 2'.format(i)
lightColorsLeft.append(pixelBlue)
lightColorsRight.append(pixelBlue)
else:
##print '{0} - segment 3'.format(i)
lightColorsLeft.append(pixelRed)
lightColorsRight.append(pixelRed)
elif s == 'checker':
if b == True:
lightColorsLeft.append(pixelGreen)
lightColorsRight.append(pixelGreen)
b = False
else:
lightColorsLeft.append(pixelBlue)
lightColorsRight.append(pixelBlue)
b = True
else:
segmentLength = (len(lightsAll) / 2) / 3
if i < segmentLength:
##print '{0} - segment 1'.format(i)
lightColorsLeft.append(pixelGreen)
lightColorsRight.append(pixelGreen)
elif i <= (segmentLength * 2):
##print '{0} - segment 2'.format(i)
lightColorsLeft.append(pixelRed)
lightColorsRight.append(pixelRed)
else:
##print '{0} - segment 3'.format(i)
lightColorsLeft.append(pixelBlue)
lightColorsRight.append(pixelBlue)
lightColorsRight.reverse()
lightColorsAll = lightColorsLeft + lightColorsRight
#print 'lightColorsAll {0}:'.format(len(lightColorsAll))
#for i in range(0, len(lightColorsAll)):
#print '{0} - [{1},{2},{3}]'.format(i, lightColorsAll[i][0], lightColorsAll[i][1], lightColorsAll[i][2])
def showNode(n):
if checkTick1():
nodeStates[n] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
def showLights():
if checkTick1():
for i in range(0,len(lightNodesAll)):
nodeStates[lightNodesAll[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
def showFlames():
if checkTick1():
for i in range(0,len(flameNodesAll)):
nodeStates[flameNodesAll[i]] = rcFlameDuration
def showLeftSideAll():
global lightNodesLeft, lightNodesRight, lightNodesPerSide
global flameNodesLeft, flameNodesRight, flameNodesPerSide
if checkTick1():
for i in range(0,lightNodesPerSide):
nodeStates[lightNodesAll[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
for i in range(0,flameNodesPerSide):
nodeStates[flameNodesAll[i]] = rcFlameDuration
def showRightSideAll():
global lightNodesLeft, lightNodesRight, lightNodesPerSide
global flameNodesLeft, flameNodesRight, flameNodesPerSide
if checkTick1():
for i in range(lightNodesPerSide, len(lightNodesAll)):
nodeStates[lightNodesAll[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
for i in range(flameNodesPerSide , len(flameNodesAll)):
nodeStates[flameNodesAll[i]] = rcFlameDuration
def chaseNodeSimple():
global rcIndex1
if checkTick1():
for i in range(0,len(lightNodesAll)):
if i == rcIndex1:
nodeStates[lightNodesAll[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
rcIndex1 += 1
if rcIndex1 > len(lightNodesAll):
rcIndex1 = 0
def chaseNodeDual():
global rcIndex1, lightNodesLeft, lightNodesRight, lightNodesPerSide
if checkTick1():
if rcIndex1 > lightNodesPerSide:
rcIndex1 = 0
for i in range(0,lightNodesPerSide):
if i == rcIndex1:
nodeStates[lightNodesLeft[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
nodeStates[lightNodesRight[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
rcIndex1 += 1
def chaseNodeDualReverse():
global rcIndex1, lightNodesLeft, lightNodesRight, lightNodesPerSide
if checkTick1():
if rcIndex1 < 0:
rcIndex1 = lightNodesPerSide
for i in range(0, lightNodesPerSide):
if i == rcIndex1:
nodeStates[lightNodesLeft[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
nodeStates[lightNodesRight[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
rcIndex1 -= 1
def chaseMultiNodeDual(n):
global rcIndex1, lightNodesLeft, lightNodesRight, lightNodesPerSide
if checkTick1():
if rcIndex1 > n - 1:
rcIndex1 = 0
for i in range(0, lightNodesPerSide - rcIndex1):
if i % n == 0:
nodeStates[lightNodesLeft[i + rcIndex1]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
nodeStates[lightNodesRight[i + rcIndex1]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
rcIndex1 += 1
def chaseLightSimple():
#light simple chaser
global rcIndex1
if checkTick1():
if rcIndex1 > len(lightsAll):
rcIndex1 = 0
for i in range(0,len(lightsAll)):
if i == rcIndex1:
activateLight(i)
else:
pass
rcIndex1 += 1
def chaseLightCircuit():
#light circle chaser
global rcIndex1
if checkTick1():
if rcIndex1 > len(lightsAll)/2:
rcIndex1 = 0
for i in range(0,len(lightsAll)/2):
if i == rcIndex1:
activateLight(i)
activateLight(i + len(lightsAll)/2)
else:
pass
rcIndex1 += 1
def chaseLightDual():
#light dual chaser
global rcIndex1
if checkTick1():
if rcIndex1 > len(lightsAll)/2:
rcIndex1 = 0
for i in range(0,len(lightsAll)/2):
if i == rcIndex1:
leftI = i
rightI = (len(lightsAll) - 1) - i
activateLight(leftI)
activateLight(rightI)
else:
pass
rcIndex1 += 1
def chaseLightDualBounce():
#light dual chaser with bounce
global rcIndex1, rcBool1
if checkTick1():
if rcBool1 == True:
if rcIndex1 >= len(lightsAll)/2:
rcBool1 = False
for i in range(0,len(lightsAll)/2):
if i == rcIndex1:
leftI = i
rightI = (len(lightsAll) - 1) - i
activateLight(leftI)
activateLight(rightI)
else:
pass
if rcBool1 == True:
rcIndex1 += 1
else:
if rcIndex1 <= 0:
rcBool1 = True
for i in range(0,len(lightsAll)/2):
if i == rcIndex1:
leftI = i
rightI = (len(lightsAll) - 1) - i
activateLight(leftI)
activateLight(rightI)
else:
pass
if rcBool1 == False:
rcIndex1 -= 1
def chaseMultiLightDual(n):
#light dual chaser, every n lights
global rcIndex1
if checkTick1():
if rcIndex1 > n - 1:
rcIndex1 = 0
for i in range(0,(len(lightsAll)/2) - rcIndex1):
if i % n == 0:
leftI = i + rcIndex1
rightI = ((len(lightsAll) - 1) - i) - rcIndex1
activateLight(leftI)
activateLight(rightI)
else:
pass
rcIndex1 += 1
def chaseMultiLight(n):
#light chaser, every n lights
global rcIndex1
if checkTick1():
if rcIndex1 > n - 1:
rcIndex1 = 0
for i in range(0,(len(lightsAll)) - rcIndex1):
if i % n == 0:
activateLight(i + rcIndex1)
else:
pass
rcIndex1 += 1
def twinkleAllLights():
if checkTick1():
for i in range(0,len(lightsAll)):
if coinToss(1) == True:
activateLight(i)
else:
pass
def showLogicalLight(n):
if checkTick1():
for i in range(0,len(lightsAll)):
if i == n:
activateLight(i)
else:
pass
def sillyRabbits1():
global rcIndex1, rcIndex2, rcIndex3, rcIndex4, rcNextEvent1
if checkTick1():
if time.time() > rcNextEvent1:
rcIndex3 = random.randint(0, len(lightsAll) - 1)
rcIndex4 = rcIndex3 + random.randint(-3, 3)
rcIndex4 = max(min(rcIndex4, len(lightsAll)) - 1, 0)
#print 'rcIndex3 = {0}, rcIndex4 = {1}'.format(rcIndex3, rcIndex4)
rcNextEvent1 = time.time() + random.uniform(2.5,6.0)
if rcIndex1 < rcIndex3:
rcIndex1 += 1
elif rcIndex1 > rcIndex3:
rcIndex1 -= 1
if rcIndex2 < rcIndex4:
rcIndex2 += 1
elif rcIndex2 > rcIndex4:
rcIndex2 -= 1
if abs(rcIndex1 - rcIndex2) < 5:
#print "woah!"
rcIndex3 = random.randint(0, len(lightsAll))
activateLight(rcIndex1)
activateLight(rcIndex2)
def fillUpLightsSimple():
global rcIndex1
if checkTick1():
if rcIndex1 > len(lightsAll):
rcIndex1 = 0
for i in range(0,len(lightsAll)):
if i < rcIndex1:
activateLight(i)
else:
pass
rcIndex1 += 1
def fillUpLightsDual():
global rcIndex1
if checkTick1():
if rcIndex1 > len(lightsAll)/2:
rcIndex1 = 0
for i in range(0,len(lightsAll)/2):
if i < rcIndex1:
leftI = i
rightI = (len(lightsAll) - 1) - i
activateLight(leftI)
activateLight(rightI)
else:
pass
rcIndex1 += 1
def fillUpLightsDualEq(e):
if checkTick1():
e = max(min(e, len(lightsAll)/2), 0)
for i in range(0,len(lightsAll)/2):
if i <= e:
leftI = i
rightI = (len(lightsAll) - 1) - i
activateLight(leftI)
activateLight(rightI)
else:
pass
def fillUpLightsDualEqFake():
if checkTick1():
e = random.randint(0,len(lightsAll)/2)
for i in range(0,len(lightsAll)/2):
if i <= e:
leftI = i
rightI = (len(lightsAll) - 1) - i
activateLight(leftI)
activateLight(rightI)
else:
pass
def lightAndFireChaserSimple():
global rcIndex1
if checkTick1():
if rcIndex1 > len(lightsAndFire):
rcIndex1 = 0
for i in range(0,len(lightsAndFire)):
if i == rcIndex1:
if lightsAndFire[i][0] == 'F':
activateFlame(lightsAndFire[i][1] + 1)
elif lightsAndFire[i][0] == 'L':
activateLight(lightsAndFire[i][1])
rcIndex1 += 1
def lightAndFireChaserLeft():
global rcIndex1
chaseLength = len(lightsAndFireLeft) - 1
if checkTick1():
if rcIndex1 > chaseLength:
rcIndex1 = 0
for i in range(0,chaseLength):
if i == rcIndex1:
if lightsAndFireLeft[i][0] == 'L':
activateLight(lightsAndFireLeft[i][1])
#if next index is fire, light it now and skip next node
if lightsAndFireLeft[i + 1][0] == 'F':
activateFlame(lightsAndFireLeft[i + 1][1] + 1)
rcIndex1 += 1
rcIndex1 += 1
def lightAndFireChaserRight():
global rcIndex2
chaseLength = len(lightsAndFireRight) - 1
if checkTick2():
if rcIndex2 > chaseLength:
rcIndex2 = 0
for i in range(0,chaseLength):
if i == rcIndex2:
if lightsAndFireRight[i][0] == 'L':
activateLight(lightsAndFireRight[i][1])
#if this index is fire, light it and next light now
#then skip ahead by 1
if lightsAndFireRight[i][0] == 'F':
activateFlame(lightsAndFireRight[i][1] + 1)
activateLight(lightsAndFireRight[i + 1][1])
rcIndex2 += 1
rcIndex2 += 1
def lightAndFireChaserLeftReverse():
global rcIndex1
chaseLength = len(lightsAndFireLeft) - 1
if checkTick1():
if rcIndex1 < 0:
rcIndex1 = chaseLength
for i in range(0,chaseLength):
if i == rcIndex1:
if lightsAndFireLeft[i][0] == 'L':
activateLight(lightsAndFireLeft[i][1])
#if this index is fire, light it and next light now
#then skip ahead by 1
if lightsAndFireLeft[i][0] == 'F':
activateFlame(lightsAndFireLeft[i][1] + 1)
activateLight(lightsAndFireLeft[i - 1][1])
rcIndex1 -= 1
rcIndex1 -= 1
def lightAndFireChaserRightReverse():
global rcIndex2
chaseLength = len(lightsAndFireRight) - 1
if checkTick2():
if rcIndex2 < 0:
rcIndex2 = chaseLength
for i in range(0,chaseLength):
if i == rcIndex2:
if lightsAndFireRight[i][0] == 'L':
activateLight(lightsAndFireRight[i][1])
#if next index is fire, light it now and skip next node
if lightsAndFireRight[i - 1][0] == 'F':
activateFlame(lightsAndFireRight[i - 1][1] + 1)
rcIndex2 -= 1
rcIndex2 -= 1
def lightAndFireChaserLeftBounce():
global rcIndex1, rcBool1
chaseLength = len(lightsAndFireLeft) - 1
if checkTick1():
if rcBool1 == True:
if rcIndex1 > chaseLength:
rcBool1 = False
for i in range(0,chaseLength):
if i == rcIndex1:
if lightsAndFireLeft[i][0] == 'L':
activateLight(lightsAndFireLeft[i][1])
#if next index is fire, light it now and skip next node
if lightsAndFireLeft[i + 1][0] == 'F':
activateFlame(lightsAndFireLeft[i + 1][1] + 1)
rcIndex1 += 1
if rcBool1 == True:
rcIndex1 += 1
else:
if rcIndex1 < 0:
rcBool1 = True
for i in range(0,chaseLength):
if i == rcIndex1:
if lightsAndFireLeft[i][0] == 'L':
activateLight(lightsAndFireLeft[i][1])
#if this index is fire, light it and next light now
#then skip ahead by 1
if lightsAndFireLeft[i][0] == 'F':
activateFlame(lightsAndFireLeft[i][1] + 1)
activateLight(lightsAndFireLeft[i - 1][1])
rcIndex1 -= 1
if rcBool1 == False:
rcIndex1 -= 1
def lightAndFireChaserRightBounce():
global rcIndex2, rcBool2
chaseLength = len(lightsAndFireRight) - 1
if checkTick2():
if rcBool2 == True:
if rcIndex2 > chaseLength:
rcBool2 = False
for i in range(0,chaseLength):
if i == rcIndex2:
if lightsAndFireRight[i][0] == 'L':
activateLight(lightsAndFireRight[i][1])
#if this index is fire, light it and next light now
#then skip ahead by 1
if lightsAndFireRight[i][0] == 'F':
activateFlame(lightsAndFireRight[i][1] + 1)
activateLight(lightsAndFireRight[i + 1][1])
rcIndex2 += 1
if rcBool2 == True:
rcIndex2 += 1
else:
if rcIndex2 < 0:
rcBool2 = True
for i in range(0,chaseLength):
if i == rcIndex2:
if lightsAndFireRight[i][0] == 'L':
activateLight(lightsAndFireRight[i][1])
#if next index is fire, light it now and skip next node
if lightsAndFireRight[i - 1][0] == 'F':
activateFlame(lightsAndFireRight[i - 1][1] + 1)
rcIndex2 -= 1
if rcBool2 == False:
rcIndex2 -= 1
def twinkleAllFlames():
if checkTick2():
for i in range(0,len(flameNodesAll)):
if coinToss(1) == True:
activateFlame(i)
else:
pass
def twinkleAllLightsRandomFade():
global rcLightFadeOutTime
if checkTick1():
for i in range(0,len(lightsAll)):
if coinToss(3) == True:
rcLightFadeOutTime = random.uniform(0.2, 2.0)
activateLight(i)
else:
pass
def twinkleOneFlame():
if checkTick2():
luckyWinner = random.randint(0,len(flameNodesAll))
for i in range(0,len(flameNodesAll)):
if i == luckyWinner:
activateFlame(i)
else:
pass
def twinkleOneLight():
if checkTick1():
luckyWinner = random.randint(0,len(lightsAll))
for i in range(0,len(lightsAll)):
if i == luckyWinner:
activateLight(i)
else:
pass
def twinkleAllLightNodes():
if checkTick1():
for i in range(0,len(lightNodesAll)):
if coinToss(5) == True:
nodeStates[lightNodesAll[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
else:
pass
def lightningSync():
if checkTick1():
if coinToss(3) == True:
for i in range(0,len(lightNodesAll)):
nodeStates[lightNodesAll[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
else:
pass
def lightningSides():
if checkTick1():
if coinToss(3) == True:
for i in range(0,len(lightNodesLeft)):
nodeStates[lightNodesLeft[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
else:
pass
if coinToss(3) == True:
for i in range(0,len(lightNodesRight)):
nodeStates[lightNodesRight[i]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
else:
pass
def chaseFlames():
global rcIndex1
if checkTick1():
if rcIndex1 > len(flameNodesAll):
rcIndex1 = 0
for i in range(0,len(flameNodesAll)):
if i == rcIndex1:
nodeStates[flameNodesAll[i]] = rcFlameDuration
rcIndex1 += 1
def chaseFlamesDual():
global rcIndex2
if checkTick2():
if rcIndex2 > len(flameNodesAll)/2:
rcIndex2 = 0
for i in range(0,len(flameNodesAll)/2):
if i == rcIndex2:
leftI = i
rightI = (len(flameNodesAll) - 1) - i
activateFlame(leftI + 1)
activateFlame(rightI + 1)
else:
pass
rcIndex2 += 1
def chaseMultiFlamesDual(n):
#flames dual chaser, every n flames
global rcIndex2
if checkTick2():
if n > len(flameNodesAll)/2:
n = len(flameNodesAll)/2
if rcIndex2 > n - 1:
rcIndex2 = 0
for i in range(0,(len(flameNodesAll)/2) - rcIndex2):
if i % n == 0:
leftI = i + rcIndex2
rightI = ((len(flameNodesAll) - 1) - i) - rcIndex2
activateFlame(leftI + 1)
activateFlame(rightI + 1)
else:
pass
rcIndex2 += 1
def chaseMultiFlamesDualReverse(n):
#reverse flames dual chaser, every n flames
global rcIndex2
if checkTick2():
if n > len(flameNodesAll)/2:
n = len(flameNodesAll)/2
if rcIndex2 < 0:
rcIndex2 = n - 1
for i in range(0,(len(flameNodesAll)/2) - rcIndex2):
if i % n == 0:
leftI = i + rcIndex2
rightI = ((len(flameNodesAll) - 1) - i) - rcIndex2
activateFlame(leftI + 1)
activateFlame(rightI + 1)
else:
pass
rcIndex2 -= 1
def chaseFlamesDualReverse():
global rcIndex2
if checkTick2():
if rcIndex2 < 0:
rcIndex2 = len(flameNodesAll)/2
for i in range(0,len(flameNodesAll)/2):
if i == rcIndex2:
leftI = i
rightI = (len(flameNodesAll) - 1) - i
activateFlame(leftI + 1)
activateFlame(rightI + 1)
else:
pass
rcIndex2 -= 1
def chaseFlamesDualBounce():
global rcIndex2, rcBool2
if checkTick2():
if rcBool2 == True:
if rcIndex2 > (len(flameNodesAll)/2) -1:
rcBool2 = False
for i in range(0,len(flameNodesAll)/2):
if i == rcIndex2:
leftI = i
rightI = (len(flameNodesAll) - 1) - i
activateFlame(leftI + 1)
activateFlame(rightI + 1)
else:
pass
if rcBool2 == True:
rcIndex2 += 1
else:
if rcIndex2 < 0:
rcBool2 = True
for i in range(0,len(flameNodesAll)/2):
if i == rcIndex2:
leftI = i
rightI = (len(flameNodesAll) - 1) - i
activateFlame(leftI + 1)
activateFlame(rightI + 1)
else:
pass
if rcBool2 == False:
rcIndex2 -= 1
def clear():
for i in range(0,len(nodeMap)):
nodeStates[i] = 0
def clearImmediate(ledStrip):
print 'RunwayControl - clearImmediate()'
clear()
update(ledStrip)
def decrementDurations(t):
for i in range(0,len(nodeMap)):
nodeStates[i] -= t
def updateFingerLights(a):
for i in range(0, len(a)):
activateLight(a[i] - 1)
def updateFingerFlames(a):
for i in range(0, len(a)):
activateFlame(a[i])
def checkTick1():
global rcTick1, rcNextTick1
if time.time() > rcNextTick1:
rcNextTick1 = time.time() + rcTick1
return True
else:
return False
def checkTick2():
global rcTick2, rcNextTick2
if time.time() > rcNextTick2:
rcNextTick2 = time.time() + rcTick2
return True
else:
return False
def activateLight(i):
#print 'RunwayControl - activateLight {0}'.format(i)
try:
nodeStates[lightsAll[i][0]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
except:
pass
#print "activateLight - ERROR: Light {0}, node 0 doesn't exist".format(i)
try:
nodeStates[lightsAll[i][1]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
except:
pass
#print "activateLight - ERROR: Light {0}, node 1 doesn't exist".format(i)
try:
nodeStates[lightsAll[i][2]] = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
except:
pass
#print "activateLight - ERROR: Light {0}, node 2 doesn't exist".format(i)
def activateFlame(i):
#print 'RunwayControl - activateFlame {0}'.format(i)
requestedFlameNumber = i
requestedFlameNode = getNodeFromFlameNumber(requestedFlameNumber)
nodeStates[flameNodesAll[requestedFlameNode]] = rcFlameDuration
def update(ledStrip):
global rcLightFadeOutTime, rcLightFadeInTime, pixelOn, pixelFlame, lightColorsAll, rcColorMapEnabled, rcRainbowMode
effectiveLightDuration = rcLightDuration + rcLightFadeOutTime + rcLightFadeInTime
for i in xrange(0,len(nodeMap)):
#color mapping
if rcColorMapEnabled == True:
j = float(i)/len(nodeMap)
k = int(j * len(lightColorsAll)-1)
pixelOn = lightColorsAll[k]
if nodeStates[i] > effectiveLightDuration - rcLightFadeInTime and rcLightFadeInTime > 0:
if nodeMap[i] == 'F':
ledStrip.setPixel(i, pixelFlame)
else:
fadeAmount = 0
nodeTime = effectiveLightDuration - nodeStates[i]
if nodeTime > 0:
fadeAmount = nodeTime/rcLightFadeInTime
r, g, b = pixelOn
p = int(fadeAmount * 255)
if r > 0:
r = p
if g > 0:
g = p
if b > 0:
b = p
ledStrip.setPixel(i, [r,g,b])
elif nodeStates[i] > rcLightFadeOutTime:
if nodeMap[i] == 'F':
ledStrip.setPixel(i, pixelFlame)
else:
if rcRainbowMode == True:
pixelOn = getRandomColor()
ledStrip.setPixel(i, pixelOn)
elif nodeStates[i] > 0 and nodeStates[i] <= rcLightFadeOutTime:
if nodeMap[i] == 'F':
ledStrip.setPixel(i, pixelFlame)
else:
r = pixelOn[0]