Rose.js 855 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var Path = require("../Path");
  2. /**
  3. * 玫瑰线
  4. * @module zrender/graphic/shape/Rose
  5. */
  6. var sin = Math.sin;
  7. var cos = Math.cos;
  8. var radian = Math.PI / 180;
  9. var _default = Path.extend({
  10. type: 'rose',
  11. shape: {
  12. cx: 0,
  13. cy: 0,
  14. r: [],
  15. k: 0,
  16. n: 1
  17. },
  18. style: {
  19. stroke: '#000',
  20. fill: null
  21. },
  22. buildPath: function (ctx, shape) {
  23. var x;
  24. var y;
  25. var R = shape.r;
  26. var r;
  27. var k = shape.k;
  28. var n = shape.n;
  29. var x0 = shape.cx;
  30. var y0 = shape.cy;
  31. ctx.moveTo(x0, y0);
  32. for (var i = 0, len = R.length; i < len; i++) {
  33. r = R[i];
  34. for (var j = 0; j <= 360 * n; j++) {
  35. x = r * sin(k / n * j % 360 * radian) * cos(j * radian) + x0;
  36. y = r * sin(k / n * j % 360 * radian) * sin(j * radian) + y0;
  37. ctx.lineTo(x, y);
  38. }
  39. }
  40. }
  41. });
  42. module.exports = _default;