summaryrefslogtreecommitdiff
path: root/lib/screens/sprinkles.js
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2016-05-09 00:31:25 -0500
committerBen Beltran <ben@nsovocal.com>2016-05-09 00:31:25 -0500
commita140f3add912ef4bd659c1c1e82184643be7d845 (patch)
tree131f33520cc40abc387474fa9c2ac4f536e6d7d1 /lib/screens/sprinkles.js
parentae6dbe43bf54581dd7012f95581d4a1b6ee245f0 (diff)
parent09ab7e985d46cad6d3c89e37f983e286e9fda2f6 (diff)
Merge branch 'feature/the-actual-tomato-sauce' into develop
Diffstat (limited to 'lib/screens/sprinkles.js')
-rw-r--r--lib/screens/sprinkles.js28
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;