-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrawRect.ts
39 lines (37 loc) · 816 Bytes
/
drawRect.ts
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
import drawMethods from '../drawMethods';
const drawRect = (
context: CanvasRenderingContext2D,
{
x,
y,
width,
height,
drawMethod = drawMethods.FILL,
rotation = 0,
}: {
x: number;
y: number;
width: number;
height: number;
drawMethod?: drawMethods;
rotation?: number;
}
): void => {
context.translate(x, y);
context.rotate(rotation);
const relativeX = -width / 2;
const relativeY = -height / 2;
if (
drawMethod === drawMethods.FILL ||
drawMethod === drawMethods.FILL_AND_STROKE
) {
context.fillRect(relativeX, relativeY, width, height);
}
if (
drawMethod === drawMethods.STROKE ||
drawMethod === drawMethods.FILL_AND_STROKE
) {
context.strokeRect(relativeX, relativeY, width, height);
}
};
export default drawRect;