Drawaria Geometric Pattern Generator (Fixed)

Dibuja patrones perfectos (Círculos, Espirales, Estrellas) sin errores

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         Drawaria Geometric Pattern Generator (Fixed)
// @namespace    http://tampermonkey.net
// @version      1.3
// @description  Dibuja patrones perfectos (Círculos, Espirales, Estrellas) sin errores
// @author       User
// @match        https://drawaria.online/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let drawing = false;

    // --- Interfaz de Usuario (Ajustada para no chocar con tus otros botones) ---
    const menu = document.createElement('div');
    menu.style = "position: fixed; top: 300px; left: 15px; z-index: 1000000; background: #1a1a1a; color: white; padding: 15px; border-radius: 10px; border: 2px solid #333; font-family: sans-serif; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.5); width: 135px;";
    menu.innerHTML = `
        <div style="font-weight: bold; text-align: center; font-size: 10px; color: #00ffff; margin-bottom: 5px;">GEOMETRIC BOTS</div>
        <button id="btnCircle" style="cursor:pointer; background:#444; color:white; border:none; padding:5px; border-radius:4px;">Círculo</button>
        <button id="btnSpiral" style="cursor:pointer; background:#444; color:white; border:none; padding:5px; border-radius:4px;">Espiral</button>
        <button id="btnStar" style="cursor:pointer; background:#444; color:white; border:none; padding:5px; border-radius:4px;">Estrella</button>
        <button id="btnStop" style="cursor:pointer; background:#d9534f; color:white; border:none; padding:5px; margin-top:5px; border-radius:4px; font-weight:bold;">DETENER</button>
    `;
    document.body.appendChild(menu);

    // --- Lógica de Dibujo Mejorada ---
    async function simulateMouse(x, y, type = 'mousedown') {
        const canvas = document.querySelector('canvas') || document.querySelector('#game-canvas');
        if (!canvas) return;
        const rect = canvas.getBoundingClientRect();
        
        const ev = new MouseEvent(type, {
            bubbles: true,
            cancelable: true,
            view: window,
            clientX: rect.left + x,
            clientY: rect.top + y,
            button: 0,
            buttons: (type === 'mouseup') ? 0 : 1 // Importante para que el juego detecte el "click"
        });
        canvas.dispatchEvent(ev);
    }

    async function drawPattern(points) {
        if (drawing) return; // Evita solapar dibujos
        drawing = true;
        
        for (let i = 0; i < points.length; i++) {
            if (!drawing) break;
            let type = 'mousemove';
            if (i === 0) type = 'mousedown';
            if (i === points.length - 1) type = 'mouseup';
            
            simulateMouse(points[i].x, points[i].y, type);
            await new Promise(r => setTimeout(r, 25)); // Delay más estable
        }
        drawing = false;
        simulateMouse(0, 0, 'mouseup');
    }

    function getCenter() {
        const canvas = document.querySelector('canvas') || document.querySelector('#game-canvas');
        return { x: canvas.width / 2, y: canvas.height / 2 };
    }

    // --- Eventos ---
    document.getElementById('btnCircle').onclick = () => {
        let pts = [];
        const {x: cX, y: cY} = getCenter();
        let radius = 120;
        for (let i = 0; i <= 360; i += 10) {
            let rad = i * Math.PI / 180;
            pts.push({ x: cX + radius * Math.cos(rad), y: cY + radius * Math.sin(rad) });
        }
        drawPattern(pts);
    };

    document.getElementById('btnSpiral').onclick = () => {
        let pts = [];
        const {x: cX, y: cY} = getCenter();
        for (let i = 0; i < 500; i += 5) {
            let angle = 0.1 * i;
            let x = cX + (1 + angle) * Math.cos(angle) * 3;
            let y = cY + (1 + angle) * Math.sin(angle) * 3;
            pts.push({ x, y });
        }
        drawPattern(pts);
    };

    document.getElementById('btnStar').onclick = () => {
        let pts = [];
        const {x: cX, y: cY} = getCenter();
        let r = 150;
        for (let i = 0; i <= 5; i++) {
            let angle = (i * 144 - 90) * Math.PI / 180; 
            pts.push({ x: cX + r * Math.cos(angle), y: cY + r * Math.sin(angle) });
        }
        drawPattern(pts);
    };

    document.getElementById('btnStop').onclick = () => {
        drawing = false;
        console.log("Bot detenido.");
    };

})();