-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-pixoo.js
79 lines (70 loc) · 1.82 KB
/
test-pixoo.js
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
import {Pixoo} from './src/divoom/pixoo.js';
import {Canvas} from './src/divoom/canvas.js';
function hslToRgb(h, s, l) {
let r,
g,
b;
if(s === 0) {
r = g = b = l; // achromatic
} else {
const hue2rgb = function hue2rgb(p, q, t) {
if(t < 0) t += 1;
if(t > 1) t -= 1;
if(t < 1 / 6) return p + (q - p) * 6 * t;
if(t < 1 / 2) return q;
if(t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
return p;
};
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
r = hue2rgb(p, q, h + 1 / 3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1 / 3);
}
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
}
const pixooMax = new Pixoo();
const canvas = new Canvas();
const offset = 0;
const colorCount = 1024;
// canvas.transformByRowAndColumn((x, y, _color, index) => {
// if(
// x === 0
// || x === 31
// || y === 0
// || y === 31
// ) {
// return [0, 0, 0];
// }
// return data[index];
// });
// canvas.transformByRowAndColumn((x, y, _color, index) => {
// if(
// x === 0
// || x === 31
// || y === 0
// || y === 31
// ) {
// return [0, 0, 0];
// }
// const offsettedIndex = (index + offset) % colorCount;
// return hslToRgb(offsettedIndex / colorCount, 1, 0.5);
// });
// canvas.width = canvas.height = 16;
canvas.transformByRowAndColumn((x, y, _color, index) => {
if(
x === 0
|| x === 31
|| y === 0
|| y === 31
) {
return [0, 0, 0];
}
// if(x === 5 && y === 5) return [0, 0, 0];
const offsettedIndex = (index + offset) % colorCount;
// // console.log(hslToRgb(offsettedIndex / colorCount, 1, 0.5));
return hslToRgb(offsettedIndex / colorCount, 1, 0.5);
});
// console.log(canvas);
const raw = pixooMax.getStaticImage(canvas);
console.log(raw, raw.length);