Isogon.js 717 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var Path = require("../Path");
  2. /**
  3. * 正多边形
  4. * @module zrender/shape/Isogon
  5. */
  6. var PI = Math.PI;
  7. var sin = Math.sin;
  8. var cos = Math.cos;
  9. var _default = Path.extend({
  10. type: 'isogon',
  11. shape: {
  12. x: 0,
  13. y: 0,
  14. r: 0,
  15. n: 0
  16. },
  17. buildPath: function (ctx, shape) {
  18. var n = shape.n;
  19. if (!n || n < 2) {
  20. return;
  21. }
  22. var x = shape.x;
  23. var y = shape.y;
  24. var r = shape.r;
  25. var dStep = 2 * PI / n;
  26. var deg = -PI / 2;
  27. ctx.moveTo(x + r * cos(deg), y + r * sin(deg));
  28. for (var i = 0, end = n - 1; i < end; i++) {
  29. deg += dStep;
  30. ctx.lineTo(x + r * cos(deg), y + r * sin(deg));
  31. }
  32. ctx.closePath();
  33. return;
  34. }
  35. });
  36. module.exports = _default;