Drawaria Geometric Pattern Generator (Fixed)

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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.");
    };

})();