-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo-bassin.js
59 lines (50 loc) · 1.25 KB
/
demo-bassin.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
const Serialed = require('./serialed.js')
ctrl = new Serialed.SerialedBassin()
RUN = true
/* VERTICAL
go to next row once previous has been drawn
in this exemple speed reflects FPS !
*/
var Y = 0
function animVertic() {
ctrl.on('next', ()=>{
Y = (Y+1)%(5*16)
X = (X+1)%(32)
ctrl.clear()
for (var x=0; x<32; x++) ctrl.pixelMatrix(x,Y,10,10,10)
for (var x=0; x<32; x++) ctrl.pixelMatrix(x,(Y*2)%80,10,0,0)
for (var x=0; x<32; x++) ctrl.pixelMatrix(x,(79-Math.round(Y/2)),0,0,10)
for (var x=0; x<32; x++) ctrl.pixelMatrix(x,(79-(Y*2)%80),10,0,0)
for (var y=0; y<(5*16); y++) ctrl.pixelMatrix(X,y,10,10,0)
for (var y=0; y<(5*16); y++) ctrl.pixelMatrix(31-(X*2)%32,y,0,0,10)
})
}
/* HORIZONTAL
go to next col every 50ms
in this exemple speed is independant to FPS !
*/
var X = 0
function animHorizon() {
setTimeout(()=>{
X = (X+1)%(32)
ctrl.clear()
for (var y=0; y<(5*16); y++) ctrl.pixelMatrix(X,y,10,10,10)
if (RUN) animHorizon()
}, 50)
}
// FPS
function printFPS() {
setTimeout(()=>{
console.log('FPS', ctrl.fps())
if (RUN) printFPS()
}, 2000)
}
// START DEMO
printFPS()
// animHorizon()
animVertic()
// PROPERLY CLOSE
process.on('SIGINT', function() {
RUN = false
ctrl.close()
});