gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js minecraft circle generator width height pos debug
- User
html css js minecraft circle generator width height pos debug
- Assistant
html css js minecraft circle generator width height pos debug
Sure! Below is a simple Minecraft-style circle generator using HTML, CSS, and JavaScript. It lets you specify width, height, and position (x, y), and it draws a circle of "Minecraft blocks" on a canvas. There's also a debug mode to show the grid and position info.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Minecraft Circle Generator</title>
<style>
body {
font-family: monospace, monospace;
background: #222;
color: #eee;
margin: 0;
padding: 20px;
}
#controls {
margin-bottom: 10px;
}
label {
margin-right: 10px;
}
input[type=number] {
width: 60px;
background: #333;
border: 1px solid #555;
color: #eee;
padding: 4px 6px;
border-radius: 3px;
margin-right: 15px;
}
input[type=checkbox] {
transform: scale(1.2);
margin-left: 10px;
}
canvas {
background: #87CEEB; /* sky blue */
display: block;
margin-top: 15px;
border: 2px solid #444;
image-rendering: pixelated;
}
</style>
</head>
<body>
<div id="controls">
<label>Width: <input id="width" type="number" min="1" value="20" /></label>
<label>Height: <input id="height" type="number" min="1" value="20" /></label>
<label>Position X: <input id="posX" type="number" min="0" value="25" /></label>
<label>Position Y: <input id="posY" type="number" min="0" value="25" /></label>
<label>Block Size: <input id="blockSize" type="number" min="4" max="32" value="16" /></label>
<label>
<input type="checkbox" id="debug" />
Debug mode
</label>
<button id="generate">Generate</button>
</div>
<canvas id="canvas" width="800" height="600"></canvas>
<script>
(() => {
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const controls = {
width: document.getElementById("width"),
height: document.getElementById("height"),
posX: document.getElementById("posX"),
posY: document.getElementById("posY"),
blockSize: document.getElementById("blockSize"),
debug: document.getElementById("debug"),
generate: document.getElementById("generate"),
};
// Minecraft block colors for some variety (stone blocks)
// Just a simple palette to simulate blocks
const blockColors = [
"#777777", // stone gray
"#8B4513", // dirt brown
"#228B22", // grass green
"#C2B280", // sand
"#A0522D", // wood
"#5F9EA0", // prismarine-ish
];
// Draw single block at (gridX, gridY)
function drawBlock(gridX, gridY, blockSize, color) {
const px = gridX * blockSize;
const py = gridY * blockSize;
ctx.fillStyle = color;
ctx.fillRect(px, py, blockSize, blockSize);
// Draw block shading for 3D effect
const shadeColor = shadeColorHex(color, -20);
const lightColor = shadeColorHex(color, 20);
ctx.strokeStyle = shadeColor;
ctx.lineWidth = 1;
// Shadow (bottom + right)
ctx.beginPath();
ctx.moveTo(px + blockSize, py);
ctx.lineTo(px + blockSize, py + blockSize);
ctx.lineTo(px, py + blockSize);
ctx.stroke();
// Light (top + left)
ctx.strokeStyle = lightColor;
ctx.beginPath();
ctx.moveTo(px, py);
ctx.lineTo(px + blockSize, py);
ctx.lineTo(px + blockSize, py + blockSize);
ctx.stroke();
}
// Helper: shade a hex color (amount from -100 to +100)
// negative darkens, positive lightens
function shadeColorHex(color, amount) {
let col = color.replace(/^#/, "");
if (col.length === 3) {
col = col.split("").map(c => c+c).join("");
}
const num = parseInt(col, 16);
let r = (num >> 16) + amount;
let g = ((num >> 8) & 0x00ff) + amount;
let b = (num & 0x0000ff) + amount;
r = Math.min(255, Math.max(0, r));
g = Math.min(255, Math.max(0, g));
b = Math.min(255, Math.max(0, b));
return "#" + (r << 16 | g << 8 | b).toString(16).padStart(6, '0');
}
// Draw grid overlay for debug
function drawGrid(canvasWidth, canvasHeight, blockSize) {
ctx.strokeStyle = "#444";
ctx.lineWidth = 0.5;
for (let x = 0; x <= canvasWidth; x += blockSize) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, canvasHeight);
ctx.stroke();
}
for (let y = 0; y <= canvasHeight; y += blockSize) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(canvasWidth, y);
ctx.stroke();
}
}
// Draw coordinates on each block for debug
function drawCoords(gridX, gridY, blockSize, posX, posY) {
const px = gridX * blockSize;
const py = gridY * blockSize;
ctx.fillStyle = "rgba(255,255,255,0.7)";
ctx.font = `${Math.floor(blockSize/3)}px monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(`${posX},${posY}`, px + blockSize/2, py + blockSize/2);
}
// Determine if point is inside an ellipse (for circle)
function pointInEllipse(px, py, cx, cy, rx, ry) {
// Ellipse equation: ((x - cx)^2 / rx^2) + ((y - cy)^2 / ry^2) <= 1
return (((px - cx) * (px - cx)) / (rx * rx)) + (((py - cy) * (py - cy)) / (ry * ry)) <= 1;
}
function generateCircle() {
const wBlocks = parseInt(controls.width.value);
const hBlocks = parseInt(controls.height.value);
const posX = parseInt(controls.posX.value);
const posY = parseInt(controls.posY.value);
const blockSize = parseInt(controls.blockSize.value);
const debug = controls.debug.checked;
if (isNaN(wBlocks) || isNaN(hBlocks) || isNaN(posX) || isNaN(posY) || isNaN(blockSize)) {
alert("Please enter valid numbers");
return;
}
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Fill background (sky blue)
ctx.fillStyle = "#87CEEB";
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Optional grid for debug
if (debug) drawGrid(canvas.width, canvas.height, blockSize);
// Circle center and radii in blocks
const cx = posX;
const cy = posY;
const rx = wBlocks / 2;
const ry = hBlocks / 2;
// Draw the ellipse/circle with blocks
for (let y = 0; y < canvas.height / blockSize; y++) {
for (let x = 0; x < canvas.width / blockSize; x++) {
if (pointInEllipse(x + 0.5, y + 0.5, cx, cy, rx, ry)) {
// Pick random block color for variety
const color = blockColors[(x + y) % blockColors.length];
drawBlock(x, y, blockSize, color);
if (debug) {
drawCoords(x, y, blockSize, x, y);
}
}
}
}
// Draw circle outline in debug mode
if (debug) {
ctx.strokeStyle = "#FF0000";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.ellipse(
cx * blockSize,
cy * blockSize,
rx * blockSize,
ry * blockSize,
0,
0,
2 * Math.PI
);
ctx.stroke();
}
}
controls.generate.addEventListener("click", generateCircle);
// Initial generate on load
generateCircle();
})();
</script>
</body>
</html>
If you want me to add more Minecraft-specific textures or functionality (like different block types, exporting coordinates, or 3D preview), just ask!
Not yet included in a published release.