diff options
| author | Rubén Beltran del Río <ben@nsovocal.com> | 2018-06-26 22:00:10 +0000 |
|---|---|---|
| committer | Rubén Beltran del Río <ben@nsovocal.com> | 2018-06-26 22:00:10 +0000 |
| commit | c80b2f4575cfc3d74ec8e0b112943cbd081ffcd7 (patch) | |
| tree | 4d2c7a991fcc6510431af72225f7cea2c450f86a /lib/screens | |
| parent | be12c97f83026087e0974fc54508b09c3154c9eb (diff) | |
| parent | fd38d4096e65ba5afba8ed1ddc75ed1814ca8c16 (diff) | |
Merge branch 'feature/rbdr-update-docs' into 'master'
Update Documentation
See merge request rbdr/tomato-sauce!1
Diffstat (limited to 'lib/screens')
| -rw-r--r-- | lib/screens/circle.js | 38 | ||||
| -rw-r--r-- | lib/screens/gradients.js | 22 | ||||
| -rw-r--r-- | lib/screens/mirrors.js | 38 | ||||
| -rw-r--r-- | lib/screens/random.js | 22 | ||||
| -rw-r--r-- | lib/screens/sprinkles.js | 34 |
5 files changed, 87 insertions, 67 deletions
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; diff --git a/lib/screens/gradients.js b/lib/screens/gradients.js index 5e63d5b..2d4a2f0 100644 --- a/lib/screens/gradients.js +++ b/lib/screens/gradients.js @@ -1,14 +1,20 @@ 'use strict'; -// Draws moving gradient boxes. -const Gradients = function (modulation, width, height, renderer) { +/** + * Draws moving gradient boxes + * + * @function GradientsScreen + * @implements IScreen + */ +module.exports = function (modulation, width, height, renderer) { + let response = ''; - for (let i = 0; i < height; i++) { - for (let j = 0; j < width; j++) { - let red = ((modulation + i) * 255 / height) % 255; - let blue = ((modulation + j) * 255 / width) % 255; - let green = ((modulation + i * j) * 255 / (width * height)) % 255; + for (let i = 0; i < height; ++i) { + for (let j = 0; j < width; ++j) { + const red = ((modulation + i) * 255 / height) % 255; + const blue = ((modulation + j) * 255 / width) % 255; + const green = ((modulation + i * j) * 255 / (width * height)) % 255; response = response + renderer(red, blue, green); response = response + ' '; @@ -21,5 +27,3 @@ const Gradients = function (modulation, width, height, renderer) { return response; }; - -module.exports = Gradients; diff --git a/lib/screens/mirrors.js b/lib/screens/mirrors.js index d683fb6..e842217 100644 --- a/lib/screens/mirrors.js +++ b/lib/screens/mirrors.js @@ -1,30 +1,36 @@ 'use strict'; -// Draws small moving gradient boxes and repeats them. -const Mirrors = function (modulation, width, height, renderer) { - let response = []; +/** + * Draws small moving gradient boxes and repeats them. + * + * @function MirrorsScreen + * @implements IScreen + */ +module.exports = function (modulation, width, height, renderer) { - let scale = 2 + Math.round(Math.random() * 4); - let scaledHeight = Math.floor(height / scale); - let scaledWidth = Math.floor(width / scale); + const response = []; - for (let i = 0; i < scaledHeight; i++) { - let row = []; - for (let j = 0; j < scaledWidth; j++) { - let red = ((modulation + i) * 255 / height) % 255; - let blue = ((modulation + j) * 255 / width) % 255; - let green = ((modulation + i * j) * 255 / (width * height)) % 255; + const scale = 2 + Math.round(Math.random() * 4); + const scaledHeight = Math.floor(height / scale); + const scaledWidth = Math.floor(width / scale); - let cell = [renderer(red, blue, green), ' ']; + for (let i = 0; i < scaledHeight; ++i) { + const row = []; + for (let j = 0; j < scaledWidth; ++j) { + const red = ((modulation + i) * 255 / height) % 255; + const blue = ((modulation + j) * 255 / width) % 255; + const green = ((modulation + i * j) * 255 / (width * height)) % 255; + + const cell = [renderer(red, blue, green), ' ']; row.push(cell.join('')); } let rowText = ''; - for (let j = 0; j < scale; j++) { + for (let j = 0; j < scale; ++j) { rowText += row.reverse().join(''); } - for (let j = 1; j < scale; j++) { + for (let j = 1; j < scale; ++j) { response[j * i] = rowText; response[(height - 1 - (j * i))] = rowText; } @@ -32,5 +38,3 @@ const Mirrors = function (modulation, width, height, renderer) { return response.join('\n'); }; - -module.exports = Mirrors; diff --git a/lib/screens/random.js b/lib/screens/random.js index 6ac706f..0cacea7 100644 --- a/lib/screens/random.js +++ b/lib/screens/random.js @@ -1,14 +1,20 @@ 'use strict'; -// random colors -const Random = function (modulation, width, height, renderer) { +/** + * Draws random colors + * + * @function RandomScreen + * @implements IScreen + */ +module.exports = function (modulation, width, height, renderer) { + let response = ''; - for (let i = 0; i < height; i++) { - for (let j = 0; j < width; j++) { - 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 < height; ++i) { + for (let j = 0; j < width; ++j) { + const red = Math.floor(Math.random() * 255); + const blue = Math.floor(Math.random() * 255); + const green = Math.floor(Math.random() * 255); response = response + renderer(red, blue, green); response = response + ' '; @@ -21,5 +27,3 @@ const Random = function (modulation, width, height, renderer) { return response; }; - -module.exports = Random; diff --git a/lib/screens/sprinkles.js b/lib/screens/sprinkles.js index 446f46e..f12200e 100644 --- a/lib/screens/sprinkles.js +++ b/lib/screens/sprinkles.js @@ -1,28 +1,32 @@ 'use strict'; -// Places random sprinkles in the screen each frame. Same color per -// frame. -const Sprinkles = function (modulation, width, height, renderer) { +/** + * Draws random sprinkles in the screen each frame. Same color per + * frame. + * + * @function SprinklesScreen + * @implements IScreen + */ +module.exports = 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; + const maxSprinkleCount = (width * height) / 2; + const minSprinkleCount = (width * height) / 8; + const 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); + const red = Math.floor(Math.random() * 255); + const blue = Math.floor(Math.random() * 255); + const 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; + for (let i = 0; i < sprinkleCount; ++i) { + const x = Math.round(Math.random() * (width - 1)) + 1; + const y = Math.round(Math.random() * (height - 1)) + 1; - 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)} `; } return response; }; - -module.exports = Sprinkles; |