2026-10-31 23:35:38 -05:00
|
|
|
const setupScriptRunner = () => {
|
2026-11-01 00:25:24 -05:00
|
|
|
canvasContext = canvas.getContext("2d");
|
2026-10-31 23:35:38 -05:00
|
|
|
Painter.canvas = canvas;
|
|
|
|
|
Painter.canvasContext = canvasContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const runScript = () => {
|
2026-11-01 00:25:24 -05:00
|
|
|
resetCanvasState();
|
2026-10-31 23:35:38 -05:00
|
|
|
for (const elm of script.children) {
|
|
|
|
|
elm.action(Painter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-01 00:25:24 -05:00
|
|
|
const resetCanvasState = () => {
|
|
|
|
|
resetRotation();
|
|
|
|
|
resetCanvasBrush();
|
|
|
|
|
clearCanvas();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resetCanvasBrush = () => {
|
|
|
|
|
setDefaultBrushSize();
|
|
|
|
|
setDefaultBrushColor();
|
|
|
|
|
setBrushToCenter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const setDefaultBrushSize = () => {
|
|
|
|
|
Painter.brushSize = BRUSH_SIZE;
|
|
|
|
|
Painter.canvasContext.lineWidth = BRUSH_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const setDefaultBrushColor = () => {
|
|
|
|
|
Painter.brushColor = BRUSH_COLOR;
|
|
|
|
|
Painter.canvasContext.fillStyle = BRUSH_COLOR;
|
|
|
|
|
Painter.canvasContext.strokeStyle = BRUSH_COLOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const setBrushToCenter = () => {
|
2026-10-31 23:35:38 -05:00
|
|
|
Painter.x1 = Painter.canvas.width / 2
|
|
|
|
|
Painter.y1 = Painter.canvas.height / 2
|
|
|
|
|
Painter.canvasContext.moveTo( Painter.x1, Painter.y1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const clearCanvas = () => {
|
|
|
|
|
Painter.canvasContext.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resetRotation = () => {
|
|
|
|
|
Painter.rotation = 0;
|
|
|
|
|
}
|