diff options
| author | Ben Beltran <ben@nsovocal.com> | 2016-05-09 00:31:25 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2016-05-09 00:31:25 -0500 |
| commit | a140f3add912ef4bd659c1c1e82184643be7d845 (patch) | |
| tree | 131f33520cc40abc387474fa9c2ac4f536e6d7d1 /lib/screens/circle.js | |
| parent | ae6dbe43bf54581dd7012f95581d4a1b6ee245f0 (diff) | |
| parent | 09ab7e985d46cad6d3c89e37f983e286e9fda2f6 (diff) | |
Merge branch 'feature/the-actual-tomato-sauce' into develop
Diffstat (limited to 'lib/screens/circle.js')
| -rw-r--r-- | lib/screens/circle.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/screens/circle.js b/lib/screens/circle.js new file mode 100644 index 0000000..d8a4d10 --- /dev/null +++ b/lib/screens/circle.js @@ -0,0 +1,32 @@ +'use strict'; + +// Draws concentric circles. Each ring has its own color. +const Circle = function (modulation, width, height, renderer) { + let response = []; + + let circles = width > height ? height : width; + + for (let i = 0; i < circles; i++) { + let centerX = Math.round(width / 2) + 1; + let centerY = Math.round(height / 2) + 1; + + let red = Math.floor(Math.random() * 255); + let blue = Math.floor(Math.random() * 255); + let green = Math.floor(Math.random() * 255); + + for (let j = 0; j < 180; j++) { + let angle = 2 * j * (Math.PI / 180); + let x = Math.round(centerX + Math.sin(angle) * i); + let y = Math.round(centerY + Math.cos(angle) * i); + + if (x <= width && x > 0 && y <= height && y > 0) { + 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 = Circle; |