]>
Commit | Line | Data |
---|---|---|
c7b4bd19 BB |
1 | 'use strict'; |
2 | ||
fd38d409 RBR |
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) { | |
c7b4bd19 | 10 | |
6b909d95 | 11 | let response = []; |
c7b4bd19 | 12 | |
fd38d409 | 13 | const circles = width > height ? height : width; |
c7b4bd19 | 14 | |
fd38d409 RBR |
15 | for (let i = 0; i < circles; ++i) { |
16 | const centerX = Math.round(width / 2) + 1; | |
17 | const centerY = Math.round(height / 2) + 1; | |
c7b4bd19 | 18 | |
fd38d409 RBR |
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); | |
c7b4bd19 BB |
27 | |
28 | if (x <= width && x > 0 && y <= height && y > 0) { | |
6b909d95 | 29 | const position = `\x1B[${y};${x}H`; // Move cursor to y,x (CSI y;x H) |
c7b4bd19 BB |
30 | response += `${position}${renderer(red, blue, green)} `; |
31 | } | |
32 | } | |
33 | } | |
34 | ||
35 | return response; | |
36 | }; |