blob: 9ba1e16f2bae13da346a3501ab78761f0fa94c79 (
plain)
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
|
'use strict';
/**
* Draws random sprinkles in the screen each frame. Same color per
* frame.
*
* @function SprinklesScreen
* @implements IScreen
*/
module.exports = function (modulation, width, height, renderer) {
let response = '';
const maxSprinkleCount = (width * height) / 2;
const minSprinkleCount = (width * height) / 8;
const sprinkleCount = Math.round(Math.random() * (maxSprinkleCount - minSprinkleCount)) + minSprinkleCount;
const red = Math.floor(Math.random() * 255);
const blue = Math.floor(Math.random() * 255);
const green = Math.floor(Math.random() * 255);
for (let i = 0; i < sprinkleCount; ++i) {
const x = Math.round(Math.random() * (width - 1)) + 1;
const y = Math.round(Math.random() * (height - 1)) + 1;
const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H)
response += `${position}${renderer(red, blue, green)} `;
}
return response;
};
|