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