aboutsummaryrefslogtreecommitdiff
path: root/lib/screens/mirrors.js
blob: 4f29c7d924dc0dafefaeebb2602f569f18d77bbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';

/**
 * Draws small moving gradient boxes and repeats them.
 *
 * @function MirrorsScreen
 * @implements IScreen
 */
module.exports = function (modulation, width, height, renderer) {

    const response = [];

    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;

            const 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');
};