aboutsummaryrefslogtreecommitdiff
path: root/lib/screens/random.js
blob: d5de25775a15ecec1393e8111550fa1a1b9e4b01 (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
'use strict';

/**
 * Draws random colors
 *
 * @function RandomScreen
 * @implements IScreen
 */
module.exports = function (modulation, width, height, renderer) {

    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);

            response = response + renderer(red, blue, green);
            response = response + ' ';
        }

        if (i < height - 1) {
            response = response + '\n';
        }
    }

    return response;
};