Rose.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { __extends } from "tslib";
  2. import Path from '../Path.js';
  3. var sin = Math.sin;
  4. var cos = Math.cos;
  5. var radian = Math.PI / 180;
  6. var RoseShape = (function () {
  7. function RoseShape() {
  8. this.cx = 0;
  9. this.cy = 0;
  10. this.r = [];
  11. this.k = 0;
  12. this.n = 1;
  13. }
  14. return RoseShape;
  15. }());
  16. export { RoseShape };
  17. var Rose = (function (_super) {
  18. __extends(Rose, _super);
  19. function Rose(opts) {
  20. return _super.call(this, opts) || this;
  21. }
  22. Rose.prototype.getDefaultStyle = function () {
  23. return {
  24. stroke: '#000',
  25. fill: null
  26. };
  27. };
  28. Rose.prototype.getDefaultShape = function () {
  29. return new RoseShape();
  30. };
  31. Rose.prototype.buildPath = function (ctx, shape) {
  32. var R = shape.r;
  33. var k = shape.k;
  34. var n = shape.n;
  35. var x0 = shape.cx;
  36. var y0 = shape.cy;
  37. var x;
  38. var y;
  39. var r;
  40. ctx.moveTo(x0, y0);
  41. for (var i = 0, len = R.length; i < len; i++) {
  42. r = R[i];
  43. for (var j = 0; j <= 360 * n; j++) {
  44. x = r
  45. * sin(k / n * j % 360 * radian)
  46. * cos(j * radian)
  47. + x0;
  48. y = r
  49. * sin(k / n * j % 360 * radian)
  50. * sin(j * radian)
  51. + y0;
  52. ctx.lineTo(x, y);
  53. }
  54. }
  55. };
  56. return Rose;
  57. }(Path));
  58. Rose.prototype.type = 'rose';
  59. export default Rose;