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