2e62cfd799a8b5f4f7d81628ca346e84d4675d2c5c4a6c5dcbf6f51aead35d2095e05f663a2d4a550422bf6ef4a3bba1bc0a98e9ab9266d51c3c9958b94055 781 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * 圆环
  3. */
  4. import Path, { PathProps } from '../Path';
  5. export class RingShape {
  6. cx = 0
  7. cy = 0
  8. r = 0
  9. r0 = 0
  10. }
  11. export interface RingProps extends PathProps {
  12. shape?: Partial<RingShape>
  13. }
  14. class Ring extends Path<RingProps> {
  15. shape: RingShape
  16. constructor(opts?: RingProps) {
  17. super(opts);
  18. }
  19. getDefaultShape() {
  20. return new RingShape();
  21. }
  22. buildPath(ctx: CanvasRenderingContext2D, shape: RingShape) {
  23. const x = shape.cx;
  24. const y = shape.cy;
  25. const PI2 = Math.PI * 2;
  26. ctx.moveTo(x + shape.r, y);
  27. ctx.arc(x, y, shape.r, 0, PI2, false);
  28. ctx.moveTo(x + shape.r0, y);
  29. ctx.arc(x, y, shape.r0, 0, PI2, true);
  30. }
  31. }
  32. Ring.prototype.type = 'ring';
  33. export default Ring;