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 zoom move…

  1. User

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

  2. Assistant

    Certainly! Below is a complete basic HTML + CSS + JS example of a Minecraft-style pixel circle generator with the following features:

    • Color picker
    • Start angle and end angle (in degrees)
    • Debug mode (shows pixel by pixel)
    • X and Z coordinates for center
    • Zoom
    • Move (pan) the canvas
    • Shareable URL hash reflecting all parameters

    The circle is drawn on a pixel grid to simulate Minecraft blocks. The "pixels" are squares colored with the chosen color.


    How it works overview:

    • The circle drawing uses the midpoint circle algorithm adapted for angles (start and end angle limit the drawn arc).
    • You can adjust the center (x, z) coordinates.
    • Zoom controls pixel size.
    • Pan by dragging the canvas.
    • Debug mode toggles grid lines & pixel outlines.
    • The URL hash encodes parameters:
      #/color=#rrggbb&start=deg&end=deg&debug=1|0&x=number&z=number&zoom=number&moveX=number&moveZ=number

    When you change any parameter, the hash updates automatically. Loading URL with hash will restore settings.


    Full 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 {
        background: #222;
        color: #eee;
        font-family: monospace, monospace;
        margin: 0; padding: 10px;
        user-select: none;
      }
      #controls {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 10px;
      }
      label {
        display: flex;
        flex-direction: column;
        font-size: 0.9rem;
        min-width: 100px;
      }
      input[type="number"], input[type="color"] {
        font-size: 1rem;
        width: 100%;
      }
      input[type="checkbox"] {
        transform: scale(1.3);
        margin-right: 5px;
      }
      #canvas {
        background:#111;
        image-rendering: pixelated;
        border: 1px solid #666;
        cursor: grab;
        display: block;
        margin: 0 auto;
      }
      #canvas:active {
        cursor: grabbing;
      }
      #info {
        margin-top: 10px;
        font-size: 0.9rem;
      }
      a.sharelink {
        color: #4af;
        text-decoration: underline;
        cursor: pointer;
      }
    </style>
    </head>
    <body>
    
    <h1>Minecraft Pixel Circle Generator</h1>
    
    <div id="controls">
      <label>Color
        <input type="color" id="color" value="#00cc44" title="Pick color" />
      </label>
    
      <label>Start Angle (deg)
        <input type="number" id="startAngle" min="0" max="360" step="1" value="0" />
      </label>
    
      <label>End Angle (deg)
        <input type="number" id="endAngle" min="0" max="360" step="1" value="360" />
      </label>
    
      <label>Center X (block)
        <input type="number" id="centerX" step="1" value="0" />
      </label>
    
      <label>Center Z (block)
        <input type="number" id="centerZ" step="1" value="0" />
      </label>
    
      <label>Zoom (pixel size)
        <input type="number" id="zoom" min="1" max="40" step="1" value="12" />
      </label>
    
      <label title="Show pixel outlines and coordinate info">
        <input type="checkbox" id="debug" /> Debug mode
      </label>
    </div>
    
    <canvas id="canvas" width="600" height="600" tabindex="0" aria-label="Minecraft pixel circle canvas"></canvas>
    
    <div id="info">
      <p>Drag canvas to pan. Scroll to zoom. URL updates automatically to share settings.</p>
      <p>Share link: <a href="#" id="shareLink" class="sharelink">current</a></p>
    </div>
    
    <script>
    (() => {
      // Elements
      const canvas = document.getElementById('canvas');
      const ctx = canvas.getContext('2d');
      const colorInput = document.getElementById('color');
      const startAngleInput = document.getElementById('startAngle');
      const endAngleInput = document.getElementById('endAngle');
      const centerXInput = document.getElementById('centerX');
      const centerZInput = document.getElementById('centerZ');
      const zoomInput = document.getElementById('zoom');
      const debugInput = document.getElementById('debug');
      const shareLink = document.getElementById('shareLink');
      
      const width = canvas.width;
      const height = canvas.height;
    
      // State
      let color = colorInput.value;
      let startAngle = +startAngleInput.value;
      let endAngle = +endAngleInput.value;
      let centerX = +centerXInput.value;
      let centerZ = +centerZInput.value;
      let zoom = +zoomInput.value;
      let debug = debugInput.checked;
    
      // For panning
      let panX = 0;
      let panZ = 0;
      let isDragging = false;
      let dragStart = null;
    
      // Utility: Normalize angles 0-360 (degrees)
      function normAngle(a) {
        a = a % 360;
        if(a < 0) a += 360;
        return a;
      }
    
      // Utility: Check if angle is between start and end angles (assuming CCW)
      function angleInRange(angle, startDeg, endDeg) {
        angle = normAngle(angle);
        startDeg = normAngle(startDeg);
        endDeg = normAngle(endDeg);
        if(startDeg <= endDeg) {
          return angle >= startDeg && angle <= endDeg;
        } else {
          // Wrap-around case, e.g. start=350, end=40
          return angle >= startDeg || angle <= endDeg;
        }
      }
    
      // Parse URL hash params
      function parseHash() {
        const hash = location.hash.slice(2); // remove "#/"
        if(!hash) return;
        const params = {};
        hash.split('&').forEach(kv => {
          let [k,v] = kv.split('=');
          if(k && v !== undefined) params[k] = decodeURIComponent(v);
        });
        if(params.color) color = params.color;
        if(params.start) startAngle = +params.start;
        if(params.end) endAngle = +params.end;
        if(params.x) centerX = +params.x;
        if(params.z) centerZ = +params.z;
        if(params.zoom) zoom = +params.zoom;
        if(params.debug) debug = params.debug === '1' || params.debug === 'true';
        if(params.moveX) panX = +params.moveX;
        if(params.moveZ) panZ = +params.moveZ;
    
        // Sync inputs
        colorInput.value = color;
        startAngleInput.value = startAngle;
        endAngleInput.value = endAngle;
        centerXInput.value = centerX;
        centerZInput.value = centerZ;
        zoomInput.value = zoom;
        debugInput.checked = debug;
      }
    
      // Update URL hash based on current params
      function updateHash() {
        const parts = [
          `color=${encodeURIComponent(color)}`,
          `start=${startAngle}`,
          `end=${endAngle}`,
          `debug=${debug ? '1' : '0'}`,
          `x=${centerX}`,
          `z=${centerZ}`,
          `zoom=${zoom}`,
          `moveX=${panX}`,
          `moveZ=${panZ}`
        ];
        const newHash = '#/' + parts.join('&');
        if(location.hash !== newHash) {
          history.replaceState(null, null, newHash);
          shareLink.href = newHash;
        }
      }
    
      // Convert block coords (x,z) to canvas pixel coords
      function blockToCanvas(x, z) {
        // Center: canvas center + pan + (block - center blocks)*zoom
        let cx = width / 2 + panX + (x - centerX) * zoom;
        let cz = height / 2 + panZ + (z - centerZ) * zoom;
        return [cx, cz];
      }
    
      // Calculate pixels on the circle using Midpoint Circle algorithm 
      // Adapted for arc between startAngle and endAngle.
      // Returns an array of block coords [x,z] for the circle pixels.
      function calculateCirclePixels(radius, startDeg, endDeg) {
        // Midpoint circle algorithm: iterate over first 1/8 circle and reflect points.
        // But we have angles limits, so for each candidate pixel we calculate angle and test.
    
        const pixels = new Set();
    
        // We'll iterate x = 0 to radius
        let x = 0;
        let y = radius;
        let d = 1 - radius;
    
        function processPoint(px, pz) {
          // Angle from center to point in degrees 0-360 with 0° at +X axis, CCW
          let angle = Math.atan2(pz, px) * 180 / Math.PI;
          angle = normAngle(angle);
          if(angleInRange(angle, startDeg, endDeg)) {
            pixels.add(`${px},${pz}`);
          }
        }
    
        while(x <= y) {
          // 8 octant symmetry
          // positions relative to center (0,0)
          processPoint( x,  y);
          processPoint( y,  x);
          processPoint( y, -x);
          processPoint( x, -y);
          processPoint(-x, -y);
          processPoint(-y, -x);
          processPoint(-y,  x);
          processPoint(-x,  y);
    
          if(d < 0) {
            d = d + 2 * x + 3;
          } else {
            d = d + 2 * (x - y) + 5;
            y--;
          }
          x++;
        }
    
        // Return as array of [x,z]
        return Array.from(pixels).map(s => s.split(',').map(Number));
      }
    
      // Draw grid lines for debug mode
      function drawGrid() {
        ctx.strokeStyle = "#444";
        ctx.lineWidth = 1;
        for(let x = 0; x <= width; x += zoom) {
          ctx.beginPath();
          ctx.moveTo(x + panX % zoom, 0);
          ctx.lineTo(x + panX % zoom, height);
          ctx.stroke();
        }
        for(let y = 0; y <= height; y += zoom) {
          ctx.beginPath();
          ctx.moveTo(0, y + panZ % zoom);
          ctx.lineTo(width, y + panZ % zoom);
          ctx.stroke();
        }
      }
    
      // Draw the circle pixels
      function drawCircle() {
        ctx.clearRect(0,0,width,height);
    
        if(debug) {
          drawGrid();
        }
    
        const radius = Math.round(Math.min(width, height) / 2 / zoom) - 1;
    
        // Get pixels circle arc coords in block space relative to center
        const pixels = calculateCirclePixels(radius, startAngle, endAngle);
    
        // Draw pixels as squares
        ctx.fillStyle = color;
        pixels.forEach(([dx, dz]) => {
          // Convert to canvas coords
          const [cx, cz] = blockToCanvas(dx + centerX, dz + centerZ);
          const px = Math.round(cx - zoom/2);
          const pz = Math.round(cz - zoom/2);
          ctx.fillRect(px, pz, zoom, zoom);
    
          // debug outlines and coords
          if(debug) {
            ctx.strokeStyle = "#eee";
            ctx.lineWidth = 1;
            ctx.strokeRect(px+0.5, pz+0.5, zoom-1, zoom-1);
    
            ctx.fillStyle = "#eee";
            ctx.font = (zoom > 8 ? "9px monospace" : "6px monospace");
            ctx.textAlign = "center";
            ctx.textBaseline = "middle";
            ctx.fillText(`${dx},${dz}`, cx, cz);
            ctx.fillStyle = color;
          }
        });
      }
    
      // Update state from inputs
      function updateFromInputs() {
        color = colorInput.value;
        startAngle = +startAngleInput.value;
        if(isNaN(startAngle) || startAngle < 0) startAngle = 0;
        if(startAngle > 360) startAngle = 360;
        endAngle = +endAngleInput.value;
        if(isNaN(endAngle) || endAngle < 0) endAngle = 0;
        if(endAngle > 360) endAngle = 360;
        centerX = +centerXInput.value;
        if(isNaN(centerX)) centerX = 0;
        centerZ = +centerZInput.value;
        if(isNaN(centerZ)) centerZ = 0;
        zoom = +zoomInput.value;
        if(isNaN(zoom) || zoom < 1) zoom = 12;
        if(zoom > 40) zoom = 40;
        debug = debugInput.checked;
      }
    
      // Input event handler
      function onInputChange() {
        updateFromInputs();
        updateHash();
        drawCircle();
      }
    
      // Handle canvas panning and zooming
      function onWheel(e) {
        e.preventDefault();
        const delta = Math.sign(e.deltaY);
        const oldZoom = zoom;
        zoom -= delta;
        if(zoom < 1) zoom = 1;
        if(zoom > 40) zoom = 40;
    
        // Adjust panX, panZ to zoom towards mouse cursor
        const rect = canvas.getBoundingClientRect();
        const mx = e.clientX - rect.left;
        const my = e.clientY - rect.top;
    
        panX -= (mx - width/2 - panX) * (zoom/oldZoom - 1);
        panZ -= (my - height/2 - panZ) * (zoom/oldZoom - 1);
    
        zoomInput.value = zoom;
        updateHash();
        drawCircle();
      }
    
      function onMouseDown(e) {
        isDragging = true;
        dragStart = {x: e.clientX, z: e.clientY};
        canvas.style.cursor = 'grabbing';
      }
      function onMouseMove(e) {
        if(!isDragging) return;
        const dx = e.clientX - dragStart.x;
        const dz = e.clientY - dragStart.z;
        panX += dx;
        panZ += dz;
        dragStart = {x: e.clientX, z: e.clientY};
        updateHash();
        drawCircle();
      }
      function onMouseUp(e) {
        isDragging = false;
        canvas.style.cursor = 'grab';
      }
      function onMouseLeave(e) {
        if(isDragging) onMouseUp(e);
      }
    
      // When window loads, parse hash and draw
      function init() {
        parseHash();
        updateHash();
        drawCircle();
      }
    
      // Event listeners
      colorInput.addEventListener('input', onInputChange);
      startAngleInput.addEventListener('input', onInputChange);
      endAngleInput.addEventListener('input', onInputChange);
      centerXInput.addEventListener('input', onInputChange);
      centerZInput.addEventListener('input', onInputChange);
      zoomInput.addEventListener('input', onInputChange);
      debugInput.addEventListener('change', onInputChange);
    
      window.addEventListener('hashchange', () => {
        parseHash();
        drawCircle();
      });
    
      canvas.addEventListener('wheel', onWheel, {passive:false});
      canvas.addEventListener('mousedown', onMouseDown);
      window.addEventListener('mousemove', onMouseMove);
      window.addEventListener('mouseup', onMouseUp);
      canvas.addEventListener('mouseleave', onMouseLeave);
    
      // Init
      init();
    
    })();
    </script>
    
    </body>
    </html>
    

    Features:

    • Change Color with native color picker
    • Set Start Angle and End Angle to draw circle arcs
    • Change the center coordinates (Minecraft x,z block coordinates)
    • Zoom pixel size to enlarge or shrink blocks (min 1, max 40 pixels)
    • Drag canvas to pan/move the view
    • Debug mode shows grid and block coordinate labels on pixels
    • URL hash updates live, so you can copy the URL and share your circle setup.

    Usage tips:

    • Zoom/pan to explore the pixel circle
    • Try arcs by setting start=0, end=90 for quarter circle, etc.
    • Use debug mode to see pixel coordinates
    • Copy URL to share your design instantly

    Let me know if you want me to make it save/load designs or add export features!

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