diff options
| author | eleanor-park <eleanor_park@brown.edu> | 2024-10-20 12:44:15 -0400 |
|---|---|---|
| committer | eleanor-park <eleanor_park@brown.edu> | 2024-10-20 12:44:15 -0400 |
| commit | 3b17868560090756caf8b9b0f043ea163f2320e8 (patch) | |
| tree | d748a5fa923f28e2f4e399a8846ea38aa06b78a7 /src/client/views/nodes/imageEditor/imageEditorUtils/BrushHandler.ts | |
| parent | fc06a98deec3fa2b173f8ea30a4f4b1781447b19 (diff) | |
changes
Diffstat (limited to 'src/client/views/nodes/imageEditor/imageEditorUtils/BrushHandler.ts')
| -rw-r--r-- | src/client/views/nodes/imageEditor/imageEditorUtils/BrushHandler.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/client/views/nodes/imageEditor/imageEditorUtils/BrushHandler.ts b/src/client/views/nodes/imageEditor/imageEditorUtils/BrushHandler.ts new file mode 100644 index 000000000..a9fe02d4f --- /dev/null +++ b/src/client/views/nodes/imageEditor/imageEditorUtils/BrushHandler.ts @@ -0,0 +1,35 @@ +import { GenerativeFillMathHelpers } from './GenerativeFillMathHelpers'; +import { eraserColor } from './imageEditorConstants'; +import { Point } from './imageEditorInterfaces'; +import { points } from '@turf/turf'; + +export enum BrushType { + GEN_FILL, + CUT, +} + +export class BrushHandler { + static brushCircleOverlay = (x: number, y: number, brushRadius: number, ctx: CanvasRenderingContext2D, fillColor: string /* , erase: boolean */) => { + ctx.globalCompositeOperation = 'destination-out'; + ctx.fillStyle = fillColor; + ctx.shadowColor = eraserColor; + ctx.shadowBlur = 5; + ctx.beginPath(); + ctx.arc(x, y, brushRadius, 0, 2 * Math.PI); + ctx.fill(); + ctx.closePath(); + }; + + static createBrushPathOverlay = (startPoint: Point, endPoint: Point, brushRadius: number, ctx: CanvasRenderingContext2D, fillColor: string, brushType: BrushType) => { + const dist = GenerativeFillMathHelpers.distanceBetween(startPoint, endPoint); + const pts: Point[] = []; + for (let i = 0; i < dist; i += 5) { + const s = i / dist; + const x = startPoint.x * (1 - s) + endPoint.x * s; + const y = startPoint.y * (1 - s) + endPoint.y * s; + pts.push({ x: startPoint.x, y: startPoint.y }); + BrushHandler.brushCircleOverlay(x, y, brushRadius, ctx, fillColor); + } + return pts; + }; +} |
