import { LedMatrixInstance } from "rpi-led-matrix" ; import { CubeFace } from "./CubeFace" ; import { narray } from "../../../src/utils/misc" ; import { facesCount , faceWidth , faceHeight } from "./const" ; import { Point2D } from "../maze/Point2D" ; export class Cube { public readonly faces : CubeFace [ ] ; constructor ( public readonly matrix ) { this . faces = narray ( facesCount ) . map ( ( i ) => new CubeFace ( this , i ) ) ; } animate ( tickFn , msPerFrame = 100 ) { let timeSinceLastFrame = 0 ; this . matrix . afterSync ( ( mat , dt , t ) => { timeSinceLastFrame += dt ; if ( timeSinceLastFrame > msPerFrame ) { tickFn ( timeSinceLastFrame ) ; timeSinceLastFrame = 0 ; } setTimeout ( ( ) => { this . matrix . sync ( ) ; } , 0 ) ; } ) ; this . matrix . sync ( ) ; } ; }