]> git.r.bdr.sh - rbdr/tomato-sauce/blame - lib/screens/circle.js
Update code and dpendencies
[rbdr/tomato-sauce] / lib / screens / circle.js
CommitLineData
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 */
9module.exports = function (modulation, width, height, renderer) {
c7b4bd19 10
a0666be3 11 let response = '';
c7b4bd19 12
a0666be3 13 const circles = width > height ? height : width;
c7b4bd19 14
a0666be3
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
a0666be3
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);
fd38d409 22
a0666be3
RBR
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 27
a0666be3
RBR
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 }
c7b4bd19 33 }
c7b4bd19 34
a0666be3 35 return response;
c7b4bd19 36};