diff options
Diffstat (limited to 'lib/screens')
| -rw-r--r-- | lib/screens/circle.js | 36 | ||||
| -rw-r--r-- | lib/screens/gradients.js | 26 | ||||
| -rw-r--r-- | lib/screens/mirrors.js | 44 | ||||
| -rw-r--r-- | lib/screens/random.js | 26 | ||||
| -rw-r--r-- | lib/screens/sprinkles.js | 28 |
5 files changed, 80 insertions, 80 deletions
diff --git a/lib/screens/circle.js b/lib/screens/circle.js index 720e250..d09cb07 100644 --- a/lib/screens/circle.js +++ b/lib/screens/circle.js @@ -8,29 +8,29 @@ */ module.exports = function (modulation, width, height, renderer) { - const response = []; + let response = ''; - const circles = width > height ? height : width; + const circles = width > height ? height : width; - for (let i = 0; i < circles; ++i) { - const centerX = Math.round(width / 2) + 1; - const centerY = Math.round(height / 2) + 1; + for (let i = 0; i < circles; ++i) { + const centerX = Math.round(width / 2) + 1; + const centerY = Math.round(height / 2) + 1; - const red = Math.floor(Math.random() * 255); - const blue = Math.floor(Math.random() * 255); - const 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 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); + 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) { - const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H) - response += `${position}${renderer(red, blue, green)} `; - } + if (x <= width && x > 0 && y <= height && y > 0) { + const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H) + response += `${position}${renderer(red, blue, green)} `; + } + } } - } - return response; + return response; }; diff --git a/lib/screens/gradients.js b/lib/screens/gradients.js index 2d4a2f0..9694fc6 100644 --- a/lib/screens/gradients.js +++ b/lib/screens/gradients.js @@ -8,22 +8,22 @@ */ module.exports = function (modulation, width, height, renderer) { - let response = ''; + let response = ''; - 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; + 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 + ' '; - } + response = response + renderer(red, blue, green); + response = response + ' '; + } - if (i < height - 1) { - response = response + '\n'; + if (i < height - 1) { + response = response + '\n'; + } } - } - return response; + return response; }; diff --git a/lib/screens/mirrors.js b/lib/screens/mirrors.js index e842217..4f29c7d 100644 --- a/lib/screens/mirrors.js +++ b/lib/screens/mirrors.js @@ -8,33 +8,33 @@ */ module.exports = function (modulation, width, height, renderer) { - const response = []; + const response = []; - const scale = 2 + Math.round(Math.random() * 4); - const scaledHeight = Math.floor(height / scale); - const scaledWidth = Math.floor(width / scale); + const scale = 2 + Math.round(Math.random() * 4); + const scaledHeight = Math.floor(height / scale); + const scaledWidth = Math.floor(width / scale); - 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; + 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('')); - } + const cell = [renderer(red, blue, green), ' ']; + row.push(cell.join('')); + } - let rowText = ''; - for (let j = 0; j < scale; ++j) { - rowText += row.reverse().join(''); - } + let rowText = ''; + for (let j = 0; j < scale; ++j) { + rowText += row.reverse().join(''); + } - for (let j = 1; j < scale; ++j) { - response[j * i] = rowText; - response[(height - 1 - (j * i))] = rowText; + for (let j = 1; j < scale; ++j) { + response[j * i] = rowText; + response[(height - 1 - (j * i))] = rowText; + } } - } - return response.join('\n'); + return response.join('\n'); }; diff --git a/lib/screens/random.js b/lib/screens/random.js index 0cacea7..d5de257 100644 --- a/lib/screens/random.js +++ b/lib/screens/random.js @@ -8,22 +8,22 @@ */ module.exports = function (modulation, width, height, renderer) { - let response = ''; + let response = ''; - 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); + 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 + ' '; - } + response = response + renderer(red, blue, green); + response = response + ' '; + } - if (i < height - 1) { - response = response + '\n'; + if (i < height - 1) { + response = response + '\n'; + } } - } - return response; + return response; }; diff --git a/lib/screens/sprinkles.js b/lib/screens/sprinkles.js index f12200e..9ba1e16 100644 --- a/lib/screens/sprinkles.js +++ b/lib/screens/sprinkles.js @@ -9,24 +9,24 @@ */ module.exports = function (modulation, width, height, renderer) { - let response = ''; + let response = ''; - const maxSprinkleCount = (width * height) / 2; - const minSprinkleCount = (width * height) / 8; - const 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; - const red = Math.floor(Math.random() * 255); - const blue = Math.floor(Math.random() * 255); - const 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) { - const x = Math.round(Math.random() * (width - 1)) + 1; - const 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; - const 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)} `; - } + response += `${position}${renderer(red, blue, green)} `; + } - return response; + return response; }; |