]>
Commit | Line | Data |
---|---|---|
1 | 'use strict'; | |
2 | ||
3 | /** | |
4 | * Draws concentric circles. Each ring has its own color. | |
5 | * | |
6 | * @function CircleScreen | |
7 | * @implements IScreen | |
8 | */ | |
9 | module.exports = function (modulation, width, height, renderer) { | |
10 | ||
11 | const response = []; | |
12 | ||
13 | const circles = width > height ? height : width; | |
14 | ||
15 | for (let i = 0; i < circles; ++i) { | |
16 | const centerX = Math.round(width / 2) + 1; | |
17 | const centerY = Math.round(height / 2) + 1; | |
18 | ||
19 | const red = Math.floor(Math.random() * 255); | |
20 | const blue = Math.floor(Math.random() * 255); | |
21 | const green = Math.floor(Math.random() * 255); | |
22 | ||
23 | for (let j = 0; j < 180; ++j) { | |
24 | const angle = 2 * j * (Math.PI / 180); | |
25 | const x = Math.round(centerX + Math.sin(angle) * i); | |
26 | const y = Math.round(centerY + Math.cos(angle) * i); | |
27 | ||
28 | if (x <= width && x > 0 && y <= height && y > 0) { | |
29 | const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H) | |
30 | response += `${position}${renderer(red, blue, green)} `; | |
31 | } | |
32 | } | |
33 | } | |
34 | ||
35 | return response; | |
36 | }; |