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
| 'use strict';
const fs = require('fs'); const Canvas = require('canvas'); const LedMatrix = require("node-rpi-rgb-led-matrix");
const PANEL_WIDTH = 32; const PANEL_HEIGHT = 16;
const imageFilePath = './marimekko.png';
let matrix = new LedMatrix(16); matrix.clear();
fs.readFile(imageFilePath, function(err, data) { if (err) throw err;
let img = new Canvas.Image; img.src = data;
let canvas = new Canvas(PANEL_HEIGHT, PANEL_HEIGHT); let ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0, img.width, img.height);
let imageData = ctx.getImageData(0, 0, PANEL_HEIGHT, PANEL_HEIGHT);
setInterval(function(){ for(let y=0; y<PANEL_HEIGHT; y++) { for(let x=0; x<PANEL_WIDTH; x++) { let index = (y + PANEL_WIDTH + x) * 4; matrix.setPixel(x, y, imageData.data[index], imageData.data[index+1], imageData.data[index+2]); } } }, 500); });
|