]>
git.r.bdr.sh - rbdr/tomato-sauce/blob - lib/screens/sprinkles.js
4 * Draws random sprinkles in the screen each frame. Same color per
7 * @function SprinklesScreen
10 module
.exports = function (modulation
, width
, height
, renderer
) {
14 const maxSprinkleCount
= (width
* height
) / 2;
15 const minSprinkleCount
= (width
* height
) / 8;
16 const sprinkleCount
= Math
.round(Math
.random() * (maxSprinkleCount
- minSprinkleCount
)) + minSprinkleCount
;
18 const red
= Math
.floor(Math
.random() * 255);
19 const blue
= Math
.floor(Math
.random() * 255);
20 const green
= Math
.floor(Math
.random() * 255);
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;
26 const position
= `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H)
28 response
+= `${position}${renderer(red, blue, green)} `;