-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsimpleAnimation.js
More file actions
executable file
·125 lines (114 loc) · 2.26 KB
/
simpleAnimation.js
File metadata and controls
executable file
·125 lines (114 loc) · 2.26 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
import { autoDetect, colors } from '../dist/index.js';
const { colorFromHex, colorFromRGB } = colors;
const lp = autoDetect();
let currentFrame = 0;
// this was coded by hand, yeah I know
const frames = [
// frame 0
[
{
buttons: [81, 45, 88, 44],
color: '#FF0000',
},
{
buttons: [72, 36, 77, 33],
color: '#00FF00',
},
{
buttons: [63, 27, 66, 22],
color: '#0000FF',
},
{
buttons: [54, 18, 55, 11],
color: '#d77a0d',
},
],
// frame 1
[
{
buttons: [84, 85, 44, 45, 58, 48],
color: '#FF0000',
},
{
buttons: [74, 75, 34, 35, 57, 47, 53, 43],
color: '#00FF00',
},
{
buttons: [64, 65, 24, 25, 56, 46, 52, 42],
color: '#0000FF',
},
{
buttons: [54, 55, 14, 15, 51, 41],
color: '#d77a0d',
},
],
// frame 2
[
{
buttons: [54, 18, 55, 11],
color: '#FF0000',
},
{
buttons: [63, 27, 66, 22],
color: '#00FF00',
},
{
buttons: [72, 36, 77, 33],
color: '#0000FF',
},
{
buttons: [81, 45, 88, 44],
color: '#d77a0d',
},
],
// frame 3
[
{
buttons: [84, 85, 44, 45, 58, 48],
color: '#d77a0d',
},
{
buttons: [74, 75, 34, 35, 57, 47, 53, 43],
color: '#0000FF',
},
{
buttons: [64, 65, 24, 25, 56, 46, 52, 42],
color: '#00FF00',
},
{
buttons: [54, 55, 14, 15, 51, 41],
color: '#FF0000',
},
],
];
lp.once('ready', (name) => {
console.log(`Connected to ${name}`);
animate();
setInterval(() => animate(), 1000);
});
function animate() {
lp.allOff();
for (const frameSettings of frames[currentFrame]) {
setColor(
frameSettings.buttons,
frameSettings.color,
);
}
currentFrame++;
// reset to start at the first frame
if (currentFrame > frames.length - 1) {
currentFrame = 0;
}
}
/**
*
* @param {number|number[]} buttons
* @param {string|number[]} color
*/
function setColor(buttons, color) {
const buttonsParsed = Array.isArray(buttons) ? buttons : [buttons];
const colorParsed = Array.isArray(color) ? colorFromRGB(color) : colorFromHex(color);
for (const button of buttonsParsed) {
lp.setButtonColor(button, colorParsed);
}
}