You want a Minecraft-style pixel art circle generator using HTML, CSS, and JS, that:
- Draws a circle in pixel art style (blocky pixels).
- Allows specifying color.
- Allows specifying start and end degree (like an arc segment).
- Has debug info showing x, z coords of the pixels.
- Has a share-able state via URL hash (#/...)
Got it.
Here's a complete example that meets your requirements:
Features:
- Canvas grid of blocks (e.g. 32x32).
- User inputs: startDeg, endDeg, color.
- Draw a circle (or arc) pixel by pixel.
- Debug mode: shows x,z coords on each pixel.
- URL hash saves params, updates on change.
<!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: #111;
color: #ddd;
font-family: monospace, monospace;
margin: 0; padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
#container {
position: relative;
width: 512px;
height: 512px;
background: #222;
}
canvas {
image-rendering: pixelated;
cursor: crosshair;
background: #222;
display: block;
}
.controls {
margin-bottom: 20px;
}
label {
margin-right: 10px;
}
input[type="number"] {
width: 60px;
}
input[type="color"] {
width: 50px;
height: 30px;
vertical-align: middle;
border: none;
cursor: pointer;
}
#debugToggle {
transform: scale(1.3);
vertical-align: middle;
}
#shareLink {
margin-top: 10px;
word-break: break-all;
user-select: all;
background: #222;
padding: 6px;
border: 1px solid #666;
}
</style>
</head>
<body>
<div class="controls">
<label>
Color:
<input type="color" id="color" value="#4CAF50" />
</label>
<label>
Start Deg:
<input type="number" id="startDeg" min="0" max="360" value="0" />
</label>
<label>
End Deg:
<input type="number" id="endDeg" min="0" max="360" value="360" />
</label>
<label>
Radius:
<input type="number" id="radius" min="1" max="16" value="15" />
</label>
<label title="Show pixel coordinates (x,z)">
Debug:
<input type="checkbox" id="debugToggle" />
</label>
</div>
<div id="container">
<canvas id="canvas" width="32" height="32"></canvas>
</div>
<div id="shareLink" title="Share URL will appear here"></div>
<script>
(() => {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const w = canvas.width;
const h = canvas.height;
// Pixel size in CSS pixels for display
const pixelSize = 16;
canvas.style.width = (w * pixelSize) + 'px';
canvas.style.height = (h * pixelSize) + 'px';
// Controls
const colorInput = document.getElementById('color');
const startDegInput = document.getElementById('startDeg');
const endDegInput = document.getElementById('endDeg');
const radiusInput = document.getElementById('radius');
const debugToggle = document.getElementById('debugToggle');
const shareLink = document.getElementById('shareLink');
// Circle center coords in the grid (x,z)
// We'll treat canvas coords as x horizontal, z vertical
const centerX = Math.floor(w / 2);
const centerZ = Math.floor(h / 2);
function degToRad(deg) {
return deg * Math.PI / 180;
}
function normalizeDegrees(d) {
d = d % 360;
if (d < 0) d += 360;
return d;
}
/**
* Check if angle is inside start-end arc.
* Handles wrap around 360.
*/
function angleInArc(angle, start, end) {
angle = normalizeDegrees(angle);
start = normalizeDegrees(start);
end = normalizeDegrees(end);
if (start <= end) {
return angle >= start && angle <= end;
} else {
return angle >= start || angle <= end;
}
}
/**
* Draw grid background for visibility
*/
function drawGrid() {
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "#111";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#333";
ctx.lineWidth = 0.05;
for(let i=0;i<=w;i++) {
ctx.beginPath();
ctx.moveTo(i, 0);
ctx.lineTo(i, h);
ctx.stroke();
}
for(let j=0;j<=h;j++) {
ctx.beginPath();
ctx.moveTo(0, j);
ctx.lineTo(w, j);
ctx.stroke();
}
}
/**
* Draw the pixelated arc/circle on the grid
* Using Midpoint Circle Algorithm approximation + start/end degrees to cut arc
* Block coloring + debug coords.
*/
function drawCircle() {
drawGrid();
let color = colorInput.value;
let startDeg = parseFloat(startDegInput.value);
let endDeg = parseFloat(endDegInput.value);
let r = parseInt(radiusInput.value);
let debug = debugToggle.checked;
// Draw circle pixels
// We'll loop over each pixel in the grid and decide if it lies on the circle border (approx)
// Because pixel circle, just check if distance from center is within a threshold
// Threshold defines the thickness of the circle line (in block units)
const thickness = 1.2;
ctx.font = "7px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
for(let x=0;x<w;x++) {
for(let z=0;z<h;z++) {
// convert to center relative coords with x horizontal, z vertical (like x,z coords)
let dx = x - centerX;
let dz = z - centerZ;
let dist = Math.sqrt(dx*dx + dz*dz);
// Calculate angle from center to this pixel.
// Angle in degrees: 0 deg points to +x (right),
// increasing CCW (typical unit circle)
let angle = Math.atan2(dz, dx) * 180 / Math.PI;
if (angle < 0) angle += 360;
// Check if distance is within circle band and angle is within arc segment
if (dist >= r - thickness/2 && dist <= r + thickness/2) {
if (angleInArc(angle, startDeg, endDeg)) {
// Draw the pixel block
ctx.fillStyle = color;
ctx.fillRect(x, z, 1, 1);
// Debug info for x,z coordinates on top of pixel
if (debug) {
ctx.fillStyle = "rgba(255,255,255,0.6)";
ctx.font = "6px monospace";
ctx.fillText(`${dx},${dz}`, x+0.5, z+0.5);
}
}
}
}
}
}
function updateURLHash() {
const params = {
c: colorInput.value.replace('#', ''),
s: startDegInput.value,
e: endDegInput.value,
r: radiusInput.value,
d: debugToggle.checked ? 1 : 0,
};
const hash = Object.entries(params)
.map(([k,v]) => `${k}=${encodeURIComponent(v)}`)
.join('&');
window.location.hash = `#/${hash}`;
shareLink.textContent = window.location.href;
}
function loadParamsFromHash() {
const h = window.location.hash;
if (!h.startsWith('#/')) return false;
const paramString = h.slice(2);
const params = new URLSearchParams(paramString);
const c = params.get('c');
if (c && /^([0-9a-fA-F]{6})$/.test(c)) {
colorInput.value = `#${c}`;
}
const s = params.get('s');
const e = params.get('e');
const r = params.get('r');
const d = params.get('d');
if (s !== null && !isNaN(parseFloat(s))) startDegInput.value = s;
if (e !== null && !isNaN(parseFloat(e))) endDegInput.value = e;
if (r !== null && !isNaN(parseInt(r))) radiusInput.value = r;
if (d !== null) debugToggle.checked = d === '1';
return true;
}
function onInputsChange() {
drawCircle();
updateURLHash();
}
// Init events
[colorInput, startDegInput, endDegInput, radiusInput].forEach(inp => {
inp.addEventListener('input', onInputsChange);
});
debugToggle.addEventListener('change', onInputsChange);
// Load parameters from URL hash if any
loadParamsFromHash();
drawCircle();
updateURLHash();
// Also handle manual hash changes (back button)
window.addEventListener('hashchange', () => {
if (loadParamsFromHash()) {
drawCircle();
updateURLHash();
}
});
})();
</script>
</body>
</html>
How to use
- Adjust color, start/end degrees, circle radius.
- Debug toggle shows coordinates in Minecraft x,z style around a center.
- The circle is drawn in pixel art style on a 32x32 grid.
- The URL hash updates automatically to save your settings.
- Share the URL with others to share your design.
Explanation:
- The coordinate center is at the middle of the 32x32 grid.
- Each pixel represents one Minecraft block.
x is horizontal (left-right), z is vertical (top-bottom).
- Arc is defined by start/end degrees, 0 deg to the right, CCW rotation.
- Debug mode overlays the relative coords on top of pixels.
- URL hash stores params (
# / c=color s=startDeg e=endDeg r=radius d=debug).
If you want me to extend, or add exporting coords for Minecraft command block building, just ask!