]>
Commit | Line | Data |
---|---|---|
c7b4bd19 BB |
1 | 'use strict'; |
2 | ||
fd38d409 RBR |
3 | /** |
4 | * Draws random sprinkles in the screen each frame. Same color per | |
5 | * frame. | |
6 | * | |
7 | * @function SprinklesScreen | |
8 | * @implements IScreen | |
9 | */ | |
10 | module.exports = function (modulation, width, height, renderer) { | |
11 | ||
c7b4bd19 BB |
12 | let response = ''; |
13 | ||
fd38d409 RBR |
14 | const maxSprinkleCount = (width * height) / 2; |
15 | const minSprinkleCount = (width * height) / 8; | |
16 | const sprinkleCount = Math.round(Math.random() * (maxSprinkleCount - minSprinkleCount)) + minSprinkleCount; | |
c7b4bd19 | 17 | |
fd38d409 RBR |
18 | const red = Math.floor(Math.random() * 255); |
19 | const blue = Math.floor(Math.random() * 255); | |
20 | const green = Math.floor(Math.random() * 255); | |
c7b4bd19 | 21 | |
fd38d409 RBR |
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; | |
c7b4bd19 | 25 | |
fd38d409 | 26 | const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H) |
c7b4bd19 BB |
27 | |
28 | response += `${position}${renderer(red, blue, green)} `; | |
29 | } | |
30 | ||
31 | return response; | |
32 | }; |