]> git.r.bdr.sh - rbdr/tomato-sauce/blame - lib/screens/sprinkles.js
Ports the basic script to split modules
[rbdr/tomato-sauce] / lib / screens / sprinkles.js
CommitLineData
c7b4bd19
BB
1'use strict';
2
3// Places random sprinkles in the screen each frame. Same color per
4// frame.
5const 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
28module.exports = Sprinkles;