]> git.r.bdr.sh - rbdr/tomato-sauce/blob - lib/screens/sprinkles.js
446f46ec9ff556695c4c6f3d77c1cb2f3abe1bbe
[rbdr/tomato-sauce] / lib / screens / sprinkles.js
1 'use strict';
2
3 // Places random sprinkles in the screen each frame. Same color per
4 // frame.
5 const Sprinkles = function (modulation, width, height, renderer) {
6 let response = '';
7
8 let maxSprinkleCount = (width * height) / 2;
9 let minSprinkleCount = (width * height) / 8;
10 let sprinkleCount = Math.round(Math.random() * (maxSprinkleCount - minSprinkleCount)) + minSprinkleCount;
11
12 let red = Math.floor(Math.random() * 255);
13 let blue = Math.floor(Math.random() * 255);
14 let green = Math.floor(Math.random() * 255);
15
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;
19
20 let position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H)
21
22 response += `${position}${renderer(red, blue, green)} `;
23 }
24
25 return response;
26 };
27
28 module.exports = Sprinkles;