]>
git.r.bdr.sh - rbdr/tomato-sauce/blob - lib/screens/sprinkles.js
446f46ec9ff556695c4c6f3d77c1cb2f3abe1bbe
3 // Places random sprinkles in the screen each frame. Same color per
5 const Sprinkles = function (modulation
, width
, height
, renderer
) {
8 let maxSprinkleCount
= (width
* height
) / 2;
9 let minSprinkleCount
= (width
* height
) / 8;
10 let sprinkleCount
= Math
.round(Math
.random() * (maxSprinkleCount
- minSprinkleCount
)) + minSprinkleCount
;
12 let red
= Math
.floor(Math
.random() * 255);
13 let blue
= Math
.floor(Math
.random() * 255);
14 let green
= Math
.floor(Math
.random() * 255);
16 for (let i
= 0; i
< sprinkleCount
; i
++) {
17 let x
= Math
.round(Math
.random() * (width
- 1)) + 1;
18 let y
= Math
.round(Math
.random() * (height
- 1)) + 1;
20 let position
= `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H)
22 response
+= `${position}${renderer(red, blue, green)} `;
28 module
.exports
= Sprinkles
;