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