You want a Minecraft pixel-style circle generator using HTML, CSS, and JS, where you can:
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 {
font-family: monospace, monospace;
background: #111;
color: #eee;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
padding: 1em;
}
#controls {
display: flex;
flex-wrap: wrap;
gap: 1em;
margin-bottom: 1em;
}
label {
display: flex;
flex-direction: column;
font-size: 0.9rem;
}
input[type="number"] {
width: 5em;
font-family: monospace;
font-size: 1em;
padding: 0.2em;
}
input[type="color"], input[type="text"] {
width: 6em;
height: 1.8em;
padding: 0;
border: none;
background: none;
cursor: pointer;
}
#canvas {
background: #222;
image-rendering: pixelated;
image-rendering: crisp-edges;
}
#debugToggle {
margin-left: auto;
align-self: center;
}
</style>
</head>
<body>
<h1>Minecraft Pixel Circle Generator</h1>
<div id="controls">
<label>
Color<br />
<input type="color" id="color" value="#00ccff" />
</label>
<label>
Radius<br />
<input type="number" id="radius" min="1" max="50" value="15" />
</label>
<label>
Start Degree<br />
<input type="number" id="startdeg" min="0" max="360" value="0" />
</label>
<label>
End Degree<br />
<input type="number" id="enddeg" min="0" max="360" value="360" />
</label>
<label>
Debug X,Z coords<br />
<input type="checkbox" id="debug" />
</label>
<button id="shareBtn">Copy Share Link</button>
</div>
<canvas id="canvas" width="320" height="320" style="width:320px; height:320px;"></canvas>
<script>
(() => {
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const colorInput = document.getElementById("color");
const radiusInput = document.getElementById("radius");
const startInput = document.getElementById("startdeg");
const endInput = document.getElementById("enddeg");
const debugInput = document.getElementById("debug");
const shareBtn = document.getElementById("shareBtn");
const pixelSize = 16;
const gridSize = 20; // to cover radius 15 comfortably
// canvas size based on grid
canvas.width = gridSize * pixelSize;
canvas.height = gridSize * pixelSize;
function degToRad(deg) {
return (deg * Math.PI) / 180;
}
// Helper: normalize angle to [0,360)
function normAngle(deg) {
let angle = deg % 360;
if (angle < 0) angle += 360;
return angle;
}
// Checks if angle b is between angles a1 and a2 clockwise
function angleInArc(angle, a1, a2) {
angle = normAngle(angle);
a1 = normAngle(a1);
a2 = normAngle(a2);
if (a1 === a2) return true; // full circle
if (a1 < a2) return angle >= a1 && angle <= a2;
// arc crosses 360
return angle >= a1 || angle <= a2;
}
// x,z in Minecraft coords: center at (0,0) in middle of canvas
const centerX = Math.floor(gridSize / 2);
const centerZ = Math.floor(gridSize / 2);
function drawCircle() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
const color = colorInput.value;
const radius = Math.max(1, Math.min(50, Number(radiusInput.value)));
let startDeg = Number(startInput.value);
let endDeg = Number(endInput.value);
startDeg = normAngle(startDeg);
endDeg = normAngle(endDeg);
// Draw background grid
ctx.strokeStyle = "#333";
ctx.lineWidth = 1;
for (let i = 0; i <= gridSize; i++) {
// vertical lines
ctx.beginPath();
ctx.moveTo(i * pixelSize, 0);
ctx.lineTo(i * pixelSize, gridSize * pixelSize);
ctx.stroke();
// horizontal lines
ctx.beginPath();
ctx.moveTo(0, i * pixelSize);
ctx.lineTo(gridSize * pixelSize, i * pixelSize);
ctx.stroke();
}
// Draw circle pixels
for (let x = 0; x < gridSize; x++) {
for (let z = 0; z < gridSize; z++) {
// Minecraft pixel coords relative to center
const relX = x - centerX;
const relZ = z - centerZ;
// Calculate distance from center for circle
// use circle equation: sqrt(x^2 + z^2)
let dist = Math.sqrt(relX * relX + relZ * relZ);
// Check arc angle for partial circle
// angle from center to pixel (0,0) is 0 deg angle axis+
// atan2(z,x) - careful with definitions: positive Z goes down canvas y?
// Minecraft x,z axis: x east/west, z north/south - for this canvas, z is vertical axis
// atan2 argument order: y,x
let angle = (Math.atan2(relZ, relX) * 180) / Math.PI; // degrees
angle = normAngle(angle);
// Decide if pixel should be filled
// Let's fill pixels that are within radius +-0.5 (to get pixel thickness)
// AND that are inside the angle arc from startDeg to endDeg
// We want a 1px thick ring, so test if dist between radius-0.5 and radius+0.5
if (
dist >= radius - 0.5 &&
dist <= radius + 0.5 &&
angleInArc(angle, startDeg, endDeg)
) {
// fill pixel
ctx.fillStyle = color;
ctx.fillRect(x * pixelSize, z * pixelSize, pixelSize, pixelSize);
// debug x,z coords on pixel
if (debugInput.checked) {
ctx.fillStyle = "#fff";
ctx.font = "9px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(
`${relX},${relZ}`,
x * pixelSize + pixelSize / 2,
z * pixelSize + pixelSize / 2
);
}
}
}
}
}
// Update from URL hash: "#/color/startdeg/enddeg/radius/debug/"
function loadFromHash() {
let h = location.hash.slice(2); // remove "#/"
if (!h) return false;
const parts = h.split("/");
if (parts.length < 4) return false;
const [color, startDeg, endDeg, radius, debug] = parts;
// validate inputs:
if (/^#([0-9a-fA-F]{6})$/.test(color)) colorInput.value = color;
let s = Number(startDeg);
if (!isNaN(s) && s >= 0 && s <= 360) startInput.value = s;
let e = Number(endDeg);
if (!isNaN(e) && e >= 0 && e <= 360) endInput.value = e;
let r = Number(radius);
if (!isNaN(r) && r >= 1 && r <= 50) radiusInput.value = r;
debugInput.checked = debug === "1";
return true;
}
// Save state to URL hash
function saveToHash() {
const vals = [
colorInput.value,
startInput.value,
endInput.value,
radiusInput.value,
debugInput.checked ? "1" : "0",
];
location.hash = "#/" + vals.join("/");
}
// Initialize UI listeners
function init() {
// load from hash at start
loadFromHash();
drawCircle();
[colorInput, radiusInput, startInput, endInput, debugInput].forEach((el) =>
el.addEventListener("input", () => {
drawCircle();
saveToHash();
})
);
shareBtn.addEventListener("click", () => {
navigator.clipboard
.writeText(location.href)
.then(() => alert("Share link copied!"))
.catch(() => alert("Failed to copy share link."));
});
window.addEventListener("hashchange", () => {
if (loadFromHash()) drawCircle();
});
}
init();
})();
</script>
</body>
</html>