]>
git.r.bdr.sh - rbdr/tomato-sauce/blob - lib/screens/circle.js
d8a4d100730ad4b4c3b05732e7b2ea9abaa7c670
3 // Draws concentric circles. Each ring has its own color.
4 const Circle = function (modulation
, width
, height
, renderer
) {
7 let circles
= width
> height
? height : width
;
9 for (let i
= 0; i
< circles
; i
++) {
10 let centerX
= Math
.round(width
/ 2) + 1;
11 let centerY
= Math
.round(height
/ 2) + 1;
13 let red
= Math
.floor(Math
.random() * 255);
14 let blue
= Math
.floor(Math
.random() * 255);
15 let green
= Math
.floor(Math
.random() * 255);
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
);
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)} `;
32 module
.exports
= Circle
;