created brush related elms; added brush resret logic; refactored naming convention around brush lift state
This commit is contained in:
@@ -1,20 +1,40 @@
|
||||
const setupScriptRunner = () => {
|
||||
canvasContext = canvas.getContext("2d");
|
||||
canvasContext = canvas.getContext("2d");
|
||||
Painter.canvas = canvas;
|
||||
Painter.canvasContext = canvasContext;
|
||||
}
|
||||
|
||||
const runScript = () => {
|
||||
setToCenter();
|
||||
resetRotation();
|
||||
clearCanvas();
|
||||
|
||||
resetCanvasState();
|
||||
for (const elm of script.children) {
|
||||
elm.action(Painter);
|
||||
}
|
||||
}
|
||||
|
||||
const setToCenter = () => {
|
||||
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 = () => {
|
||||
Painter.x1 = Painter.canvas.width / 2
|
||||
Painter.y1 = Painter.canvas.height / 2
|
||||
Painter.canvasContext.moveTo( Painter.x1, Painter.y1 );
|
||||
|
||||
Reference in New Issue
Block a user