]> git.r.bdr.sh - rbdr/tomato-sauce/blob - lib/screens/mirrors.js
e8422177cafafef3408f09cf347792f928a59647
[rbdr/tomato-sauce] / lib / screens / mirrors.js
1 'use strict';
2
3 /**
4 * Draws small moving gradient boxes and repeats them.
5 *
6 * @function MirrorsScreen
7 * @implements IScreen
8 */
9 module.exports = function (modulation, width, height, renderer) {
10
11 const response = [];
12
13 const scale = 2 + Math.round(Math.random() * 4);
14 const scaledHeight = Math.floor(height / scale);
15 const scaledWidth = Math.floor(width / scale);
16
17 for (let i = 0; i < scaledHeight; ++i) {
18 const row = [];
19 for (let j = 0; j < scaledWidth; ++j) {
20 const red = ((modulation + i) * 255 / height) % 255;
21 const blue = ((modulation + j) * 255 / width) % 255;
22 const green = ((modulation + i * j) * 255 / (width * height)) % 255;
23
24 const cell = [renderer(red, blue, green), ' '];
25 row.push(cell.join(''));
26 }
27
28 let rowText = '';
29 for (let j = 0; j < scale; ++j) {
30 rowText += row.reverse().join('');
31 }
32
33 for (let j = 1; j < scale; ++j) {
34 response[j * i] = rowText;
35 response[(height - 1 - (j * i))] = rowText;
36 }
37 }
38
39 return response.join('\n');
40 };