]> git.r.bdr.sh - rbdr/tomato-sauce/blame - lib/screens/sprinkles.js
Update code and dpendencies
[rbdr/tomato-sauce] / lib / screens / sprinkles.js
CommitLineData
c7b4bd19
BB
1'use strict';
2
fd38d409
RBR
3/**
4 * Draws random sprinkles in the screen each frame. Same color per
5 * frame.
6 *
7 * @function SprinklesScreen
8 * @implements IScreen
9 */
10module.exports = function (modulation, width, height, renderer) {
11
a0666be3 12 let response = '';
c7b4bd19 13
a0666be3
RBR
14 const maxSprinkleCount = (width * height) / 2;
15 const minSprinkleCount = (width * height) / 8;
16 const sprinkleCount = Math.round(Math.random() * (maxSprinkleCount - minSprinkleCount)) + minSprinkleCount;
c7b4bd19 17
a0666be3
RBR
18 const red = Math.floor(Math.random() * 255);
19 const blue = Math.floor(Math.random() * 255);
20 const green = Math.floor(Math.random() * 255);
c7b4bd19 21
a0666be3
RBR
22 for (let i = 0; i < sprinkleCount; ++i) {
23 const x = Math.round(Math.random() * (width - 1)) + 1;
24 const y = Math.round(Math.random() * (height - 1)) + 1;
c7b4bd19 25
a0666be3 26 const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H)
c7b4bd19 27
a0666be3
RBR
28 response += `${position}${renderer(red, blue, green)} `;
29 }
c7b4bd19 30
a0666be3 31 return response;
c7b4bd19 32};