{"tool":"voxel.exec","input":{"code":"// MineBench: \"a choo-choo train\"\n// Steam locomotive (black boiler, red cab, brass dome, flared stack, cowcatcher),\n// coal tender and two green coaches on rails, down a river valley with hills,\n// a water tower, a station house, trees, lamp posts and a plume of smoke.\n// Train runs along X (front = +X). Centreline z = 128. Rails at z = 125 and z = 130.\n// Block i spans [i, i+1); cc(i) is its centre.\n\nconst M = {\n  boiler: 'black_wool', cab: 'red_wool', roof: 'black_wool', trim: 'gold_block',\n  iron: 'iron_block', wood: 'oak_planks', glass: 'glass', glow: 'glowstone',\n  coach: 'green_wool', stripe: 'yellow_wool', seat: 'red_wool', tender: 'gray_wool',\n  tire: 'black_wool', spoke: 'red_wool', hub: 'gold_block', dirt: 'dirt', grass: 'grass_block',\n  stone: 'stone', sand: 'sand', water: 'water', brick: 'bricks', slate: 'stone_bricks',\n  log: 'oak_log', leaves: 'oak_leaves', ballast: 'cobblestone', tie: 'oak_planks',\n  smoke: 'white_wool', smoke2: 'gray_wool', coal: 'black_wool'\n};\n\nfunction put(x, y, z, t) {\n  x = Math.round(x); y = Math.round(y); z = Math.round(z);\n  if (x < 0 || y < 0 || z < 0 || x > 255 || y > 255 || z > 255) return;\n  block(x, y, z, t);\n}\nconst cc = (i) => i + 0.5; // centre of block i\n\n// Ragged ball. keep < 1 speckles it (leaves, smoke).\nfunction blob(cx, cy, cz, r, t, rough, keep) {\n  const R = Math.ceil(r) + 1;\n  for (let x = Math.floor(cx) - R; x <= Math.floor(cx) + R; x++)\n  for (let y = Math.floor(cy) - R; y <= Math.floor(cy) + R; y++)\n  for (let z = Math.floor(cz) - R; z <= Math.floor(cz) + R; z++) {\n    const d = Math.hypot(cc(x) - cx, cc(y) - cy, cc(z) - cz);\n    if (d > r * (1 + rough * (rng() - 0.5))) continue;\n    if (keep !== undefined && rng() > keep) continue;\n    put(x, y, z, t);\n  }\n}\n\n// Cylinder lying along X: axis at (y=yc, z=zc), blocks x0..x1.\n// taper > 0 rounds the last `taper` blocks into the smokebox front.\nfunction tubeX(x0, x1, yc, zc, r, t, taper) {\n  for (let x = x0; x <= x1; x++) {\n    let rr = r;\n    if (taper && x > x1 - taper) {\n      const k = (x - (x1 - taper)) / taper;\n      rr = r * Math.sqrt(Math.max(0.64, 1 - k * k));\n    }\n    for (let y = Math.floor(yc - r) - 1; y <= Math.ceil(yc + r); y++)\n    for (let z = Math.floor(zc - r) - 1; z <= Math.ceil(zc + r); z++)\n      if (Math.hypot(cc(y) - yc, cc(z) - zc) <= rr) put(x, y, z, t);\n  }\n}\n\n// Vertical cylinder: centre (xc, zc), blocks y0..y1. rin > 0 makes a hollow ring.\nfunction tubeY(xc, zc, y0, y1, r, t, rin) {\n  for (let y = y0; y <= y1; y++)\n  for (let x = Math.floor(xc - r) - 1; x <= Math.ceil(xc + r); x++)\n  for (let z = Math.floor(zc - r) - 1; z <= Math.ceil(zc + r); z++) {\n    const d = Math.hypot(cc(x) - xc, cc(z) - zc);\n    if (d <= r && d > (rin || 0)) put(x, y, z, t);\n  }\n}\n\n// Wheel: a disc in the XY plane (the axle runs across the track, along Z).\n// Black tyre, iron rim band, six red spokes, gold hub, open between spokes.\nfunction wheel(xc, yc, R, z1, z2) {\n  for (let x = Math.floor(xc - R) - 1; x <= Math.ceil(xc + R); x++)\n  for (let y = Math.floor(yc - R) - 1; y <= Math.ceil(yc + R); y++) {\n    const dx = cc(x) - xc, dy = cc(y) - yc, d = Math.hypot(dx, dy);\n    if (d > R) continue;\n    let t = null;\n    if (d > R - 1.2) t = M.tire;\n    else if (d > R - 2.4) t = M.iron;\n    else if (d < 1.3) t = M.hub;\n    else if (Math.abs(Math.sin(3 * Math.atan2(dy, dx))) * d / 3 < 0.55) t = M.spoke;\n    if (t) for (let z = z1; z <= z2; z++) put(x, y, z, t);\n  }\n}\n\n// ---- Landscape ---------------------------------------------------------------\nconst riverZ = (x) => 84 + 5 * Math.sin(x * 0.03);\n\n// Extra ground height above y=0 at column (x, z): hills rise toward the far edge.\nfunction hillTop(x, z) {\n  const back = Math.max(0, (96 - z) / 96);\n  const roll = 0.7 + 0.3 * Math.sin(x * 0.045 + 1.7) * Math.cos(z * 0.07);\n  return Math.round(18 * Math.pow(back, 1.3) * roll);\n}\n\nfunction terrain() {\n  for (let x = 0; x <= 255; x++)\n  for (let z = 0; z <= 255; z++) {\n    const river = Math.abs(z - riverZ(x));\n    let top = hillTop(x, z), cap = M.grass;\n    if (river < 3) { top = 0; cap = M.water; }      // river channel\n    else if (river < 5) { top = 0; cap = M.sand; }  // sandy banks\n    for (let y = 0; y <= top; y++)\n      put(x, y, z, y === top ? cap : (y >= top - 3 ? M.dirt : M.stone));\n  }\n}\n\n// Flowers scattered on the flat grass, kept off the track, station and river.\nfunction flowers() {\n  const kinds = [M.smoke, 'red_wool', 'yellow_wool', 'purple_wool'];\n  for (let x = 0; x <= 255; x++)\n  for (let z = 0; z <= 255; z++) {\n    if (hillTop(x, z) > 0 || Math.abs(z - riverZ(x)) < 6) continue;\n    if (z >= 116 && z <= 138) continue;\n    if (x >= 196 && z <= 120) continue;\n    if (rng() < 0.004) put(x, 1, z, kinds[Math.floor(rng() * kinds.length)]);\n  }\n}\n\n// Ballast bed, sleepers and two iron rails along the whole valley.\nfunction track() {\n  box(0, 1, 121, 255, 1, 134, M.ballast);\n  for (let x = 0; x <= 255; x += 2) box(x, 2, 122, x, 2, 133, M.tie);\n  line(0, 3, 125, 255, 3, 125, M.iron);\n  line(0, 3, 130, 255, 3, 130, M.iron);\n}\n\n// Station house behind the track: brick walls, slate roof, windows, door, gold sign.\nfunction station() {\n  const x0 = 200, x1 = 238, z0 = 106, z1 = 118;\n  for (let x = x0; x <= x1; x++)\n  for (let z = z0; z <= z1; z++) {\n    const edge = x === x0 || x === x1 || z === z0 || z === z1;\n    if (edge) {\n      for (let y = 1; y <= 6; y++) {\n        let t = M.brick;\n        if ((z === z0 || z === z1) && y >= 3 && y <= 4 && (x - x0) % 4 !== 0) t = M.glass;\n        if (z === z0 && x >= 218 && x <= 219 && y <= 3) t = M.wood;\n        put(x, y, z, t);\n      }\n    }\n    const pitch = Math.min(z - z0, z1 - z); // 0 at the eaves, 6 at the ridge\n    for (let y = 7; y <= 7 + pitch; y++) put(x, y, z, M.slate);\n  }\n  for (const x of [204, 232]) line(x, 1, 105, x, 5, 105, M.iron);\n  box(204, 6, 105, 232, 6, 105, M.trim);\n}\n\n// Water tower: four oak legs, iron-banded tank with water inside, domed cap.\nfunction waterTower() {\n  const cx = 92, cz = 108;\n  for (const [lx, lz] of [[89, 105], [94, 105], [89, 110], [94, 110]]) line(lx, 1, lz, lx, 14, lz, M.log);\n  for (let y = 15; y <= 20; y++)\n  for (let x = cx - 5; x <= cx + 4; x++)\n  for (let z = cz - 5; z <= cz + 4; z++) {\n    const d = Math.hypot(cc(x) - cx, cc(z) - cz);\n    if (d > 4) continue;\n    let t = d > 3 ? M.wood : M.water;\n    if (y === 15 || y === 20) t = M.iron;\n    put(x, y, z, t);\n  }\n  tubeY(cx, cz, 21, 21, 3.6, M.iron);\n  tubeY(cx, cz, 22, 22, 2.4, M.iron);\n  put(cx, 23, cz, M.trim);\n}\n\n// Lamp posts with glowstone heads, both sides of the track.\nfunction lamps() {\n  for (const x of [6, 30, 54, 78, 102, 126, 150, 174, 198, 222, 246])\n  for (const z of [120, 136]) {\n    line(x, 1, z, x, 9, z, M.iron);\n    put(x, 10, z, M.glow);\n  }\n}\n\n// Trees on the flat ground and up the hills, kept clear of track, river, tower, station.\nfunction trees() {\n  let placed = 0;\n  for (let tries = 0; placed < 26 && tries < 4000; tries++) {\n    const x = 4 + Math.floor(rng() * 248), z = Math.floor(rng() * 256);\n    if (z > 112 && z < 142) continue;\n    if (Math.abs(z - riverZ(x)) < 7) continue;\n    if (Math.abs(x - 92) < 9 && Math.abs(z - 108) < 9) continue;\n    if (x > 196 && z < 122) continue;\n    const base = hillTop(x, z) + 1;\n    const h = 5 + Math.floor(rng() * 3);\n    for (let y = base; y < base + h; y++) put(x, y, z, M.log);\n    blob(x + 0.5, base + h, z + 0.5, 2.8 + rng() * 1.2, M.leaves, 0.3, 0.9);\n    blob(x + 0.5 + (rng() - 0.5) * 2, base + h - 1.5, z + 0.5, 2.0 + rng(), M.leaves, 0.3, 0.9);\n    placed++;\n  }\n}\n\n// ---- Train -------------------------------------------------------------------\n\n// Passenger coach: green body, yellow waist stripe, glass windows, black arched roof.\nfunction coach(lo, hi) {\n  box(lo, 12, 123, hi, 12, 132, M.wood);                       // floor\n  for (let x = lo; x <= hi; x++) {\n    const i = x - lo;\n    const endCar = x === lo || x === hi;\n    for (let y = 12; y <= 21; y++) {\n      for (let z = 123; z <= 132; z++) {                         // end walls\n        if (endCar) put(x, y, z, (y >= 15 && y <= 19 && z >= 126 && z <= 129) ? M.glass : M.coach);\n      }\n      for (const z of [122, 133]) {                              // long sides\n        let t = y === 14 ? M.stripe : M.coach;\n        if (y >= 15 && y <= 19 && i % 4 !== 0) t = M.glass;\n        put(x, y, z, t);\n      }\n    }\n    for (let y = 22; y <= 27; y++)                               // arched roof\n      for (let z = 122; z <= 133; z++)\n        if (Math.hypot(cc(y) - 22, cc(z) - 128) <= 6) put(x, y, z, M.roof);\n    if (i % 6 === 3) put(x, 21, 128, M.glow);                    // ceiling lights\n  }\n  box(lo + 1, 13, 123, hi - 1, 13, 125, M.seat);                 // benches either side of the aisle\n  box(lo + 1, 14, 123, hi - 1, 15, 123, M.seat);\n  box(lo + 1, 13, 130, hi - 1, 13, 132, M.seat);\n  box(lo + 1, 14, 132, hi - 1, 15, 132, M.seat);\n  wheel(lo + 5, 8, 4, 124, 125); wheel(lo + 5, 8, 4, 130, 131);\n  wheel(hi - 5, 8, 4, 124, 125); wheel(hi - 5, 8, 4, 130, 131);\n  line(lo + 5, 8, 124, lo + 5, 8, 131, M.iron);\n  line(hi - 5, 8, 124, hi - 5, 8, 131, M.iron);\n}\n\n// Coal tender: grey tank with gold stripes and a heaped load of coal.\nfunction tender() {\n  box(117, 12, 123, 140, 19, 132, M.tender);\n  box(117, 15, 122, 140, 15, 122, M.trim);\n  box(117, 15, 133, 140, 15, 133, M.trim);\n  for (let x = 117; x <= 140; x++)\n  for (let z = 123; z <= 132; z++) {\n    const d = Math.hypot(x + 0.5 - 128.5, (z + 0.5 - 127.5) * 1.6);\n    if (d < 13) put(x, 20, z, M.coal);\n    if (d < 9 && rng() < 0.6) put(x, 21, z, M.coal);\n    if (d < 5 && rng() < 0.4) put(x, 22, z, M.coal);\n  }\n  wheel(122, 8, 4, 124, 125); wheel(122, 8, 4, 130, 131);\n  wheel(136, 8, 4, 124, 125); wheel(136, 8, 4, 130, 131);\n  line(122, 8, 124, 122, 8, 131, M.iron);\n  line(136, 8, 124, 136, 8, 131, M.iron);\n}\n\n// Steam locomotive: cab, boiler, dome, stack, headlamp, cowcatcher, running gear.\nfunction loco() {\n  box(144, 10, 122, 196, 11, 133, M.iron);                       // frame\n  wheel(148, 8, 4, 124, 125); wheel(148, 8, 4, 130, 131);        // trailing wheels\n  line(148, 8, 124, 148, 8, 131, M.iron);\n  for (const xc of [158, 170, 182]) {                            // driving wheels\n    wheel(xc, 10, 6, 124, 125); wheel(xc, 10, 6, 130, 131);\n    line(xc, 10, 124, xc, 10, 131, M.iron);\n  }\n  line(158, 9, 122, 182, 9, 122, M.iron);                        // side rods\n  line(158, 9, 133, 182, 9, 133, M.iron);\n  box(186, 9, 119, 196, 15, 121, M.iron);                        // cylinders\n  box(186, 9, 134, 196, 15, 136, M.iron);\n  box(144, 16, 120, 196, 16, 121, M.wood);                       // running boards either side\n  box(144, 16, 134, 196, 16, 135, M.wood);\n\n  tubeX(162, 195, 20, 128, 5, M.boiler, 3);                      // boiler barrel\n  for (const xr of [166, 178, 190]) tubeX(xr, xr, 20, 128, 5, M.iron); // hoops\n\n  tubeY(170, 128, 25, 25, 2.6, M.trim);                          // brass steam dome\n  tubeY(170, 128, 26, 26, 2.1, M.trim);\n  tubeY(170, 128, 27, 27, 1.4, M.trim);\n  put(170, 28, 128, M.trim);\n\n  const stack = [[24, 2.6, M.coal], [25, 2.2, M.coal], [26, 2.0, M.coal], [27, 2.0, M.coal],\n    [28, 1.7, M.coal], [29, 1.7, M.coal], [30, 1.7, M.coal], [31, 2.3, M.iron],\n    [32, 1.9, M.coal], [33, 2.3, M.iron]];\n  for (const [y, r, t] of stack) tubeY(188, 128, y, y, r, t, y === 33 ? 1.6 : 0);\n\n  for (let y = 18; y <= 21; y++)                                 // headlamp, gold bezel\n    for (let z = 126; z <= 129; z++)\n      put(196, y, z, (y >= 19 && y <= 20 && z >= 127 && z <= 128) ? M.glow : M.trim);\n\n  for (let x = 196; x <= 212; x++) {                             // cowcatcher: slatted wedge\n    const top = Math.floor(12 - (x - 196) * 7 / 16);\n    for (let y = 4; y <= top; y++)\n      for (const z of [123, 125, 127, 129, 131]) put(x, y, z, M.iron);\n  }\n  for (let y = 4; y <= 5; y++) for (let z = 123; z <= 132; z++) put(212, y, z, M.trim); // gold nose\n\n  for (let x = 144; x <= 161; x++)                               // cab shell\n  for (let y = 16; y <= 30; y++)\n  for (let z = 123; z <= 132; z++) {\n    const shell = x === 144 || x === 161 || z === 123 || z === 132 || y === 16 || y === 30;\n    if (!shell) continue;\n    let t = M.cab;\n    if ((z === 123 || z === 132) && y >= 21 && y <= 25 && (x - 144) % 4 !== 0) t = M.glass;\n    if ((x === 144 || x === 161) && y >= 21 && y <= 25 && z >= 126 && z <= 129) t = M.glass;\n    put(x, y, z, t);\n  }\n  box(143, 31, 122, 162, 31, 133, M.roof);                       // cab roof with overhang\n}\n\nfunction train() {\n  coach(43, 76);\n  line(77, 10, 128, 79, 10, 128, M.iron);\n  coach(80, 113);\n  line(114, 10, 128, 116, 10, 128, M.iron);\n  tender();\n  line(141, 10, 128, 143, 10, 128, M.iron);\n  loco();\n}\n\n// Smoke plume drifting back from the stack, and a wisp of steam from the dome.\nfunction smoke() {\n  for (let i = 0; i < 14; i++)\n    blob(188.5 - 2.4 * i + (rng() - 0.5) * 2, 35.5 + 1.6 * i + (rng() - 0.5),\n         128.5 + (rng() - 0.5) * 2.5, 1.8 + 0.35 * i,\n         i < 7 ? M.smoke : M.smoke2, 0.35, 0.9);\n  blob(170.5, 30, 128.5, 1.6, M.smoke, 0.3, 0.9);\n}\n\n// ---- Run ---------------------------------------------------------------------\nterrain();\nflowers();\ntrack();\nstation();\nwaterTower();\ntrees();\nlamps();\ntrain();\nsmoke();\n","gridSize":256,"palette":"simple","seed":123}}
