Sure! Here's a simple Minecraft pixel circle generator that you can run in a browser. It generates a circle (or arc) of blocks in an X-Z plane with specified start and end degrees, and colors the blocks. It includes debug info and a shareable URL hash to store parameters.
html Copy 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: Arial, sans-serif;
margin: 20px;
background: #222;
color: #eee;
user-select: none;
}
label {
margin-right: 10px;
}
input[type=number], input[type=color] {
width: 80px;
margin-right: 20px;
border-radius: 4px;
border: 1px solid #444;
background: #333;
color: #eee;
text-align: center;
}
#canvas-container {
margin-top: 20px;
position: relative;
display: inline-block;
border: 2px solid #555;
background: #111;
}
canvas {
background: #111;
image-rendering: pixelated;
}
#debugInfo {
margin-top: 15px;
font-family: monospace;
max-height: 120px;
overflow-y: auto;
background: #111;
border: 1px solid #444;
padding: 8px;
white-space: pre-wrap;
font-size: 13px;
}
button {
background: #444;
color: #eee;
border: none;
padding: 8px 14px;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
}
button:hover {
background: #666;
}
#shareLink {
margin-left: 10px;
font-size: 12px;
color: #aaa;
}
#controls {
display: flex;
flex-wrap: wrap;
gap: 10px;
align-items: center;
}
</style>
</head>
<body>
<h1>Minecraft Pixel Circle Generator (X-Z plane)</h1>
<div id="controls">
<label>X: <input id="inputX" type="number" value="0" /></label>
<label>Z: <input id="inputZ" type="number" value="0" /></label>
<label>Radius: <input id="inputRadius" type="number" value="8" min="1" max="50" /></label>
<label>Start°: <input id="inputStartDeg" type="number" value="0" min="0" max="360" /></label>
<label>End°: <input id="inputEndDeg" type="number" value="360" min="0" max="360" /></label>
<label>Color: <input id="inputColor" type="color" value="#00bfff" /></label>
<label><input id="inputDebug" type="checkbox" /> Debug</label>
<button id="btnGenerate">Generate</button>
<button id="btnShare">Copy Share Link</button>
<span id="shareLink"></span>
</div>
<div id="canvas-container">
<canvas id="canvas" width="400" height="400" style="width:400px; height:400px;"></canvas>
</div>
<div id="debugInfo" style="display:none;"></div>
<script>
(() => {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const size = canvas.width; // 400x400 px
const blockPixelSize = 16; // each "block" as a 16x16 px square on canvas
const blocksPerRow = size / blockPixelSize; // 25 blocks max per axis
// Inputs
const inputX = document.getElementById('inputX');
const inputZ = document.getElementById('inputZ');
const inputRadius = document.getElementById('inputRadius');
const inputStartDeg = document.getElementById('inputStartDeg');
const inputEndDeg = document.getElementById('inputEndDeg');
const inputColor = document.getElementById('inputColor');
const inputDebug = document.getElementById('inputDebug');
const btnGenerate = document.getElementById('btnGenerate');
const btnShare = document.getElementById('btnShare');
const debugInfo = document.getElementById('debugInfo');
const shareLinkSpan = document.getElementById('shareLink');
// The Y coordinate is fixed as 0, since we generate a circle on X-Z plane.
// Convert degrees to radians helper
function degToRad(deg) {
return (deg * Math.PI) / 180;
}
// Normalize angle 0 - 360 degrees
function normalizeAngle(deg) {
let angle = deg % 360;
if (angle < 0) angle += 360;
return angle;
}
// Check if angle t (deg) is between start and end angles (deg), clockwise from start to end
function angleBetween(t, start, end) {
t = normalizeAngle(t);
start = normalizeAngle(start);
end = normalizeAngle(end);
if (start <= end) {
return t >= start && t <= end;
} else {
// Wrapped case, e.g., start=300, end=60
return t >= start || t <= end;
}
}
// Generate circle block coordinates
function generateCircleBlocks(cx, cz, radius, startDeg, endDeg) {
const blocks = [];
// We iterate over potential blocks in a bounding square box around center
// to find those on the circle perimeter within given segment
const r = radius;
const radiusTolerance = 0.5; // how close to radius to accept
// Bounding box:
const minX = Math.floor(cx - r - 1);
const maxX = Math.ceil(cx + r + 1);
const minZ = Math.floor(cz - r - 1);
const maxZ = Math.ceil(cz + r + 1);
for(let x = minX; x <= maxX; x++) {
for(let z = minZ; z <= maxZ; z++) {
// Compute dist from center to block center
const dx = x - cx;
const dz = z - cz;
const dist = Math.sqrt(dx*dx + dz*dz);
if (Math.abs(dist - r) <= radiusTolerance) {
// Compute angle of this block relative to center
// 0 deg is +X axis, positive CCW
let angleRad = Math.atan2(dz, dx);
let angleDeg = normalizeAngle(angleRad * 180 / Math.PI);
if(angleBetween(angleDeg, startDeg, endDeg)) {
blocks.push({x, z, angleDeg});
}
}
}
}
// Sort blocks by angle ascending (optional)
blocks.sort((a,b) => a.angleDeg - b.angleDeg);
return blocks;
}
// Draw blocks on canvas, centered
function drawBlocks(blocks, centerX, centerZ, color, debug) {
ctx.clearRect(0,0, canvas.width, canvas.height);
// Draw grid background
ctx.fillStyle = '#111';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Compute offset to center map on given center block
// We want the center block at (centerX, centerZ) to be at the center of canvas in block coords
const centerBlockCanvasX = Math.floor(blocksPerRow / 2);
const centerBlockCanvasZ = Math.floor(blocksPerRow / 2);
// For debug info text
let debugText = '';
blocks.forEach(({x,z,angleDeg}) => {
const dx = x - centerX;
const dz = z - centerZ;
const canvasX = centerBlockCanvasX + dx;
const canvasZ = centerBlockCanvasZ - dz; // invert Z to match canvas Y-axis direction (top=0)
if(canvasX < 0 || canvasZ < 0 || canvasX >= blocksPerRow || canvasZ >= blocksPerRow) return;
// Draw block rectangle
ctx.fillStyle = color;
ctx.fillRect(canvasX*blockPixelSize, canvasZ*blockPixelSize, blockPixelSize, blockPixelSize);
// Draw debug text if enabled
if(debug) {
ctx.fillStyle = '#eee';
ctx.font = '10px monospace';
ctx.fillText(`${x},${z}`, canvasX*blockPixelSize + 2, canvasZ*blockPixelSize + 12);
debugText += `Block: X=${x} Z=${z} Angle=${angleDeg.toFixed(1)}°\n`;
}
});
debugInfo.style.display = debug ? 'block' : 'none';
debugInfo.textContent = debugText;
}
// Read parameters from inputs and generate/draw circle
function generateAndDraw() {
const cx = parseInt(inputX.value);
const cz = parseInt(inputZ.value);
const radius = Math.max(1, Math.min(50, parseInt(inputRadius.value)));
let startDeg = parseFloat(inputStartDeg.value);
let endDeg = parseFloat(inputEndDeg.value);
const color = inputColor.value;
const debug = inputDebug.checked;
// Clamp angles between 0-360
startDeg = normalizeAngle(startDeg);
endDeg = normalizeAngle(endDeg);
// Special case: if start == end, treat as full circle
if(startDeg === endDeg) {
endDeg = (startDeg + 360) % 360;
}
const blocks = generateCircleBlocks(cx, cz, radius, startDeg, endDeg);
drawBlocks(blocks, cx, cz, color, debug);
}
// Encode parameters to URL hash
function updateHash() {
const params = new URLSearchParams();
params.set('x', inputX.value);
params.set('z', inputZ.value);
params.set('radius', inputRadius.value);
params.set('startdeg', inputStartDeg.value);
params.set('enddeg', inputEndDeg.value);
params.set('color', inputColor.value);
params.set('debug', inputDebug.checked ? '1' : '0');
const hashStr = '#/' + params.toString();
window.history.replaceState(null, '', hashStr);
shareLinkSpan.textContent = window.location.href;
}
// Load parameters from URL hash if present
function loadFromHash() {
if(window.location.hash.startsWith('#/')) {
const hashParams = new URLSearchParams(window.location.hash.slice(2));
if(hashParams.has('x')) inputX.value = hashParams.get('x');
if(hashParams.has('z')) inputZ.value = hashParams.get('z');
if(hashParams.has('radius')) inputRadius.value = hashParams.get('radius');
if(hashParams.has('startdeg')) inputStartDeg.value = hashParams.get('startdeg');
if(hashParams.has('enddeg')) inputEndDeg.value = hashParams.get('enddeg');
if(hashParams.has('color')) inputColor.value = hashParams.get('color');
if(hashParams.has('debug')) inputDebug.checked = hashParams.get('debug') === '1';
}
}
// Copy share link to clipboard
function copyShareLink() {
if(!shareLinkSpan.textContent) {
alert('No share link generated yet. Generate first.');
return;
}
navigator.clipboard.writeText(shareLinkSpan.textContent)
.then(() => alert('Share link copied to clipboard!'))
.catch(() => alert('Failed to copy link.'));
}
// Event Listeners
btnGenerate.addEventListener('click', () => {
generateAndDraw();
updateHash();
});
btnShare.addEventListener('click', copyShareLink);
// Auto-generate on input changes but debounce a bit
let inputTimeout;
['inputX','inputZ','inputRadius','inputStartDeg','inputEndDeg','inputColor','inputDebug'].forEach(id => {
const elem = document.getElementById(id);
elem.addEventListener('input', () => {
clearTimeout(inputTimeout);
inputTimeout = setTimeout(() => {
generateAndDraw();
updateHash();
}, 300);
});
});
// Init
loadFromHash();
generateAndDraw();
updateHash();
})();
</script>
</body>
</html>
If you want me to add or change features, or generate code for something else, just ask!