spin.js 618 B

1234567891011121314151617181920212223
  1. var charm = require('../')(process);
  2. charm.reset();
  3. var radius = 10;
  4. var theta = 0;
  5. var points = [];
  6. var iv = setInterval(function () {
  7. var x = 2 + (radius + Math.cos(theta) * radius) * 2;
  8. var y = 2 + radius + Math.sin(theta) * radius;
  9. points.unshift([ x, y ]);
  10. var colors = [ 'red', 'yellow', 'green', 'cyan', 'blue', 'magenta' ];
  11. points.forEach(function (p, i) {
  12. charm.position(p[0], p[1]);
  13. var c = colors[Math.floor(i / 12)];
  14. charm.background(c).write(' ')
  15. });
  16. points = points.slice(0, 12 * colors.length - 1);
  17. theta += Math.PI / 40;
  18. }, 50);