diff options
| author | Ben Beltran <ben@nsovocal.com> | 2016-05-09 00:30:22 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2016-05-09 00:30:22 -0500 |
| commit | c7b4bd19a006d61c3b4979e884370d123cec7524 (patch) | |
| tree | 6be738bd4641e2fd2ab8a754dc529e773c220d64 /lib/screens/sprinkles.js | |
| parent | ae6dbe43bf54581dd7012f95581d4a1b6ee245f0 (diff) | |
Ports the basic script to split modules
Diffstat (limited to 'lib/screens/sprinkles.js')
| -rw-r--r-- | lib/screens/sprinkles.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/screens/sprinkles.js b/lib/screens/sprinkles.js new file mode 100644 index 0000000..446f46e --- /dev/null +++ b/lib/screens/sprinkles.js @@ -0,0 +1,28 @@ +'use strict'; + +// Places random sprinkles in the screen each frame. Same color per +// frame. +const Sprinkles = function (modulation, width, height, renderer) { + let response = ''; + + let maxSprinkleCount = (width * height) / 2; + let minSprinkleCount = (width * height) / 8; + let sprinkleCount = Math.round(Math.random() * (maxSprinkleCount - minSprinkleCount)) + minSprinkleCount; + + let red = Math.floor(Math.random() * 255); + let blue = Math.floor(Math.random() * 255); + let green = Math.floor(Math.random() * 255); + + for (let i = 0; i < sprinkleCount; i++) { + let x = Math.round(Math.random() * (width - 1)) + 1; + let y = Math.round(Math.random() * (height - 1)) + 1; + + let position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H) + + response += `${position}${renderer(red, blue, green)} `; + } + + return response; +}; + +module.exports = Sprinkles; |