| 1044 | |
| 1045 | class DigitSketchPad { |
| 1046 | constructor(container, rows, cols, options = {}) { |
| 1047 | if (!container) { |
| 1048 | throw new Error("Raster-Container nicht gefunden."); |
| 1049 | } |
| 1050 | this.container = container; |
| 1051 | this.rows = rows; |
| 1052 | this.cols = cols; |
| 1053 | this.values = new Float32Array(rows * cols); |
| 1054 | this.cells = []; |
| 1055 | this.isDrawing = false; |
| 1056 | this.activeMode = "draw"; |
| 1057 | this.onChange = null; |
| 1058 | this.pendingChange = false; |
| 1059 | this.interactionRow = null; |
| 1060 | const defaultBrush = { |
| 1061 | drawRadius: 1.2, |
| 1062 | eraseRadius: 1.2, |
| 1063 | drawStrength: 0.85, |
| 1064 | eraseStrength: 0.8, |
| 1065 | softness: 0.5, |
| 1066 | }; |
| 1067 | this.brush = Object.assign(defaultBrush, options.brush || {}); |
| 1068 | this.buildGrid(); |
| 1069 | } |
| 1070 | |
| 1071 | buildGrid() { |
| 1072 | this.gridElement = document.createElement("div"); |