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 | |
| parent | ae6dbe43bf54581dd7012f95581d4a1b6ee245f0 (diff) | |
| parent | 09ab7e985d46cad6d3c89e37f983e286e9fda2f6 (diff) | |
Merge branch 'feature/the-actual-tomato-sauce' into develop
Diffstat (limited to 'lib/screens')
| -rw-r--r-- | lib/screens/circle.js | 32 | ||||
| -rw-r--r-- | lib/screens/gradients.js | 25 | ||||
| -rw-r--r-- | lib/screens/mirrors.js | 36 | ||||
| -rw-r--r-- | lib/screens/random.js | 25 | ||||
| -rw-r--r-- | lib/screens/sprinkles.js | 28 |
5 files changed, 146 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; diff --git a/lib/screens/gradients.js b/lib/screens/gradients.js new file mode 100644 index 0000000..5e63d5b --- /dev/null +++ b/lib/screens/gradients.js @@ -0,0 +1,25 @@ +'use strict'; + +// Draws moving gradient boxes. +const Gradients = 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; + + response = response + renderer(red, blue, green); + response = response + ' '; + } + + if (i < height - 1) { + response = response + '\n'; + } + } + + return response; +}; + +module.exports = Gradients; diff --git a/lib/screens/mirrors.js b/lib/screens/mirrors.js new file mode 100644 index 0000000..d683fb6 --- /dev/null +++ b/lib/screens/mirrors.js @@ -0,0 +1,36 @@ +'use strict'; + +// Draws small moving gradient boxes and repeats them. +const Mirrors = function (modulation, width, height, renderer) { + let response = []; + + let scale = 2 + Math.round(Math.random() * 4); + let scaledHeight = Math.floor(height / scale); + let scaledWidth = Math.floor(width / scale); + + 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; + + let cell = [renderer(red, blue, green), ' ']; + row.push(cell.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; + } + } + + return response.join('\n'); +}; + +module.exports = Mirrors; diff --git a/lib/screens/random.js b/lib/screens/random.js new file mode 100644 index 0000000..6ac706f --- /dev/null +++ b/lib/screens/random.js @@ -0,0 +1,25 @@ +'use strict'; + +// random colors +const Random = 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); + + response = response + renderer(red, blue, green); + response = response + ' '; + } + + if (i < height - 1) { + response = response + '\n'; + } + } + + return response; +}; + +module.exports = Random; 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; |