Canvas based drawing board
English | 中文
Link: https://songlh.top/paint-board/
Completed Features:
- free draw
- color can be modified and line width can be displayed according to speed
- multiple effects, fluorescent、multicolor、crayon、bubbles、spray
- eraser
- draw text, dclick the board to enter text
- drawing board drag and drop
- select mode, can zoom, move and delete(Backspace) elements
- multi layer, can add, delete and sort
- undo, redo, clean, save
Unfinished Features:
- image
- Infinite scaling
- toggle background color
- multi project
- ...
git clone https://github.com/LHRUN/paint-board.git
pnpm install
pnpm dev
├─components
│ ├─info // help info
│ ├─layer // multi layer
│ ├─mask // mask
│ ├─toolPanel // tool panel
│ └─icons
│
├─hooks
│ └─event.ts // event hook
├─pages
│ └─board // board page
│
├─types
│
├─i18n
│
└─utils
├─constants
├─history.ts // history operation record
├─common.ts
├─layer.ts // multi layer
├─paintBoard.ts // PaintBoard
├─storage.ts // localStorage cache
├─cursor.ts // mouse cursor
├─select.ts // select mode
└─element
├─eraser.ts // eraser
├─element.ts // basic element
├─freeDraw.ts // free draw
└─text.ts // text element
- First create a PaintBoard class,where all canvas data is processed, such as init, render, dragging...
class PaintBoard {
canvas: HTMLCanvasElement
context: CanvasRenderingContext2D
...
constructor(canvas: HTMLCanvasElement) {}
initCanvas() {}
render() {}
drag() {}
...
}
- Then according to the current operation, create the corresponding canvas element, such as freedraw, eraserm, text...
class CanvasElement {
type: string
layer: number
// ...
constructor(type: string, layer: number) {
this.type = type
this.layer = layer
// ...
}
// ...
}
- Finally, some universal logic will be encapsulated to change the final display on canvas, such as undo, redo, layer...