Drawaria Geometric Pattern Generator (Fixed)

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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.");
    };

})();