Skip to content

Commit a3f736f

Browse files
author
Rzah
committed
galaxy and shuffle functions added
Galaxy function sets animated cosmos themed profile, uncomment call on line 37 or 38 to run. Shuffle function randomises arrays (SO copypasta)
1 parent 32cf3dd commit a3f736f

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

POC/ts/index.ts

+77-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ keyboard.setBrightness(63);
3333

3434
// sparkleBatch();
3535

36+
// cosmos themed profile
37+
// galaxy('uk');
38+
// galaxy('us');
39+
3640
/*
3741
* Let's set some color!
3842
*/
@@ -126,6 +130,78 @@ function sparkleBatch() {
126130
}
127131
}
128132

133+
function shuffle(array: any): any {
134+
var currentIndex = array.length, temporaryValue, randomIndex;
135+
while (0 !== currentIndex) {
136+
randomIndex = Math.floor(Math.random() * currentIndex);
137+
currentIndex -= 1;
138+
temporaryValue = array[currentIndex];
139+
array[currentIndex] = array[randomIndex];
140+
array[randomIndex] = temporaryValue;
141+
}
142+
return array;
143+
}
144+
145+
function galaxy(region: string) {
146+
console.log('running galaxy');
147+
allColor("#000000");
148+
var mySelector = [];
149+
for (var i = 0; i < 216; i++) {
150+
mySelector.push(i);
151+
}
152+
153+
if (region == 'uk') {
154+
var ki = Object.keys(KeyInfo["en-GB"]);
155+
} else {
156+
var ki = Object.keys(KeyInfo["en-US"]);
157+
}
158+
159+
ki = shuffle(ki);
160+
var ffs = ki.length;
161+
var color_array = [];
162+
var target_array = [];
163+
var delay_array = [];
164+
let randomKey: any = 0;
165+
const c = ['7D008E', '1A0478', '6B5D9E', '9398D7', '3F70B4'];
166+
const d = ['140751', '160124', '140034', '07001D', '30053F'];
167+
for (var i = 0; i < ffs; i++) {
168+
target_array.push([ki[i]]);
169+
delay_array.push(i*20);
170+
color_array.push(c[Math.floor(Math.random() * c.length)]);
171+
}
172+
173+
for (var index = 0; index < color_array.length; index++) {
174+
var color_arg = color_array[index];
175+
var key_array = target_array[index];
176+
var startDelay = delay_array[index];
177+
var back_color = (d[Math.floor(Math.random() * d.length)]);
178+
179+
for (var i = 0; i < key_array.length; i++) {
180+
if (region == 'uk') {
181+
var key = KeyInfo["en-GB"][key_array[i]];
182+
} else {
183+
var key = KeyInfo["en-US"][key_array[i]];
184+
}
185+
186+
keyboard.setKeyState(new KeyState(key)
187+
.setToColorHex("#"+color_arg)
188+
.setFromColorHex("#"+back_color)
189+
.setUpMaximum("#"+back_color)
190+
.setUpIncrement(50)
191+
.setUpIncrementDelay(10)
192+
.setDownDecrement(50)
193+
.setDownDecrementDelay(5)
194+
.setUpHoldDelay(5)
195+
.setDownHoldDelay(900)
196+
.setStartDelay(startDelay)
197+
.setTransitionReverse()
198+
.setApplyDelayed()
199+
);
200+
}
201+
202+
}
203+
}
204+
129205
function allColor(hexColor: string) {
130206
const keys = Object.keys(KeyInfo["en-US"]);
131207
for (const keyName of keys) {
@@ -140,4 +216,4 @@ function sleep(sleepDuration: number) {
140216
while (new Date().getTime() < now + sleepDuration) {
141217
/* do nothing */
142218
}
143-
}
219+
}

package-lock.json

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)