{"tool":"voxel.exec","input":{"code":"// MineBench: a choo-choo train. Steam loco, tender, three coaches, on a rolling\n// diorama with a station, telegraph line, trees and a smoke plume.\n// Track runs along X, nose points to +X. Rails at z=125 and z=131 (y=2).\n// Wheel centres y=7, radius 4. Boiler axis y=14, z=128.\n\nconst CZ = 128;\n\nfunction clamp(v, a, b) { return v < a ? a : (v > b ? b : v); }\n\n// Filled disc in the plane x = const. pick(d, dy, dz) returns a block type or null.\nfunction discX(x, cy, cz, r, pick) {\n  const R = Math.ceil(r);\n  for (let dy = -R; dy <= R; dy++) for (let dz = -R; dz <= R; dz++) {\n    const d = Math.sqrt(dy * dy + dz * dz);\n    if (d > r + 0.3) continue;\n    const t = pick(d, dy, dz);\n    if (t) block(x, cy + dy, cz + dz, t);\n  }\n}\n\n// Filled disc in the plane y = const. pick(d, dx, dz).\nfunction discY(y, cx, cz, r, pick) {\n  const R = Math.ceil(r);\n  for (let dx = -R; dx <= R; dx++) for (let dz = -R; dz <= R; dz++) {\n    const d = Math.sqrt(dx * dx + dz * dz);\n    if (d > r + 0.3) continue;\n    const t = pick(d, dx, dz);\n    if (t) block(cx + dx, y, cz + dz, t);\n  }\n}\n\n// Filled disc in the plane z = const (wheels). pick(d, dx, dy).\nfunction discZ(z, cx, cy, r, pick) {\n  const R = Math.ceil(r);\n  for (let dx = -R; dx <= R; dx++) for (let dy = -R; dy <= R; dy++) {\n    const d = Math.sqrt(dx * dx + dy * dy);\n    if (d > r + 0.3) continue;\n    const t = pick(d, dx, dy);\n    if (t) block(cx + dx, cy + dy, z, t);\n  }\n}\n\n// ---------- terrain ----------\nfunction inStation(x, z) { return x >= 96 && x <= 150 && z >= 102 && z <= 121; }\n\n// Ground top height. Flat around the track, hills rolling away from it.\nfunction groundTop(x, z) {\n  if (inStation(x, z)) return 0;\n  const d = Math.abs(z - CZ);\n  const s = clamp((d - 8) / 14, 0, 1);\n  const h = 0.5 + 0.25 * Math.sin(x * 0.09) + 0.25 * Math.cos(z * 0.13 + x * 0.03);\n  return Math.floor(9 * h * s);\n}\n\nfor (let x = 16; x <= 240; x++) {\n  for (let z = 72; z <= 184; z++) {\n    const top = groundTop(x, z);\n    if (inStation(x, z)) {\n      block(x, 0, z, 'cobblestone');\n      continue;\n    }\n    if (top === 0) {\n      block(x, 0, z, Math.abs(z - CZ) <= 5 ? 'stone' : 'grass_block');\n      continue;\n    }\n    for (let y = 0; y < top; y++) block(x, y, z, 'dirt');\n    block(x, top, z, 'grass_block');\n  }\n}\n\n// ---------- track ----------\nfor (let x = 24; x <= 232; x += 2) box(x, 1, 122, x, 1, 134, 'oak_planks');\nbox(24, 2, 125, 232, 2, 125, 'iron_block');\nbox(24, 2, 131, 232, 2, 131, 'iron_block');\n\n// ---------- station ----------\nbox(100, 1, 113, 136, 1, 118, 'stone_bricks');   // raised platform\n// house\nbox(104, 1, 104, 120, 6, 110, 'bricks');\nfor (let z = 104; z <= 110; z++) {\n  const top = 7 + Math.min(z - 104, 110 - z);\n  box(103, 7, z, 121, top, z, 'black_wool');\n}\nbox(104, 6, 104, 120, 6, 104, 'gold_block');     // fascia sign band\nbox(107, 3, 104, 108, 4, 104, 'glass');\nbox(112, 3, 104, 113, 4, 104, 'glass');\nbox(117, 3, 104, 118, 4, 104, 'glass');\nbox(108, 3, 110, 109, 4, 110, 'glass');\nbox(116, 3, 110, 117, 4, 110, 'glass');\nbox(112, 1, 110, 113, 3, 110, 'oak_planks');     // door\n// lamp posts along the platform edge\nfor (const lx of [104, 120, 136]) {\n  box(lx, 2, 113, lx, 5, 113, 'oak_log');\n  block(lx, 6, 113, 'glowstone');\n}\n// benches\nbox(104, 2, 117, 107, 2, 117, 'oak_planks');\nbox(124, 2, 117, 129, 2, 117, 'oak_planks');\n// waiting passengers\nfunction person(x, z, shirt) {\n  block(x, 2, z, 'black_wool');\n  block(x, 3, z, shirt);\n  block(x, 4, z, shirt);\n  block(x, 5, z, 'orange_wool');\n}\nperson(112, 115, 'red_wool');\nperson(116, 116, 'blue_wool');\nperson(124, 114, 'green_wool');\nperson(130, 116, 'red_wool');\n// water tower\nfor (const [lx, lz] of [[140, 104], [144, 104], [140, 110], [144, 110]]) box(lx, 1, lz, lx, 9, lz, 'oak_log');\ndiscY(10, 142, 107, 3, () => 'iron_block');\ndiscY(11, 142, 107, 3, () => 'iron_block');\ndiscY(12, 142, 107, 3, () => 'iron_block');\ndiscY(13, 142, 107, 3, () => 'iron_block');\ndiscY(14, 142, 107, 2, () => 'iron_block');\ndiscY(15, 142, 107, 1, () => 'iron_block');\n\n// ---------- trees ----------\nfunction tree(x, z, H) {\n  const y0 = groundTop(x, z) + 1;\n  const trunkTop = y0 + H;\n  for (let y = y0; y < trunkTop; y++) block(x, y, z, 'oak_log');\n  const cy = trunkTop + 1;\n  const R = 3.2 + rng() * 0.8;\n  const S = Math.ceil(R) + 1;\n  for (let dx = -S; dx <= S; dx++) for (let dy = -S; dy <= S; dy++) for (let dz = -S; dz <= S; dz++) {\n    if (dx * dx + dy * dy + dz * dz > R * R + (rng() - 0.5) * 2.5) continue;\n    if (dx === 0 && dz === 0 && cy + dy <= trunkTop) continue;\n    block(x + dx, cy + dy, z + dz, 'oak_leaves');\n  }\n}\ntree(40, 96, 6);\ntree(62, 88, 5);\ntree(84, 170, 7);\ntree(104, 178, 6);\ntree(170, 92, 5);\ntree(192, 172, 6);\ntree(214, 104, 7);\ntree(226, 160, 5);\ntree(28, 152, 6);\ntree(126, 178, 5);\ntree(150, 84, 6);\ntree(178, 150, 5);\n\n// ---------- telegraph line along z=141 ----------\nfor (let px = 24; px <= 232; px += 16) {\n  const y0 = groundTop(px, 141) + 1;\n  box(px, y0, 141, px, y0 + 6, 141, 'oak_log');\n  box(px, y0 + 5, 140, px, y0 + 5, 142, 'oak_planks');\n}\nfor (let px = 24; px < 232; px += 16) {\n  const ya = groundTop(px, 141) + 6;\n  const yb = groundTop(px + 16, 141) + 6;\n  line(px, ya, 141, px + 16, yb, 141, 'black_wool');\n}\n\n// ---------- the train ----------\n// one wheel: a disc of radius 4 centred at (cx, 7), two thick, at z = zA and zB\nfunction wheel(cx, zA, zB) {\n  for (const z of [zA, zB]) {\n    discZ(z, cx, 7, 4, (d, u, v) => {\n      if (d <= 1) return 'gold_block';\n      if (d >= 3.2) return 'iron_block';\n      if (u === 0 || v === 0) return 'red_wool';\n      return 'black_wool';\n    });\n  }\n}\nfunction axle(cx) {\n  wheel(cx, 124, 125);\n  wheel(cx, 131, 132);\n}\n\n// --- locomotive, x 172..218 ---\nbox(172, 5, 126, 216, 6, 130, 'gray_wool');              // chassis\nbox(172, 11, 120, 216, 11, 121, 'iron_block');           // side skirts\nbox(172, 11, 135, 216, 11, 136, 'iron_block');\n\n// cab\nbox(172, 9, 122, 185, 9, 134, 'gray_wool');              // footplate\nbox(172, 10, 122, 172, 21, 134, 'red_wool');             // back wall\nbox(185, 10, 122, 185, 21, 134, 'red_wool');             // front wall\nbox(173, 10, 122, 184, 21, 122, 'red_wool');             // left side\nbox(173, 10, 134, 184, 21, 134, 'red_wool');             // right side\nbox(175, 14, 122, 179, 18, 122, 'glass');\nbox(181, 14, 122, 184, 18, 122, 'glass');\nbox(175, 14, 134, 179, 18, 134, 'glass');\nbox(181, 14, 134, 184, 18, 134, 'glass');\nbox(170, 22, 120, 188, 22, 136, 'black_wool');            // roof\n\n// boiler, axis along x at y=14, z=128\nfor (let x = 186; x <= 216; x++) {\n  const band = x === 189 || x === 201 || x === 212;\n  discX(x, 14, CZ, x === 216 ? 5.2 : 6, (d, dy, dz) => {\n    if (x === 216) return d <= 2.5 ? 'iron_block' : 'black_wool';   // smokebox door\n    if (band) return 'iron_block';\n    if (dy >= 5) return 'gray_wool';                              // lit top\n    if (Math.abs(dz) >= 5 && Math.abs(dy) <= 1) return 'gold_block'; // pinstripe\n    return 'black_wool';\n  });\n}\n\n// steam dome, bell, chimney\ndiscY(20, 198, CZ, 2.6, () => 'gold_block');\ndiscY(21, 198, CZ, 2.0, () => 'gold_block');\ndiscY(22, 198, CZ, 1.2, () => 'gold_block');\nblock(198, 23, CZ, 'gold_block');\ndiscY(21, 204, CZ, 1, () => 'gold_block');\nblock(204, 22, CZ, 'gold_block');\nfor (let y = 20; y <= 26; y++) {\n  const r = y <= 22 ? 1.5 : (y <= 25 ? 2 : 2.6);\n  discY(y, 210, CZ, r, () => 'black_wool');\n}\ndiscY(27, 210, CZ, 3, () => 'iron_block');\n\n// cowcatcher: slatted wedge, low at the nose\nfor (let x = 210; x <= 216; x++) {\n  const top = 3 + Math.floor((216 - x) * 0.8);\n  for (let y = 3; y <= top; y++) for (let z = 122; z <= 134; z += 2) block(x, y, z, 'iron_block');\n}\nbox(216, 5, 125, 216, 7, 131, 'black_wool');              // buffer beam\n\n// headlamp\nbox(217, 13, 127, 217, 15, 129, 'gold_block');\nblock(217, 14, CZ, 'glowstone');\nblock(218, 14, CZ, 'glowstone');\n\n// driving wheels and rods\naxle(180); axle(189); axle(198); axle(207);\nbox(180, 7, 123, 207, 7, 123, 'iron_block');\nbox(180, 7, 133, 207, 7, 133, 'iron_block');\n\n// --- tender, x 148..168 ---\nbox(148, 5, 126, 168, 6, 130, 'gray_wool');\nbox(148, 8, 122, 168, 14, 134, 'black_wool');\nbox(148, 11, 121, 168, 11, 121, 'red_wool');\nbox(148, 11, 135, 168, 11, 135, 'red_wool');\nbox(148, 15, 122, 168, 15, 134, 'black_wool');\nbox(154, 16, 125, 162, 16, 131, 'black_wool');\nfor (let x = 148; x <= 168; x++) for (let z = 122; z <= 134; z++) {\n  if (rng() < 0.12) block(x, 15, z, 'gray_wool');\n}\naxle(153); axle(163);\n\n// coupler, loco to tender\nbox(169, 6, 127, 171, 6, 129, 'iron_block');\n\n// --- coaches ---\nfunction bellows(g0, g1) {\n  box(g0, 6, 127, g1, 6, 129, 'iron_block');             // coupler\n  box(g0, 8, 125, g1, 13, 131, 'black_wool');            // bellows\n}\nfunction coach(x0, x1, body) {\n  box(x0, 5, 126, x1, 6, 130, 'gray_wool');              // chassis\n  box(x0, 9, 122, x1, 15, 134, body);                    // body\n  for (let x = x0; x <= x1; x++) {\n    discX(x, 15, CZ, 6.5, (d, dy, dz) => {\n      if (dy < 0) return null;\n      if (Math.abs(dz) >= 6) return body;\n      return dy >= 3 ? 'white_wool' : body;              // white arched roof\n    });\n  }\n  box(x0, 14, 122, x1, 14, 122, 'gold_block');           // window-line trim\n  box(x0, 14, 134, x1, 14, 134, 'gold_block');\n  for (let wx = x0 + 3; wx + 2 <= x1 - 3; wx += 6) {\n    box(wx, 11, 122, wx + 2, 13, 122, 'glass');\n    box(wx, 11, 134, wx + 2, 13, 134, 'glass');\n  }\n  axle(x0 + 6);\n  axle(x1 - 6);\n}\ncoach(38, 72, 'blue_wool');\nbellows(73, 74);\ncoach(75, 109, 'green_wool');\nbellows(110, 111);\ncoach(112, 146, 'blue_wool');\nbellows(147, 147);\n\n// ---------- smoke plume from the chimney ----------\nfor (let i = 0; i < 12; i++) {\n  const ox = Math.round(210 - 2.6 * i - rng() * 2);\n  const oy = Math.round(30 + 1.5 * i + rng());\n  const oz = Math.round(CZ + (rng() - 0.5) * 2.5);\n  const r = 1.8 + 0.4 * i + rng();\n  const R = Math.ceil(r);\n  for (let dx = -R; dx <= R; dx++) for (let dy = -R; dy <= R; dy++) for (let dz = -R; dz <= R; dz++) {\n    if (dx * dx + dy * dy + dz * dz > r * r) continue;\n    block(ox + dx, oy + dy, oz + dz, i > 7 && rng() < 0.6 ? 'gray_wool' : 'white_wool');\n  }\n}\n","gridSize":256,"palette":"simple","seed":123}}
