]> git.r.bdr.sh - rbdr/tomato-sauce/blame_incremental - lib/screens/sprinkles.js
Update code and dpendencies
[rbdr/tomato-sauce] / lib / screens / sprinkles.js
... / ...
CommitLineData
1'use strict';
2
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
12 let response = '';
13
14 const maxSprinkleCount = (width * height) / 2;
15 const minSprinkleCount = (width * height) / 8;
16 const sprinkleCount = Math.round(Math.random() * (maxSprinkleCount - minSprinkleCount)) + minSprinkleCount;
17
18 const red = Math.floor(Math.random() * 255);
19 const blue = Math.floor(Math.random() * 255);
20 const green = Math.floor(Math.random() * 255);
21
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;
25
26 const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H)
27
28 response += `${position}${renderer(red, blue, green)} `;
29 }
30
31 return response;
32};