Sure! Here's a simple Minecraft pixel circle generator implemented in HTML/CSS/JS. It lets you specify:
- center (x, z)
- color (hex code)
- start angle (degrees)
- end angle (degrees)
- debug mode (showing coordinates)
- shareable URL with parameters encoded after
#
Features:
- Generates circle pixels as divs styled like Minecraft blocks in a grid
- Angles in degrees (0° at positive x-axis, increasing counterclockwise)
- Debug mode shows coordinates of each pixel in tooltips
- URL hash encodes settings for sharing and instant loading
How to use:
- Set parameters and click Generate
- Copy URL from address bar to share your circle config
- Reloading page with that URL auto-loads the circle
Full 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: sans-serif;
margin: 1rem;
background: #222;
color: #eee;
}
label {
display: inline-block;
margin: 0.5rem 1rem 0.5rem 0;
}
input[type="number"], input[type="color"], input[type="text"] {
font-size: 1rem;
padding: 0.2rem 0.5rem;
width: 80px;
}
button {
margin:0 1rem 1rem 0;
font-size: 1rem;
}
#circle {
display: inline-grid;
margin-top: 1rem;
background: #444;
grid-gap: 1px;
}
.pixel {
width: 15px;
height: 15px;
background-color: #ccc;
position: relative;
box-sizing: border-box;
}
.pixel.debug:hover::after {
content: attr(data-coord);
position: absolute;
top: -1.5em;
left: 50%;
transform: translateX(-50%);
background: rgba(0,0,0,0.7);
color: #fff;
font-size: 0.7rem;
padding: 1px 4px;
border-radius: 3px;
white-space: nowrap;
pointer-events: none;
z-index: 100;
}
.pixel.empty {
background: transparent;
}
.controls {
margin-bottom: 1rem;
}
</style>
</head>
<body>
<h1>Minecraft Pixel Circle Generator</h1>
<div class="controls">
<label>X: <input type="number" id="inputX" value="0" /></label>
<label>Z: <input type="number" id="inputZ" value="0" /></label>
<label>Color: <input type="color" id="inputColor" value="#3f51b5" /></label>
<label>Start Deg: <input type="number" id="inputStartDeg" value="0" min="0" max="359" /></label>
<label>End Deg: <input type="number" id="inputEndDeg" value="360" min="1" max="360" /></label>
<label>Debug: <input type="checkbox" id="inputDebug" /></label>
<button id="btnGenerate">Generate</button>
</div>
<div id="circle"></div>
<script>
(() => {
const inputX = document.getElementById('inputX');
const inputZ = document.getElementById('inputZ');
const inputColor = document.getElementById('inputColor');
const inputStartDeg = document.getElementById('inputStartDeg');
const inputEndDeg = document.getElementById('inputEndDeg');
const inputDebug = document.getElementById('inputDebug');
const btnGenerate = document.getElementById('btnGenerate');
const circleContainer = document.getElementById('circle');
// Generate circle pixels using Midpoint circle algorithm with angle filtering
function generateCirclePixels(centerX, centerZ, startDeg, endDeg) {
// Radius is fixed for demo (try 10)
const radius = 10;
const pixels = [];
// Normalize angles 0-360
startDeg = ((startDeg % 360) + 360) % 360;
endDeg = ((endDeg % 360) + 360) % 360;
function inAngleRange(angle) {
if (startDeg <= endDeg) {
return angle >= startDeg && angle <= endDeg;
} else {
return angle >= startDeg || angle <= endDeg;
}
}
// Midpoint Circle algo gets pixels in 1 octant
// We reflect points in all 8 octants
// Then filter points with angle range
// get angle of a pixel from center, with 0° at +x axis right side (like unit circle)
// atan2 returns radians from -pi to pi
function angleOf(x, z) {
let rad = Math.atan2(z - centerZ, x - centerX);
let deg = rad * 180 / Math.PI;
if (deg < 0) deg += 360;
return deg;
}
// Using a set to avoid duplicates
const uniquePixels = new Set();
let x = radius;
let z = 0;
let err = 0;
while (x >= z) {
const candidates = [
[centerX + x, centerZ + z],
[centerX + z, centerZ + x],
[centerX - z, centerZ + x],
[centerX - x, centerZ + z],
[centerX - x, centerZ - z],
[centerX - z, centerZ - x],
[centerX + z, centerZ - x],
[centerX + x, centerZ - z],
];
candidates.forEach(([px, pz]) => {
const ang = angleOf(px, pz);
if (inAngleRange(ang)) {
const key = px + ',' + pz;
if (!uniquePixels.has(key)) {
uniquePixels.add(key);
pixels.push({x: px, z: pz});
}
}
});
z += 1;
err += 1 + 2*z;
if (2*(err - x) + 1 > 0) {
x -= 1;
err += 1 - 2*x;
}
}
return pixels;
}
function renderCircle(pixels, centerX, centerZ, color, debug) {
if (!pixels.length) {
circleContainer.innerHTML = '<p>No pixels to display</p>';
return;
}
// Find bounding box around pixels for grid
let minX = Infinity, maxX = -Infinity, minZ = Infinity, maxZ = -Infinity;
pixels.forEach(({x, z}) => {
if (x < minX) minX = x;
if (x > maxX) maxX = x;
if (z < minZ) minZ = z;
if (z > maxZ) maxZ = z;
});
const width = maxX - minX + 1;
const height = maxZ - minZ + 1;
circleContainer.style.display = 'inline-grid';
circleContainer.style.gridTemplateColumns = `repeat(${width}, 15px)`;
circleContainer.style.gridTemplateRows = `repeat(${height}, 15px)`;
circleContainer.innerHTML = '';
// Create a map to quickly find if pixel exists for coordinates
const pixelSet = new Set(pixels.map(({x,z}) => (x + ',' + z)));
for(let zPos = minZ; zPos <= maxZ; zPos++) {
for(let xPos = minX; xPos <= maxX; xPos++) {
const key = xPos + ',' + zPos;
const pixelDiv = document.createElement('div');
pixelDiv.classList.add('pixel');
if(pixelSet.has(key)) {
pixelDiv.style.backgroundColor = color;
if (debug) {
pixelDiv.classList.add('debug');
pixelDiv.setAttribute('data-coord', `X:${xPos}, Z:${zPos}`);
}
} else {
pixelDiv.classList.add('empty');
}
circleContainer.appendChild(pixelDiv);
}
}
}
function updateFromHash() {
if(location.hash.length < 2) return false;
try {
// #/x,z,color,start,end,debug
// example: #/0,0,#3f51b5,0,360,1
const h = location.hash.substring(2);
const parts = h.split(',');
if(parts.length >= 6) {
inputX.value = parseInt(parts[0]) || 0;
inputZ.value = parseInt(parts[1]) || 0;
inputColor.value = parts[2] || '#3f51b5';
inputStartDeg.value = parseInt(parts[3]) || 0;
inputEndDeg.value = parseInt(parts[4]) || 360;
inputDebug.checked = parts[5] === '1' ? true : false;
return true;
}
} catch(e) {
console.log('Error parsing hash:', e);
}
return false;
}
function updateHash() {
const x = parseInt(inputX.value) || 0;
const z = parseInt(inputZ.value) || 0;
const color = inputColor.value || '#3f51b5';
const start = parseInt(inputStartDeg.value) || 0;
const end = parseInt(inputEndDeg.value) || 360;
const debug = inputDebug.checked ? '1' : '0';
const hash = `#/${x},${z},${color},${start},${end},${debug}`;
history.replaceState(null,null,hash);
}
function generate() {
const x = parseInt(inputX.value) || 0;
const z = parseInt(inputZ.value) || 0;
const color = inputColor.value || '#3f51b5';
let startDeg = parseInt(inputStartDeg.value) || 0;
let endDeg = parseInt(inputEndDeg.value) || 360;
const debug = inputDebug.checked;
// Clamp input degrees
if (startDeg < 0) startDeg = 0;
if (startDeg >= 360) startDeg = 0;
if (endDeg < 1) endDeg = 1;
if (endDeg > 360) endDeg = 360;
updateHash();
const pixels = generateCirclePixels(x, z, startDeg, endDeg);
renderCircle(pixels, x, z, color, debug);
}
btnGenerate.addEventListener('click', generate);
// Load from hash on start
if(!updateFromHash()){
generate(); // Default generate if no hash
} else {
generate();
}
// Optional: generate on Enter key press in any input
const inputs = [inputX, inputZ, inputColor, inputStartDeg, inputEndDeg, inputDebug];
inputs.forEach(input => {
input.addEventListener('keydown', e => {
if (e.key === 'Enter') generate();
});
});
})();
</script>
</body>
</html>
Explanation:
- The "circle" is drawn on a grid with 15px squares.
- Radius is fixed at 10 blocks, can be modified inside
generateCirclePixels if you want.
- The angle range is used to filter pixels by checking the pixel's angle around the center.
- The debug checkbox shows coordinates on hover.
- The hash URL preserves the parameters as
#/x,z,color,start,end,debug where debug = 1 or 0.
- You can share URLs like:
http://yourdomain/#/0,0,#ff0000,45,180,1
which draws a red semicircle in debug mode from 45° to 180° centered at (0,0).
If you want me to add radius input or other features, just ask!