Skip to content

Commit

Permalink
Merge pull request #2 from wesleytabaka/upstream-pr-29
Browse files Browse the repository at this point in the history
Sync upstream PR alexeden#29
  • Loading branch information
wesleytabaka authored Mar 30, 2022
2 parents 2eefec2 + bdb3c5f commit e4448f6
Show file tree
Hide file tree
Showing 6 changed files with 2,332 additions and 99 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 1.12.0

### Changes

* Update dependencies flagged by npm audit
* Add the following values to the `MuxType` enum:
* `InversedZStripe`
* `P10Outdoor1R1G1BMultiplexMapper1`
* `P10Outdoor1R1G1BMultiplexMapper2`
* `P10Outdoor1R1G1BMultiplexMapper3`
* `P10CoremanMapper`
* `P8Outdoor1R1G1BMultiplexMapper`
* `FlippedStripeMultiplexMapper`
* `P10Outdoor32x16HalfScanMapper`

### Pull Requests

* [Upgrade to latest rpi-rgb-led-matrix](https://github.com/alexeden/rpi-led-matrix/pull/29)
108 changes: 78 additions & 30 deletions examples/kitchen-sink.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
import * as color from 'color';
import { LedMatrix, LedMatrixInstance, Font, LayoutUtils, HorizontalAlignment, VerticalAlignment } from '../src';
import {
LedMatrix,
LedMatrixInstance,
Font,
LayoutUtils,
HorizontalAlignment,
VerticalAlignment,
} from '../src';
import { matrixOptions, runtimeOptions } from './_config';

enum Colors {
black = 0x000000,
red = 0xFF0000,
green = 0x00FF00,
blue = 0x0000FF,
magenta = 0xFF00FF,
cyan = 0x00FFFF,
yellow = 0xFFFF00,
red = 0xff0000,
green = 0x00ff00,
blue = 0x0000ff,
magenta = 0xff00ff,
cyan = 0x00ffff,
yellow = 0xffff00,
}

const rainbow64 = Array.from(Array(64))
.map((_, i, { length }) => Math.floor(360 * i / length))
.map((_, i, { length }) => Math.floor((360 * i) / length))
.map(hue => color.hsl(hue, 100, 50).rgbNumber());

const rainbow = (i: number) => rainbow64[Math.min(rainbow64.length - 1, Math.max(i % 64, 0))];
const rainbow = (i: number) =>
rainbow64[Math.min(rainbow64.length - 1, Math.max(i % 64, 0))];

const wait = (t: number) => new Promise(ok => setTimeout(ok, t));

const spin = async (matrix: LedMatrixInstance, speed = 50, clear = true) => {
for (let i = 0; i <= matrix.height(); i++) {
if (clear) matrix.clear();
matrix.fgColor(rainbow(i)).drawLine(0, i, matrix.width(), matrix.height() - i).sync();
matrix
.fgColor(rainbow(i))
.drawLine(0, i, matrix.width(), matrix.height() - i)
.sync();
if (speed) await wait(speed);
}

for (let i = matrix.width(); i >= 0; i--) {
if (clear) matrix.clear();
matrix.fgColor(rainbow(i)).drawLine(i, 0, matrix.width() - i, matrix.height()).sync();
matrix
.fgColor(rainbow(i))
.drawLine(i, 0, matrix.width() - i, matrix.height())
.sync();
if (speed) await wait(speed);
}
};
Expand All @@ -53,39 +67,67 @@ const spin = async (matrix: LedMatrixInstance, speed = 50, clear = true) => {
// Text positions
const font = new Font('helvR12', `${process.cwd()}/fonts/helvR12.bdf`);
matrix.font(font);
const lines = LayoutUtils.textToLines(font, matrix.width(), 'Hello, matrix!');

for (const alignmentH of [HorizontalAlignment.Left, HorizontalAlignment.Center, HorizontalAlignment.Right]) {
for (const alignmentV of [VerticalAlignment.Top, VerticalAlignment.Middle, VerticalAlignment.Bottom]) {
const lines = LayoutUtils.textToLines(
font,
matrix.width(),
'Hello, matrix!'
);

for (const alignmentH of [
HorizontalAlignment.Left,
HorizontalAlignment.Center,
HorizontalAlignment.Right,
]) {
for (const alignmentV of [
VerticalAlignment.Top,
VerticalAlignment.Middle,
VerticalAlignment.Bottom,
]) {
matrix.fgColor(rainbow(Math.floor(64 * Math.random()))).clear();
LayoutUtils.linesToMappedGlyphs(lines, font.height(), matrix.width(), matrix.height(), alignmentH, alignmentV)
.map(glyph => {
matrix.drawText(glyph.char, glyph.x, glyph.y);
});
LayoutUtils.linesToMappedGlyphs(
lines,
font.height(),
matrix.width(),
matrix.height(),
alignmentH,
alignmentV
).map(glyph => {
matrix.drawText(glyph.char, glyph.x, glyph.y);
});
matrix.sync();
await wait(400);
}
}
}


// Clear section
{
matrix.clear().fgColor(Colors.magenta).fill().sync();
await wait(333);
matrix
.clear(0, 0, matrix.width() / 2, matrix.height() / 2)
.clear(matrix.width() / 2, matrix.height() / 2, matrix.width(), matrix.height())
.clear(
matrix.width() / 2,
matrix.height() / 2,
matrix.width(),
matrix.height()
)
.sync();
await wait(500);
}

// Fill section
{
matrix.clear()
matrix
.clear()
.fgColor(Colors.green)
.fill(0, 0, matrix.width() / 2, matrix.height() / 2)
.fill(matrix.width() / 2, matrix.height() / 2, matrix.width(), matrix.height())
.fill(
matrix.width() / 2,
matrix.height() / 2,
matrix.width(),
matrix.height()
)
.sync();
await wait(500);
}
Expand All @@ -96,7 +138,10 @@ const spin = async (matrix: LedMatrixInstance, speed = 50, clear = true) => {
const rgb = [Colors.red, Colors.green, Colors.blue];
matrix.clear().sync();
for (let i = 0; i < 10; i++) {
matrix.fgColor(rgb[i % 3]).drawRect(0, i * rectHeight, matrix.width() - 1, rectHeight).sync();
matrix
.fgColor(rgb[i % 3])
.drawRect(0, i * rectHeight, matrix.width() - 1, rectHeight)
.sync();
await wait(200);
}
}
Expand All @@ -115,7 +160,8 @@ const spin = async (matrix: LedMatrixInstance, speed = 50, clear = true) => {
// Draw line
for (let i = 0; i < matrix.width(); i++) {
const x = i;
matrix.clear()
matrix
.clear()
.fgColor(rainbow(i))
.drawLine(x, 0, x, matrix.height())
.sync();
Expand All @@ -135,7 +181,8 @@ const spin = async (matrix: LedMatrixInstance, speed = 50, clear = true) => {
const centerX = Math.floor(matrix.width() / 2);
const centerY = Math.floor(matrix.height() / 2);
for (let r = 0; r <= matrix.width() * 1.5; r++) {
matrix.clear()
matrix
.clear()
.fgColor(Colors.red)
.drawCircle(0, r, r)
.fgColor(Colors.magenta)
Expand All @@ -151,7 +198,10 @@ const spin = async (matrix: LedMatrixInstance, speed = 50, clear = true) => {
}
matrix.clear();
for (let r = matrix.width() - 15; r >= 0; r--) {
matrix.fgColor(rainbow64[r % 64]).drawCircle(centerX, centerY, r).sync();
matrix
.fgColor(rainbow(r % 64))
.drawCircle(centerX, centerY, r)
.sync();
await wait(44);
}
await wait(1000);
Expand All @@ -169,9 +219,7 @@ const spin = async (matrix: LedMatrixInstance, speed = 50, clear = true) => {
await spin(matrix, 0);
await spin(matrix, 1, false);
await wait(15000);
}
catch (error) {
} catch (error) {
console.error(error);
}

})();
Loading

0 comments on commit e4448f6

Please sign in to comment.