function hcyl(bottom, height, radius, id) { let radsq = radius * radius let innerRadsq =…
- User
function hcyl(bottom, height, radius, id) { let radsq = radius * radius let innerRadsq = (radius - 1.2) * (radius - 1.2) height += bottom for (let x = -radius; x <= radius; x++) { for (let y = bottom; y < height; y++) { for (let z = -radius; z <= radius; z++) { let d = x * x + z * z if (d < radsq && d >= innerRadsq) { world.setBlock(p2.x + x, p2.y + y, p2.z + z, id) } } } } }
function cyl(bottom, height, radius, id) { let radsq = radius * radius height += bottom for (let x = -radius; x <= radius; x++) { for (let y = bottom; y < height; y++) { for (let z = -radius; z <= radius; z++) { let d = x * x + z * z if (d < radsq) { world.setBlock(p2.x + x, p2.y + y, p2.z + z, id) } } } } }
function cube(bottom, height, radius, id) { let radsq = radius * radius height += bottom for (let x = -radius; x <= radius; x++) { for (let y = bottom; y < height; y++) { for (let z = -radius; z <= radius; z++) { let d = x + z if (d < radsq) { world.setBlock(p2.x + x, p2.y + y, p2.z + z, id) } } } } }
function sphereoid(w, h, d, id) { let w2 = w * w let h2 = h * h let d2 = d * d let w3 = (w - 1.5) * (w - 1.5) let h3 = (h - 1.5) * (h - 1.5) let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) { for (let x = -w; x <= w; x++) { for (let z = -d; z <= d; z++) { let n = x * x / w2 + y * y / h2 + z * z / d2 let n2 = x * x / w3 + y * y / h3 + z * z / d3 if (n < 1 && n2 >= 1) { world.setBlock(p2.x + x, p2.y + y, p2.z + z, id) } } } }}
function sleep(ms) { return new Promise(resolve => setTimeout(() => resolve(), ms)) }
async function asphereoid(w, h, d, id) { let px = p2.x let py = p2.y let pz = p2.z let w2 = w * w let h2 = h * h let d2 = d * d let w3 = (w - 1.5) * (w - 1.5) let h3 = (h - 1.5) * (h - 1.5) let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) { for (let x = -w; x <= w; x++) { for (let z = -d; z <= d; z++) { let n = x * x / w2 + y * y / h2 + z * z / d2 let n2 = x * x / w3 + y * y / h3 + z * z / d3 if (n < 1 && n2 >= 1) { world.setBlock(px + x, py + y, pz + z, id) await sleep(10) } } } }}
function line(x1, y1, z1, x2, y2, z2, id) { let dx = Math.abs(x2 - x1); let dy = Math.abs(y2 - y1); let dz = Math.abs(z2 - z1); let sx = (x1 < x2) ? 1 : -1; let sy = (y1 < y2) ? 1 : -1; let sz = (z1 < z2) ? 1 : -1; let err1 = dx - dy; let err2 = dx - dz; let err3 = dy - dz;
while (true) { world.setBlock(x1, y1, z1, id); if (x1 === x2 && y1 === y2 && z1 === z2) break; let e2 = 2 * err1; let e3 = 2 * err2; let e4 = 2 * err3; if (e2 > -dy) { err1 -= dy; err2 -= dz; x1 += sx; } if (e2 < dx) { err1 += dx; err3 -= dz; y1 += sy; } if (e3 > -dz) { err2 += dy; err3 += dx; z1 += sz; } }}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) { for (let x = 0; x < w; x++) { for (let y = 0; y < h; y++) { for (let z = 0; z < l; z++) { let block = world.getBlock(sx + x, sy + y, sz + z); world.setBlock(dx + x, dy + y, dz + z, block); } } } }
- Assistant
= 20;
function delay(ms) { return new Promise(resolve => setTimeout(() => resolve(), ms / fps)); }
(async function() { // Example usage:
// Draw a hollow cylinder (radius 10, height 20, with block ID 1) at the current position (p2) hcyl(0, 20, 10, 1);
// Wait for 2 seconds await delay(2000);
// Draw a solid cylinder (radius 10, height 20, with block ID 2) at the current position (p2) cyl(0, 20, 10, 2);
// Wait for 2 seconds await delay(2000);
// Draw a cube (height 20, radius 10, with block ID 3) at the current position (p2) cube(0, 20, 10, 3);
// Wait for 2 seconds await delay(2000);
// Draw a spheroid (width 10, height 20, depth 10, with block ID 4) at the current position (p2) sphereoid(10, 20, 10, 4);
// Animate drawing a spheroid (width 10, height 20, depth 10, with block ID 5) at the current position (p2) over 5 seconds await asphereoid(10, 20, 10, 5); })();