Got it! You want a simple Minecraft-style pixel circle generator using HTML, CSS, and JavaScript. It should:
- Draw a circle made of pixel blocks (like Minecraft blocks) on an XZ grid (top-down view).
- Support:
- Color input
- Start degree and end degree (for partial circles/arcs)
- Zoom
- Move (offset)
- Debug mode (to show some grid or coordinate info)
- Include a shareable URL hash to restore settings (
# or #/ style)
Here is a complete working example:
<!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: #eee;
margin: 20px;
}
label {
margin-right: 10px;
}
input[type="number"] {
width: 60px;
}
#canvas {
image-rendering: pixelated;
margin-top: 15px;
border: 2px solid #555;
background: #111;
}
#debugInfo {
font-size: 0.8em;
margin-top: 10px;
color: #aaa;
}
.controls {
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Minecraft Pixel Circle Generator</h1>
<div class="controls">
<label>
Color: <input type="color" id="color" value="#4caf50"/>
</label>
<label>
Start °: <input type="number" id="startDeg" value="0" min="0" max="360" />
</label>
<label>
End °: <input type="number" id="endDeg" value="360" min="0" max="360" />
</label>
<label>
Radius: <input type="number" id="radius" value="12" min="1" max="64" />
</label>
<label>
Zoom: <input type="number" id="zoom" value="20" min="5" max="40" />
</label>
<label>
Move X: <input type="number" id="moveX" value="0" />
</label>
<label>
Move Z: <input type="number" id="moveZ" value="0" />
</label>
<label>
Debug: <input type="checkbox" id="debug" />
</label>
<button id="shareBtn">Generate Share Link</button>
</div>
<canvas id="canvas" width="640" height="640"></canvas>
<div id="debugInfo"></div>
<script>
(() => {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Controls
const colorInput = document.getElementById('color');
const startDegInput = document.getElementById('startDeg');
const endDegInput = document.getElementById('endDeg');
const radiusInput = document.getElementById('radius');
const zoomInput = document.getElementById('zoom');
const moveXInput = document.getElementById('moveX');
const moveZInput = document.getElementById('moveZ');
const debugInput = document.getElementById('debug');
const shareBtn = document.getElementById('shareBtn');
const debugDiv = document.getElementById('debugInfo');
// Save state to URL hash
function saveStateToHash() {
const v = [
colorInput.value.replace('#',''),
startDegInput.value,
endDegInput.value,
radiusInput.value,
zoomInput.value,
moveXInput.value,
moveZInput.value,
debugInput.checked ? '1' : '0'
].join(',');
location.hash = '#/' + v;
}
// Load from URL hash
function loadStateFromHash() {
if (!location.hash.startsWith('#/')) return false;
try {
let parts = location.hash.slice(2).split(',');
if (parts.length !== 8) return false;
colorInput.value = '#' + parts[0];
startDegInput.value = parts[1];
endDegInput.value = parts[2];
radiusInput.value = parts[3];
zoomInput.value = parts[4];
moveXInput.value = parts[5];
moveZInput.value = parts[6];
debugInput.checked = parts[7] === '1';
return true;
} catch {
return false;
}
}
function degToRad(d) {
return d * Math.PI / 180;
}
// Main draw function
function draw() {
const color = colorInput.value;
const startDeg = Math.min(Math.max(parseFloat(startDegInput.value), 0), 360);
const endDeg = Math.min(Math.max(parseFloat(endDegInput.value), 0), 360);
const radius = Math.max(parseInt(radiusInput.value), 1);
const zoom = Math.max(parseInt(zoomInput.value), 1);
const moveX = parseInt(moveXInput.value);
const moveZ = parseInt(moveZInput.value);
const debugMode = debugInput.checked;
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Fill background
ctx.fillStyle = '#111';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Center of canvas in pixels
const centerX = canvas.width/2 + moveX * zoom;
const centerZ = canvas.height/2 + moveZ * zoom;
// Draw grid in debug mode
if (debugMode) {
ctx.strokeStyle = '#333';
ctx.lineWidth = 1;
for(let x = 0; x <= canvas.width; x += zoom) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, canvas.height);
ctx.stroke();
}
for(let z = 0; z <= canvas.height; z += zoom) {
ctx.beginPath();
ctx.moveTo(0, z);
ctx.lineTo(canvas.width, z);
ctx.stroke();
}
}
// Draw all possible blocks in the radius bounds:
// We'll approximate a circle by testing each x,z if it lies on the edge of the arc.
// We want a circle pixelated on the XZ plane. Minecraft blocks are on integral grid.
// Use Midpoint Circle or just distance formula and angle check.
// Draw pixels that satisfy:
// radius - 0.5 <= dist <= radius + 0.5 (block thickness: 1 unit)
// and startDeg <= angle <= endDeg (angle in degrees from +X axis CCW)
ctx.fillStyle = color;
let blockCount = 0;
for(let x = -radius-1; x <= radius+1; x++) {
for(let z = -radius-1; z <= radius+1; z++) {
let dist = Math.sqrt(x*x + z*z);
if(dist >= radius - 0.5 && dist <= radius + 0.5) {
// Calculate angle in degrees from +X axis CCW:
let angle = Math.atan2(z, x) * 180/Math.PI;
if(angle < 0) angle += 360;
if (startDeg <= endDeg) {
if(angle < startDeg || angle > endDeg) continue;
} else {
// E.g. start=300, end=60 means arc crosses 0 deg
if(angle < startDeg && angle > endDeg) continue;
}
// Draw block at pixel pos
const px = centerX + x * zoom;
const pz = centerZ + z * zoom;
ctx.fillRect(px, pz, zoom, zoom);
if (debugMode) {
ctx.strokeStyle = '#222';
ctx.strokeRect(px, pz, zoom, zoom);
}
blockCount++;
}
}
}
debugDiv.textContent = `Blocks drawn: ${blockCount} | Center: (X:${-moveX}, Z:${-moveZ}) | Radius: ${radius} | Arc: ${startDeg}° to ${endDeg}°`;
}
function onChange() {
draw();
}
// Event Listeners
colorInput.addEventListener('input', onChange);
startDegInput.addEventListener('input', onChange);
endDegInput.addEventListener('input', onChange);
radiusInput.addEventListener('input', onChange);
zoomInput.addEventListener('input', onChange);
moveXInput.addEventListener('input', onChange);
moveZInput.addEventListener('input', onChange);
debugInput.addEventListener('change', onChange);
shareBtn.addEventListener('click', () => {
saveStateToHash();
alert('Share link generated! Copy the URL from the address bar.');
});
// Load on start if hash exists
loadStateFromHash();
draw();
})();
</script>
</body>
</html>
How it works:
- The canvas is a pixel grid.
- Each "block" is drawn as a filled square scaled by the zoom factor.
- You control the radius, arc angles (startDeg to endDeg), color, zoom, and offset (moveX, moveZ).
- Debug mode overlays a grid and outlines every block in a darker stroke.
- The "Generate Share Link" button serializes all options to the URL hash part, so you can share or bookmark that URL.
- Arc angles are interpreted in degrees starting from +X axis and increasing CCW, typical in math.
- Moving X and Z moves the circle on the canvas, good for checking offset.
- The canvas zoom controls block size while preserving crisp pixel block style with
image-rendering: pixelated;.
Usage example:
- Try setting startDeg=0, endDeg=180 for a semi-circle.
- Change color to any hex color.
- Adjust radius for size.
- Zoom controls pixel block size.
- Move X / Z shifts circle on the canvas.
- Enable debug mode to see grid and block edges.
- Click "Generate share link" to update URL which you can copy and share.
If you want me to add extra features or export as Minecraft commands / schematic blocks, just ask!