Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIAi2 WildChat-4.8M (AI2)

html css js minecraft pixel circle generator color startdeg enddeg debug x z share "#/"

  1. User

    html css js minecraft pixel circle generator color startdeg enddeg debug x z share "#/"

  2. Assistant

    It looks like you want a Minecraft pixel-style circle generator that works with colors, start and end degrees (for partial circles/arcs), supports debug mode, and coordinates (x, z) for positioning, plus a way to share the generated result using a URL hash (like #/).

    Here's a complete HTML + CSS + JS example that:

    • Generates a pixelated circle (or partial circle arc) in Minecraft block style
    • Allows specifying the color, start and end degrees (in degrees)
    • Accepts coordinate offsets (x, z) for the circle center
    • Has a debug mode to show angle/radius info
    • Encodes the parameters in the URL hash for easy sharing
    • Parses the URL hash on load to restore state

    Features

    • Pixel circle: Made with square divs in a grid, colored blocks for pixels
    • Partial arc support: Draws only pixels between startDeg and endDeg on a circle of set radius
    • Coordinates: The circle center is labeled with x, z coordinates
    • Debug: Shows circle radius and angles on hover or overlay
    • URL share: Changing inputs updates URL hash, loading URL with hash restores the circle

    Example Code

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Minecraft Pixel Circle Generator</title>
    <style>
      body {
        font-family: monospace, monospace;
        background: #222;
        color: #ddd;
        margin: 0;
        padding: 1em;
      }
      h1 {
        margin-top: 0;
      }
      #controls {
        margin-bottom: 1em;
        display: flex;
        flex-wrap: wrap;
        gap: 1em;
      }
      label {
        display: flex;
        flex-direction: column;
        font-size: 0.9em;
        min-width: 100px;
      }
      input[type="number"],
      input[type="color"] {
        font-size: 1em;
        padding: 0.2em 0.4em;
        border-radius: 3px;
        border: 1px solid #555;
        background: #111;
        color: #eee;
        margin-top: 0.25em;
      }
      input[type="checkbox"] {
        margin-top: 1.25em;
        width: 20px;
        height: 20px;
      }
      #canvas {
        width: 300px;
        height: 300px;
        position: relative;
        image-rendering: pixelated;
        border: 2px solid #666;
        background: #000;
      }
      .pixel {
        position: absolute;
        width: 10px;
        height: 10px;
        box-sizing: border-box;
        border: 1px solid #333;
      }
      .center-label {
        position:absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: #eee;
        font-weight: bold;
        pointer-events:none;
        text-shadow: 0 0 5px #222;
      }
      #debug-info {
        margin-top: 1em;
        font-size: 0.9em;
        white-space: pre-wrap;
        max-height: 200px;
        overflow-y: auto;
        background: #111;
        padding: 0.5em;
        border-radius: 4px;
        border: 1px solid #444;
      }
    </style>
    </head>
    <body>
    
    <h1>Minecraft Pixel Circle Generator</h1>
    
    <div id="controls">
      <label>
        Color
        <input type="color" id="color" value="#b5651d" title="Block color" />
      </label>
      <label>
        Start Degree
        <input type="number" id="startDeg" value="0" min="0" max="360" step="1" />
      </label>
      <label>
        End Degree
        <input type="number" id="endDeg" value="360" min="0" max="360" step="1" />
      </label>
      <label>
        Radius (pixels)
        <input type="number" id="radius" value="10" min="1" max="100" step="1" />
      </label>
      <label>
        Center X (block)
        <input type="number" id="centerX" value="0" step="1" />
      </label>
      <label>
        Center Z (block)
        <input type="number" id="centerZ" value="0" step="1" />
      </label>
      <label>
        Debug
        <input type="checkbox" id="debug" />
      </label>
    </div>
    
    <div id="canvas"></div>
    <div id="debug-info" style="display:none;"></div>
    
    <script>
    // Helpers
    function degToRad(deg) {
      return deg * Math.PI / 180;
    }
    
    function mod(n, m) {
      return ((n % m) + m) % m;
    }
    
    // Main
    (() => {
      const colorInput = document.getElementById('color');
      const startDegInput = document.getElementById('startDeg');
      const endDegInput = document.getElementById('endDeg');
      const radiusInput = document.getElementById('radius');
      const centerXInput = document.getElementById('centerX');
      const centerZInput = document.getElementById('centerZ');
      const debugInput = document.getElementById('debug');
      const canvas = document.getElementById('canvas');
      const debugInfo = document.getElementById('debug-info');
    
      const pixelSize = 10; // px per block pixel
    
      function updateURLHash() {
        const state = {
          c: colorInput.value,
          s: +startDegInput.value,
          e: +endDegInput.value,
          r: +radiusInput.value,
          x: +centerXInput.value,
          z: +centerZInput.value,
          d: debugInput.checked ? 1 : 0,
        };
        const hash = Object.entries(state)
          .map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
          .join('&');
        location.hash = '#/' + hash;
      }
    
      function parseHash() {
        const hash = location.hash;
        if (!hash.startsWith('#/')) return null;
        const query = hash.slice(2); // remove "#/"
        const params = {};
        query.split('&').forEach(kv => {
          const [k,v] = kv.split('=');
          if(k) params[k] = decodeURIComponent(v);
        });
        return params;
      }
    
      // Generates pixel positions for circle arc
      // centered at (cx, cz)
      function generateCirclePixels(radius, startRad, endRad, cx, cz) {
        const pixels = [];
    
        // We'll use integer grid offsets from center, check if on circle within tolerance
        // Limiting search area to (radius +1)^2 to speed up
        const rOuter = radius + 0.5; // allow 0.5 px tolerance
        const rInner = radius - 0.5;
    
        for (let dx = -radius; dx <= radius; dx++) {
          for (let dz = -radius; dz <= radius; dz++) {
            // distance
            const dist = Math.sqrt(dx*dx + dz*dz);
            if (dist >= rInner && dist <= rOuter) {
              // Compute angle in degrees 0-360, 0 on +X axis, CCW positive
              // Minecraft coords: X right, Z down on canvas? We'll consider +X right, +Z down.
    
              // atan2(z, x) to get angle
              let angle = Math.atan2(dz, dx) * (180 / Math.PI);
              if (angle < 0) angle += 360;
    
              // Check if angle in arc range (handling wraparound)
              let s = startRad >= 0 ? startRad : startRad + 2*Math.PI;
              let e = endRad >= 0 ? endRad : endRad + 2*Math.PI;
    
              // But easier, keep degrees because inputs given in degrees
              const startDeg = +startDegInput.value;
              const endDeg = +endDegInput.value;
    
              // Handle wraparound: e.g. start=350, end=10 means angles between 350-360 and 0-10
              function inArc(a, s, e) {
                a = mod(a, 360);
                s = mod(s, 360);
                e = mod(e, 360);
                if (s <= e) return a >= s && a <= e;
                else return a >= s || a <= e;
              }
    
              if (inArc(angle, startDeg, endDeg)) {
                pixels.push({x: cx + dx, z: cz + dz, angle: angle, dist: dist});
              }
            }
          }
        }
        return pixels;
      }
    
      // Render pixels on canvas
      function render() {
        canvas.innerHTML = ''; // clear
    
        const color = colorInput.value;
        const startDeg = +startDegInput.value;
        const endDeg = +endDegInput.value;
        const radius = +radiusInput.value;
        const cx = +centerXInput.value;
        const cz = +centerZInput.value;
        const debug = debugInput.checked;
    
        // Generate pixels
        const pixels = generateCirclePixels(radius, degToRad(startDeg), degToRad(endDeg), 0, 0);
    
        // Center offset to canvas center
        // Canvas is 300x300 px, center at (150,150)
        // We position pixels so that center pixel (0,0) is at center
    
        pixels.forEach(p => {
          const el = document.createElement('div');
          el.className = 'pixel';
          el.style.backgroundColor = color;
    
          // Pixel position relative to center pixel on canvas
          const left = 150 + (p.x * pixelSize) - pixelSize/2;
          const top = 150 + (p.z * pixelSize) - pixelSize/2;
    
          el.style.left = `${left}px`;
          el.style.top = `${top}px`;
          el.title = `x:${p.x + cx} z:${p.z + cz}\nAngle:${p.angle.toFixed(1)}°\nDist:${p.dist.toFixed(2)}`;
    
          if (debug) {
            el.style.borderColor = `#fff`;
          } else {
            el.style.borderColor = `#222`;
          }
    
          canvas.appendChild(el);
        });
    
        // Add center marker with coordinates
        const centerLabel = document.createElement('div');
        centerLabel.className = 'center-label';
        centerLabel.textContent = `(${cx}, ${cz})`;
        canvas.appendChild(centerLabel);
    
        if (debug) {
          debugInfo.style.display = 'block';
          debugInfo.textContent = `Radius: ${radius}\nStart Degree: ${startDeg}°\nEnd Degree: ${endDeg}°\nColor: ${color}\nCenter: (${cx}, ${cz})\nPixels: ${pixels.length}`;
        } else {
          debugInfo.style.display = 'none';
        }
      }
    
      // On inputs change
      function onChange() {
        render();
        updateURLHash();
      }
    
      // Initialize from URL hash or defaults
      function initFromHash() {
        const params = parseHash();
        if (!params) return;
    
        if (params.c) colorInput.value = params.c;
        if (params.s !== undefined) startDegInput.value = params.s;
        if (params.e !== undefined) endDegInput.value = params.e;
        if (params.r !== undefined) radiusInput.value = params.r;
        if (params.x !== undefined) centerXInput.value = params.x;
        if (params.z !== undefined) centerZInput.value = params.z;
        if (params.d !== undefined) debugInput.checked = params.d === '1';
      }
    
      // Add event listeners
      [colorInput, startDegInput, endDegInput, radiusInput, centerXInput, centerZInput, debugInput].forEach(input => {
        input.addEventListener('input', onChange);
      });
    
      // Init
      initFromHash();
      render();
    
    })();
    </script>
    
    </body>
    </html>
    

    How to Use

    • Pick a color for the blocks.
    • Enter a start degree and end degree from 0 to 360 to draw a full or partial arc (e.g. 0 to 360 draws a full circle, 45 to 135 draws an arc).
    • Set the radius for how big the circle is in pixels (blocks).
    • Set the center coordinates X and Z (Minecraft block coordinates for your reference).
    • Check Debug to see extra info and pixel borders.
    • The circle will show on the 300x300 canvas with pixelated blocks.
    • The URL hash updates with your configuration, so you can share your circle via the URL (copy and open the link to restore the circle).
    • Hover individual pixels to see their coordinate and angle info in tooltips (only visible in debug mode).

    Example share link

    You can try this directly by copying into an .html file and opening in a modern browser:

    file:///path/to/your/file.html#/c=%23b5651d&s=0&e=360&r=10&x=0&z=0&d=1
    

    Or you can change inputs and copy the URL to share.


    If you want me to help adapt this further or build additional features (like export to Minecraft commands or schematic blocks), just ask!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.