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