X-Git-Url: https://git.r.bdr.sh/rbdr/tomato-sauce/blobdiff_plain/a140f3add912ef4bd659c1c1e82184643be7d845..36ff43dc094c3058bd26546454bb7a6776c685d3:/lib/screens/circle.js diff --git a/lib/screens/circle.js b/lib/screens/circle.js index d8a4d10..720e250 100644 --- a/lib/screens/circle.js +++ b/lib/screens/circle.js @@ -1,26 +1,32 @@ 'use strict'; -// Draws concentric circles. Each ring has its own color. -const Circle = function (modulation, width, height, renderer) { - let response = []; +/** + * Draws concentric circles. Each ring has its own color. + * + * @function CircleScreen + * @implements IScreen + */ +module.exports = function (modulation, width, height, renderer) { - let circles = width > height ? height : width; + const response = []; - for (let i = 0; i < circles; i++) { - let centerX = Math.round(width / 2) + 1; - let centerY = Math.round(height / 2) + 1; + const circles = width > height ? height : width; - 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 < circles; ++i) { + const centerX = Math.round(width / 2) + 1; + const centerY = Math.round(height / 2) + 1; - 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); + const red = Math.floor(Math.random() * 255); + const blue = Math.floor(Math.random() * 255); + const green = Math.floor(Math.random() * 255); + + for (let j = 0; j < 180; ++j) { + const angle = 2 * j * (Math.PI / 180); + const x = Math.round(centerX + Math.sin(angle) * i); + const 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) + const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H) response += `${position}${renderer(red, blue, green)} `; } } @@ -28,5 +34,3 @@ const Circle = function (modulation, width, height, renderer) { return response; }; - -module.exports = Circle;