You want a Minecraft-style pixel circle generator using HTML/CSS/JS, supporting color, start/end degrees (arc), debug mode, and controls for coordinates (x, z), zoom, move, and sharing the settings via URL hash (like #/...).
Here is a complete implementation that meets these requirements:
Features:
Draws a pixelated circle or arc in a Minecraft block style (each pixel is a block).
Configurable:
Color (hex or named)
startdeg, enddeg (degrees from 0 to 360, defines an arc)
center coordinates (x, z)
zoom level (size of each block in pixels)
move (offset in pixels)
debug mode shows grid and coordinates
URL hash stores current parameters for sharing and reloading.
Responsive UI with inputs for all params.
Full code example:
html
<!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: #ddd;
font-family: monospace, monospace;
margin: 0; padding: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
background: #111;
padding: 10px 20px;
display: flex;
flex-wrap: wrap;
gap: 10px;
align-items: center;
}
label {
display: flex;
flex-direction: column;
font-size: 12px;
user-select: none;
}
input[type="number"], input[type="color"], input[type="text"] {
font-size: 16px;
width: 80px;
margin-top: 2px;
background: #333;
border: 1px solid #555;
color: #eee;
padding: 2px 4px;
border-radius: 2px;
}
input[type="checkbox"] {
margin-left: 4px;
}
#canvas-container {
flex-grow: 1;
display: flex;
justify-content: center;
align-items: center;
background: #333;
position: relative;
}
canvas {
background: #2a2a2a;
image-rendering: pixelated;
box-shadow: 0 0 10px #000 inset;
}
footer {
padding: 12px 20px;
background: #111;
font-size: 14px;
user-select: none;
}
#share-link {
width: 100%;
background: #222;
color: #ddd;
border: none;
padding: 6px 10px;
font-family: monospace;
font-size: 14px;
cursor: pointer;
border-radius: 3px;
}
#share-link:focus {
outline: 2px solid #58a;
}
@media (max-width: 600px) {
header {
flex-direction: column;
align-items: flex-start;
}
label input[type="number"], label input[type="color"], label input[type="text"] {
width: 100%;
}
}
</style>
</head>
<body>
<header>
<label>Color
<input type="color" id="color" value="#a52a2a" />
</label>
<label>Start Deg
<input type="number" id="startdeg" min="0" max="360" step="1" value="0" />
</label>
<label>End Deg
<input type="number" id="enddeg" min="0" max="360" step="1" value="360" />
</label>
<label>X (Center)
<input type="number" id="centerX" step="1" value="0" />
</label>
<label>Z (Center)
<input type="number" id="centerZ" step="1" value="0" />
</label>
<label>Zoom
<input type="number" id="zoom" min="1" max="40" step="1" value="8" />
</label>
<label>Move X
<input type="number" id="moveX" step="1" value="0" />
</label>
<label>Move Z
<input type="number" id="moveZ" step="1" value="0" />
</label>
<label>Debug
<input type="checkbox" id="debug" />
</label>
<button id="reset">Reset</button>
</header>
<div id="canvas-container">
<canvas id="canvas" width="600" height="600"></canvas>
</div>
<footer>
<input type="text" id="share-link" readonly title="Click to copy share link" />
</footer>
<script>
(() => {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Input elements
const colorInput = document.getElementById('color');
const startdegInput = document.getElementById('startdeg');
const enddegInput = document.getElementById('enddeg');
const centerXInput = document.getElementById('centerX');
const centerZInput = document.getElementById('centerZ');
const zoomInput = document.getElementById('zoom');
const moveXInput = document.getElementById('moveX');
const moveZInput = document.getElementById('moveZ');
const debugInput = document.getElementById('debug');
const resetBtn = document.getElementById('reset');
const shareLinkInput = document.getElementById('share-link');
// Settings object to hold current parameters
let settings = {
color: '#a52a2a',
startdeg: 0,
enddeg: 360,
centerX: 0,
centerZ: 0,
zoom: 8,
moveX: 0,
moveZ: 0,
debug: false,
};
// Parse degrees and fix range [0,360)
function normDeg(d) {
d = d % 360;
if (d < 0) d += 360;
return d;
}
// Check if an angle a is between start and end degrees on circle (degrees)
// Works correctly if start > end (wraps around)
function angleBetween(a, start, end) {
a = normDeg(a);
start = normDeg(start);
end = normDeg(end);
if (start <= end) {
return a >= start && a <= end;
} else {
return a >= start || a <= end;
}
}
// Convert degrees to radians
const deg2rad = Math.PI / 180;
// Draw the pixelated circle/arc
function draw() {
const {
color,
startdeg,
enddeg,
centerX,
centerZ,
zoom,
moveX,
moveZ,
debug,
} = settings;
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw grid and debug info if enabled
if (debug) {
drawGrid();
}
// Define circle radius in blocks (use a fixed radius - e.g. 30 blocks)
// Change radius if you want
const radiusBlocks = 30;
// Translate origin to center and add move offset (in pixels)
const originX = canvas.width / 2 + moveX;
const originY = canvas.height / 2 + moveZ;
// Pixels per block (=zoom input)
const block = zoom;
// Draw circle pixel blocks
// We'll iterate over a square bounding box around the circle, and fill pixels for points
// where distance to center is close to radius.
// For arcs, we'll calculate the angle of the point and only draw if between startdeg & enddeg
for (let x = centerX - radiusBlocks; x <= centerX + radiusBlocks; x++) {
for (let z = centerZ - radiusBlocks; z <= centerZ + radiusBlocks; z++) {
const dx = x - centerX;
const dz = z - centerZ;
const dist = Math.sqrt(dx * dx + dz * dz);
if (dist >= radiusBlocks - 0.5 && dist <= radiusBlocks + 0.5) {
// Calculate angle from center in degrees starting from +X going CCW
// Math.atan2 returns angle between -PI and PI in radians with y axis inverted
// Minecraft x,z plane corresponds to x,z with z "north-south".
// We'll consider angle 0 at positive X, increasing CCW (so up = 90 deg)
const angleRad = Math.atan2(dz, dx); // dz = y, dx = x
let angleDeg = angleRad * 180 / Math.PI;
if (angleDeg < 0) angleDeg += 360;
if (angleBetween(angleDeg, startdeg, enddeg)) {
// Draw block at pixel coords:
// x,z in blocks mapped to canvas coords
const px = originX + (x - centerX) * block;
const py = originY + (z - centerZ) * block;
// Draw filled rect representing one "block"
ctx.fillStyle = color;
ctx.fillRect(px, py, block, block);
if (debug) {
// Draw outlines for debugging
ctx.strokeStyle = '#555';
ctx.lineWidth = 1;
ctx.strokeRect(px, py, block, block);
// Draw coords text centered inside block (small font)
ctx.fillStyle = '#ccc';
ctx.font = `${Math.max(6, block / 3)}px monospace`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(`${x},${z}`, px + block / 2, py + block / 2);
}
}
}
}
}
if (debug) {
// Draw center crosshairs
ctx.strokeStyle = '#0f0';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(originX - 10, originY);
ctx.lineTo(originX + 10, originY);
ctx.moveTo(originX, originY - 10);
ctx.lineTo(originX, originY + 10);
ctx.stroke();
// Draw radius text
ctx.fillStyle = '#0f0';
ctx.font = '14px monospace';
ctx.fillText(`Radius: ${radiusBlocks}`, originX + 15, originY - 10);
ctx.fillText(`Center: (${centerX}, ${centerZ})`, originX + 15, originY + 15);
}
}
// Draw background grid for debugging
function drawGrid() {
const step = settings.zoom;
const width = canvas.width;
const height = canvas.height;
const ox = width / 2 + settings.moveX;
const oy = height / 2 + settings.moveZ;
ctx.strokeStyle = '#444';
ctx.lineWidth = 1;
// vertical grid lines
for (let x = ox % step; x < width; x += step) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, height);
ctx.stroke();
}
// horizontal grid lines
for (let y = oy % step; y < height; y += step) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
}
}
// Update settings from inputs
function updateSettingsFromInputs() {
settings.color = colorInput.value;
settings.startdeg = normDeg(Number(startdegInput.value));
settings.enddeg = normDeg(Number(enddegInput.value));
settings.centerX = Number(centerXInput.value);
settings.centerZ = Number(centerZInput.value);
settings.zoom = Math.max(1, Number(zoomInput.value));
settings.moveX = Number(moveXInput.value);
settings.moveZ = Number(moveZInput.value);
settings.debug = debugInput.checked;
}
// Update inputs from settings (for hash load)
function updateInputsFromSettings() {
colorInput.value = settings.color;
startdegInput.value = settings.startdeg;
enddegInput.value = settings.enddeg;
centerXInput.value = settings.centerX;
centerZInput.value = settings.centerZ;
zoomInput.value = settings.zoom;
moveXInput.value = settings.moveX;
moveZInput.value = settings.moveZ;
debugInput.checked = settings.debug;
}
// Encode settings to a compact URL hash (#/color/startdeg/enddeg/x/z/zoom/movex/movez/debug)
function updateHash() {
// We'll encode debug as 0 or 1
const dbg = settings.debug ? 1 : 0;
// Color hex without #, lowercase
const c = settings.color.replace('#', '').toLowerCase();
// Compose string
const parts = [
c,
settings.startdeg.toFixed(0),
settings.enddeg.toFixed(0),
settings.centerX.toFixed(0),
settings.centerZ.toFixed(0),
settings.zoom.toFixed(0),
settings.moveX.toFixed(0),
settings.moveZ.toFixed(0),
dbg
];
const hash = '#/' + parts.join('/');
history.replaceState(null, '', hash);
shareLinkInput.value = location.origin + location.pathname + hash;
}
// Parse settings from URL hash, returns true if success
// Format: #/color/startdeg/enddeg/x/z/zoom/movex/movez/debug
function parseHash() {
const hash = location.hash;
if (!hash.startsWith('#/')) return false;
const parts = hash.slice(2).split('/');
if (parts.length !== 9) return false;
let [
c,
startdeg,
enddeg,
x,
z,
zoom,
movex,
movez,
dbg
] = parts;
// Validate each part
// Color: hex 6 chars
if (!/^([0-9a-f]{6})$/i.test(c)) return false;
// parse nums
startdeg = Number(startdeg);
enddeg = Number(enddeg);
x = Number(x);
z = Number(z);
zoom = Number(zoom);
movex = Number(movex);
movez = Number(movez);
dbg = dbg === '1';
if (
isNaN(startdeg) || isNaN(enddeg) || isNaN(x) || isNaN(z) || isNaN(zoom) || isNaN(movex) || isNaN(movez)
) return false;
if (zoom < 1 || zoom > 100) return false;
settings.color = '#' + c;
settings.startdeg = normDeg(startdeg);
settings.enddeg = normDeg(enddeg);
settings.centerX = x;
settings.centerZ = z;
settings.zoom = zoom;
settings.moveX = movex;
settings.moveZ = movez;
settings.debug = dbg;
updateInputsFromSettings();
return true;
}
// Set all inputs change listeners
function setupListeners() {
const inputs = [
colorInput,
startdegInput,
enddegInput,
centerXInput,
centerZInput,
zoomInput,
moveXInput,
moveZInput,
debugInput
];
inputs.forEach(input => {
input.addEventListener('input', () => {
updateSettingsFromInputs();
draw();
updateHash();
});
});
// Reset button
resetBtn.addEventListener('click', () => {
settings = {
color: '#a52a2a',
startdeg: 0,
enddeg: 360,
centerX: 0,
centerZ: 0,
zoom: 8,
moveX: 0,
moveZ: 0,
debug: false,
};
updateInputsFromSettings();
draw();
updateHash();
});
// Share link copy on click
shareLinkInput.addEventListener('click', () => {
shareLinkInput.select();
document.execCommand('copy');
shareLinkInput.title = 'Copied!';
setTimeout(() => {
shareLinkInput.title = 'Click to copy share link';
}, 1000);
});
}
// Resize canvas to fit parent container dynamically
function resizeCanvas() {
const container = document.getElementById('canvas-container');
const rect = container.getBoundingClientRect();
// Set canvas size (limit max size maybe)
const size = Math.min(rect.width, rect.height);
canvas.width = size;
canvas.height = size;
draw();
}
// Initialize app
function init() {
if (!parseHash()) {
// no valid hash, load defaults
updateInputsFromSettings();
}
setupListeners();
resizeCanvas();
window.addEventListener('resize', () => {
resizeCanvas();
});
draw();
updateHash();
}
init();
})();
</script>
</body>
</html>
How to use
Open the page in any modern browser.
Use the controls on top to change the color, arc start/end degree, center coordinates, zoom (size of blocks), offset (moveX, moveZ), and enable debug to see grid with coordinates.
The canvas updates live.
A shareable URL link is generated in the footer that you can copy or share; it encodes all parameters.
Loading the page with that URL will restore the saved configuration.
Explanation
The circle is made of "blocks" arranged in Minecraft style (square pixels).
Radius is fixed at 30 blocks but can be changed easily in the code (radiusBlocks).
The "arc" draws pixels only if they lie within the angle range, handling wrap-around cases.
Zoom controls how many pixels wide each "block" is (default 8).
MoveX and MoveZ shifts the whole drawing on the canvas for visual adjustment.
Debug mode overlays a grid and labels each block with its (x,z) coordinate.
The share URL uses a simple hash encoding for reproducibility.
If you want me to extend this with downloading pixel data or exporting JSON for Minecraft blocks, just ask!