Greasy Fork is available in English.

Квадратная кисть

xdxdxd

// ==UserScript==
// @name         Квадратная кисть
// @match        https://toonio.ru/editor*
// @grant        none
// @description  xdxdxd
// @namespace    scvare kistb
// @version 0.0.1.20230523181403
// ==/UserScript==

(function() {
    setTimeout(() => {
        let dragg;
        document.addEventListener("mousedown", (() => {
            dragg = toonio.drawWindow.drawing;
        }));
        let curLine;
        function addCubic(col, w, x, y) {
            w = Math.round(w / 2);
            toonio.frame.lines.push({
                d: { t: 2, w: 1, c: col, f: col },
                p: [
                    { x: x - w, y: y - w },
                    { x: x + w, y: y - w },
                    { x: x + w, y: y - w },
                    { x: x + w, y: y + w },
                    { x: x + w, y: y + w },
                    { x: x - w, y: y + w },
                    { x: x - w, y: y + w }
                ]
            });
        }
        function addCubicAllPoints(col, w, x1, y1, x2, y2) {
            const points = getLinePoints(x1, y1, x2, y2);
            for (let i in points) {
                addCubic(col, w, points[i].x, points[i].y);
            }
        }

        function getLinePoints(x1, y1, x2, y2, step = 4) {
            const points = [];
            const dx = Math.abs(x2 - x1);
            const dy = Math.abs(y2 - y1);
            const sx = (x1 < x2) ? 1 : -1;
            const sy = (y1 < y2) ? 1 : -1;
            let err = dx - dy;
            let e2;
            let x = x1;
            let y = y1;
            let i = 0;
            while (true) {
                if (x === x2 && y === y2) {
                    break;
                }
                e2 = 2 * err;
                if (e2 > -dy) {
                    err -= dy;
                    x += sx;
                }
                if (e2 < dx) {
                    err += dx;
                    y += sy;
                }

                if (i == step) {
                    i = 0;
                    points.push({ x: x, y: y });
                }
                i++
            }

            return points;
        }

        document.addEventListener("mouseup", ((e) => {
            let curFramelines = toonio.frame.lines;
            if (dragg && e.button == 0 && !toonio.drawWindow.drawing && toonio.drawWindow.tool.t == 1) {
                curLine = curFramelines[curFramelines.length - 1];
                curFramelines.pop();
                for (let i = 0; i < curLine.p.length - 1; i++) {
                    addCubic(curLine.d.c, curLine.d.w, curLine.p[i].x, curLine.p[i].y);
                    addCubicAllPoints(curLine.d.c, curLine.d.w, curLine.p[i].x, curLine.p[i].y, curLine.p[i + 1].x, curLine.p[i + 1].y);
                }
                toonio.Redraw()
            }
        }));
    },1000);
})();