-
Notifications
You must be signed in to change notification settings - Fork 1
/
pixel-map.js
46 lines (41 loc) · 1.08 KB
/
pixel-map.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
/**
* Aureole display pixel map
*
* This file contains the Aureole pixel map for Canvas Cast.
* @see https://github.com/owenmcateer/canvas-cast
*
* @param {Int} Matrix size
* @return {array} Array of pixels with X&Y coordinates
*/
function gFxMap(size) {
const pixelMap = [];
const arms = 24;
const armPixels = 21;
const armAngle = ((Math.PI * 2) / arms);
const angleOffset = Math.PI + (armAngle * 1);
const midPoint = Math.round(size / 2);
let led = 0;
// Arms
for (let i = arms; i > 0; i--) {
const angle = armAngle * i + angleOffset;
// Arm pixels
for (let j = 0; j < armPixels; j++) {
const radius = (j * 10) + 50;
const x = (Math.sin(angle) * radius) + midPoint;
const y = (Math.cos(angle) * radius) + midPoint;
let position = led;
// Flip even rows
if (i % 2 === 0) {
position = (led - armPixels) + ((armPixels - j) * 2) -1;
}
// Add pixel position
pixelMap[position] = {
x: Math.round(x),
y: Math.round(y),
};
led++;
}
}
// Return pixel map.
return pixelMap;
}