{"tool":"voxel.exec","input":{"code":"// MineBench: steam choo-choo on a track through a meadow.\n// Steam loco (bullet nose, cab, gold bands, dome, chimney, headlamp), tender, three passenger cars\n// with glazed windows and lit interiors, a station with canopy and waiting passengers, a water tower,\n// telegraph poles, trees, flowers, a hill and a smoke trail. Track runs along x at z=128.\n\n// Every voxel goes into V first so later parts can overwrite or carve earlier ones.\n// block() is called once per surviving voxel at the very end.\nvar V = {};\nfunction put(x, y, z, t) {\n  if (x < 0 || y < 0 || z < 0 || x > 255 || y > 255 || z > 255) return;\n  V[x + ',' + y + ',' + z] = t;\n}\nfunction del(x, y, z) { delete V[x + ',' + y + ',' + z]; }\nfunction fill(x1, y1, z1, x2, y2, z2, t) {\n  for (var x = x1; x <= x2; x++)\n    for (var y = y1; y <= y2; y++)\n      for (var z = z1; z <= z2; z++) put(x, y, z, t);\n}\nfunction carve(x1, y1, z1, x2, y2, z2) {\n  for (var x = x1; x <= x2; x++)\n    for (var y = y1; y <= y2; y++)\n      for (var z = z1; z <= z2; z++) del(x, y, z);\n}\n// deterministic 0..1 noise per voxel, so every run builds the same thing\nfunction hash(x, y, z) {\n  var h = Math.sin(x * 127.1 + y * 311.7 + z * 74.7) * 43758.5453;\n  return h - Math.floor(h);\n}\n\n// ---------- terrain ----------\nvar GX1 = 4, GX2 = 251, GZ1 = 84, GZ2 = 172;\nfunction groundH(x, z) {\n  var a = (x - 60) / 38, b = (z - 172) / 16;     // big hill at the back edge\n  var c = (x - 225) / 20, d = (z - 90) / 10;     // small knoll to the south-east\n  return 2 + Math.round(14 * Math.exp(-(a * a + b * b)) + 8 * Math.exp(-(c * c + d * d)));\n}\nfor (var gx = GX1; gx <= GX2; gx++) {\n  for (var gz = GZ1; gz <= GZ2; gz++) {\n    var h = groundH(gx, gz);\n    fill(gx, 0, gz, gx, h - 2, gz, 'stone');\n    put(gx, h - 1, gz, 'dirt');\n    put(gx, h, gz, 'grass_block');\n  }\n}\n\n// wildflowers in the meadow, kept clear of the track verge and the station\nvar FLOWERS = ['red_wool', 'yellow_wool', 'white_wool', 'orange_wool', 'purple_wool'];\nfor (var fx = GX1 + 2; fx <= GX2 - 2; fx++) {\n  for (var fz = GZ1 + 2; fz <= GZ2 - 2; fz++) {\n    if (fz > 110 && fz < 154) continue;\n    if (hash(fx, 7, fz) > 0.985) {\n      put(fx, groundH(fx, fz) + 1, fz, FLOWERS[Math.floor(hash(fz, 9, fx) * FLOWERS.length)]);\n    }\n  }\n}\n\n// ---------- track ----------\nfill(6, 3, 119, 249, 3, 134, 'cobblestone');              // ballast\nfor (var tx = 6; tx <= 249; tx += 2) fill(tx, 4, 121, tx, 4, 134, 'oak_planks'); // sleepers\nfill(6, 5, 124, 249, 5, 124, 'iron_block');                // rails\nfill(6, 5, 132, 249, 5, 132, 'iron_block');\n\n// telegraph poles with crossarms and two wires\nfor (var px = 14; px <= 222; px += 26) {\n  fill(px, 3, 117, px, 13, 117, 'oak_log');\n  fill(px, 12, 115, px, 12, 119, 'oak_planks');\n  fill(px, 13, 115, px + 26, 13, 115, 'iron_block');\n  fill(px, 13, 119, px + 26, 13, 119, 'iron_block');\n}\n\n// ---------- trees ----------\nfunction leaf(x, y, z) {\n  if (V[x + ',' + y + ',' + z] !== 'oak_log') put(x, y, z, 'oak_leaves');\n}\nfunction tree(x, z, trunkH, R, seed) {\n  var base = groundH(x, z);\n  for (var y = base + 1; y <= base + trunkH; y++) put(x, y, z, 'oak_log');\n  var cy = base + trunkH + 1;\n  for (var dx = -R - 1; dx <= R + 1; dx++)\n    for (var dy = -R; dy <= R; dy++)\n      for (var dz = -R - 1; dz <= R + 1; dz++) {\n        var reach = R + (hash(x + dx, cy + dy, z + dz + seed) - 0.5) * 1.6;   // lumpy, not a clean ball\n        if (dx * dx + dy * dy * 1.15 + dz * dz <= reach * reach) leaf(x + dx, cy + dy, z + dz);\n      }\n}\nvar TREES = [\n  [24, 100, 6, 4], [40, 108, 5, 3], [18, 150, 6, 4], [52, 146, 7, 4], [72, 96, 5, 3],\n  [96, 104, 6, 4], [120, 94, 5, 3], [30, 160, 6, 4], [88, 156, 5, 3], [108, 146, 6, 4],\n  [236, 108, 6, 4], [228, 94, 5, 3], [160, 96, 6, 4], [186, 92, 5, 3], [136, 100, 6, 4],\n  [12, 88, 5, 3], [202, 90, 6, 4]\n];\nfor (var ti = 0; ti < TREES.length; ti++) {\n  tree(TREES[ti][0], TREES[ti][1], TREES[ti][2], TREES[ti][3], ti * 17);\n}\n\n// ---------- station ----------\n// platform: stone brick plinth, gold safety line on the track edge\nfill(150, 3, 135, 200, 9, 140, 'stone_bricks');\nfill(150, 10, 135, 200, 10, 140, 'stone_bricks');\nfill(150, 10, 135, 200, 10, 135, 'gold_block');\n// canopy on oak posts, glowstone lanterns underneath\nvar POSTS = [152, 168, 184, 198];\nfor (var pi = 0; pi < POSTS.length; pi++) {\n  fill(POSTS[pi], 11, 136, POSTS[pi], 16, 136, 'oak_log');\n  fill(POSTS[pi], 11, 139, POSTS[pi], 16, 139, 'oak_log');\n}\nfill(150, 17, 135, 200, 17, 141, 'oak_planks');\nput(160, 16, 137, 'glowstone');\nput(176, 16, 137, 'glowstone');\nput(192, 16, 137, 'glowstone');\n// two waiting passengers\nfunction person(x, z, coat) {\n  fill(x, 11, z, x, 12, z, 'black_wool');\n  fill(x, 13, z, x, 14, z, coat);\n  put(x, 15, z, 'orange_wool');\n  put(x, 16, z, 'brown_wool');\n}\nperson(162, 138, 'purple_wool');\nperson(179, 137, 'blue_wool');\n\n// station house behind the platform: brick walls, gable roof, windows and a plank door\nfill(156, 3, 143, 190, 16, 151, 'bricks');\nfor (var rz = 143; rz <= 151; rz++) {\n  fill(155, 17, rz, 191, 17 + Math.min(rz - 143, 151 - rz), rz, 'gray_wool');\n}\nfor (var wx = 156; wx <= 190; wx++) {\n  for (var wy = 9; wy <= 13; wy++) {\n    if ((wx - 156) % 5 === 2 || (wx - 156) % 5 === 3) put(wx, wy, 143, 'glass');\n  }\n}\nfill(172, 3, 143, 173, 6, 143, 'oak_planks');\n\n// water tower: four oak legs, plank tank with iron bands and a cone roof\nfor (var li = 0; li < 4; li++) {\n  var lx = li < 2 ? 216 : 224, lz = li % 2 ? 150 : 158;\n  fill(lx, 3, lz, lx, 14, lz, 'oak_log');\n}\nfor (var ty = 15; ty <= 22; ty++)\n  for (var tx2 = 214; tx2 <= 226; tx2++)\n    for (var tz2 = 148; tz2 <= 160; tz2++) {\n      var td = (tx2 - 220) * (tx2 - 220) + (tz2 - 154) * (tz2 - 154);\n      if (td <= 16.5 && td > 6) put(tx2, ty, tz2, ty === 17 || ty === 21 ? 'iron_block' : 'oak_planks');\n    }\nfor (var cy2 = 23; cy2 <= 26; cy2++) {\n  var rr = 4.5 - (cy2 - 23) * 1.1;\n  for (var cx2 = 214; cx2 <= 226; cx2++)\n    for (var cz2 = 148; cz2 <= 160; cz2++)\n      if ((cx2 - 220) * (cx2 - 220) + (cz2 - 154) * (cz2 - 154) <= rr * rr) put(cx2, cy2, cz2, 'gray_wool');\n}\n\n// ---------- wheels, shared by loco, tender and cars ----------\n// A wheel is a disc in the XY plane: iron tyre, coloured face, gold hub, axle through it.\n// Left pair sits at z 123-124, right pair at z 132-133, straddling the rails at z=124 and z=132.\nfunction wheelPair(xc, yc, r, face) {\n  for (var wx = xc - r; wx <= xc + r; wx++)\n    for (var wy = yc - r; wy <= yc + r; wy++) {\n      var d2 = (wx - xc) * (wx - xc) + (wy - yc) * (wy - yc);\n      if (d2 > r * r + 0.5) continue;\n      var t = d2 > (r - 1) * (r - 1) ? 'iron_block' : face;\n      put(wx, wy, 123, t); put(wx, wy, 124, t);\n      put(wx, wy, 132, t); put(wx, wy, 133, t);\n    }\n  fill(xc, yc, 124, xc, yc, 132, 'iron_block');\n  put(xc, yc, 123, 'gold_block');\n  put(xc, yc, 133, 'gold_block');\n}\n\n// ---------- locomotive (x 167..211, nose at 211) ----------\nfunction boilerR(x) {                  // round boiler; bullet-shaped nose at the front\n  if (x <= 204) return 5;\n  var t = (x - 204) / 8;\n  return 5 * Math.sqrt(Math.max(0, 1 - t * t));\n}\n// frame, drivers, connecting rod, pony truck\nfill(167, 8, 126, 211, 10, 130, 'black_wool');\nwheelPair(176, 10, 4, 'red_wool');\nwheelPair(186, 10, 4, 'red_wool');\nwheelPair(196, 10, 4, 'red_wool');\nwheelPair(207, 8, 2, 'black_wool');\nfill(176, 10, 122, 196, 10, 122, 'iron_block');      // connecting rod\n// cowcatcher: iron bars sloping up toward the back\nfor (var fx2 = 206; fx2 <= 211; fx2++)\n  for (var fy = 6; fy <= 8; fy++)\n    if (fy - 6 <= (211 - fx2) / 3) fill(fx2, fy, 126, fx2, fy, 130, 'iron_block');\n// boiler: black, gold bands (shell only), round nose\nfor (var bx = 181; bx <= 211; bx++) {\n  var br = boilerR(bx);\n  var band = (bx >= 190 && bx <= 191) || (bx >= 200 && bx <= 201);\n  for (var by = 12; by <= 22; by++)\n    for (var bz = 123; bz <= 133; bz++) {\n      var bdy = by - 17, bdz = bz - 128;\n      var bd2 = bdy * bdy + bdz * bdz;\n      if (bd2 <= br * br + 0.5) {\n        put(bx, by, bz, band && bd2 > (br - 1.5) * (br - 1.5) ? 'gold_block' : 'black_wool');\n      }\n    }\n}\nput(211, 17, 128, 'glowstone');                    // headlamp\n// steam dome, bell, chimney with flared top and gold cap\nfor (var sx = 185; sx <= 189; sx++)\n  for (var sz = 126; sz <= 130; sz++) {\n    var sd = (sx - 187) * (sx - 187) + (sz - 128) * (sz - 128);\n    if (sd <= 2.5) put(sx, 21, sz, 'gold_block');\n    if (sd <= 1.5) put(sx, 22, sz, 'gold_block');\n    if (sd <= 0.5) put(sx, 23, sz, 'gold_block');\n  }\nput(196, 23, 128, 'gold_block');\nfor (var kx = 200; kx <= 204; kx++)\n  for (var kz = 126; kz <= 130; kz++) {\n    var kd = (kx - 202) * (kx - 202) + (kz - 128) * (kz - 128);\n    if (kd <= 2.5) for (var ky = 21; ky <= 28; ky++) put(kx, ky, kz, 'black_wool');\n    if (kd <= 5) { put(kx, 29, kz, 'black_wool'); put(kx, 30, kz, 'black_wool'); }\n    if (kd <= 5) put(kx, 31, kz, 'gold_block');\n  }\n// cab: red shell, hollow interior, glass in the sides and rear, gray roof, black floor\nfill(167, 11, 125, 180, 24, 131, 'red_wool');\ncarve(168, 12, 126, 179, 23, 130);\nfill(168, 11, 126, 179, 11, 130, 'black_wool');\nfor (var cwx = 168; cwx <= 179; cwx++)\n  for (var cwy = 16; cwy <= 20; cwy++)\n    if ((cwx - 167) % 4 !== 0) { put(cwx, cwy, 125, 'glass'); put(cwx, cwy, 131, 'glass'); }\nfill(167, 16, 127, 167, 20, 129, 'glass');\nfill(166, 25, 124, 181, 25, 132, 'gray_wool');\n\n// ---------- tender (x 147..163) ----------\nfill(147, 8, 126, 163, 10, 130, 'black_wool');\nfill(147, 11, 125, 163, 19, 131, 'black_wool');\nfill(147, 15, 125, 163, 15, 125, 'gold_block');     // gold stripes on both sides\nfill(147, 15, 131, 163, 15, 131, 'gold_block');\nfill(148, 20, 126, 162, 21, 130, 'black_wool');     // coal load\nfor (var cl = 148; cl <= 162; cl++)\n  for (var cm = 126; cm <= 130; cm++)\n    if (hash(cl, 21, cm) > 0.55) put(cl, 21, cm, 'cobblestone');\nwheelPair(151, 9, 3, 'black_wool');\nwheelPair(159, 9, 3, 'black_wool');\n\n// ---------- passenger cars ----------\nfunction car(x0) {\n  var x1 = x0 + 31;\n  fill(x0, 8, 126, x1, 10, 130, 'black_wool');          // underframe\n  wheelPair(x0 + 6, 9, 3, 'black_wool');\n  wheelPair(x1 - 6, 9, 3, 'black_wool');\n  fill(x0, 11, 124, x1, 19, 132, 'red_wool');           // body\n  for (var rx = x0; rx <= x1; rx++)                     // arched roof, round across the car\n    for (var rz = 124; rz <= 132; rz++) {\n      var rh = Math.round(4 * Math.sqrt(Math.max(0, 1 - Math.pow((rz - 128) / 4.6, 2))));\n      fill(rx, 20, rz, rx, 19 + rh, rz, 'gray_wool');\n    }\n  carve(x0 + 1, 12, 125, x1 - 1, 19, 131);              // hollow interior\n  fill(x0 + 1, 11, 125, x1 - 1, 11, 131, 'oak_planks'); // wooden floor\n  for (var wx2 = x0 + 2; wx2 <= x1 - 2; wx2++) {        // glazed windows, 2 of every 4 blocks\n    var k = (wx2 - x0) % 4;\n    if (k === 1 || k === 2) {\n      for (var wy2 = 14; wy2 <= 17; wy2++) { put(wx2, wy2, 124, 'glass'); put(wx2, wy2, 132, 'glass'); }\n    }\n  }\n  fill(x0, 18, 124, x1, 18, 124, 'gold_block');         // gold window band\n  fill(x0, 18, 132, x1, 18, 132, 'gold_block');\n  fill(x0 + 14, 12, 124, x0 + 15, 15, 124, 'oak_planks'); // side doors\n  fill(x0 + 14, 12, 132, x0 + 15, 15, 132, 'oak_planks');\n  fill(x0 + 2, 12, 126, x1 - 2, 12, 126, 'oak_planks');   // benches, backs to the walls\n  fill(x0 + 2, 13, 125, x1 - 2, 14, 125, 'oak_planks');\n  fill(x0 + 2, 12, 130, x1 - 2, 12, 130, 'oak_planks');\n  fill(x0 + 2, 13, 131, x1 - 2, 14, 131, 'oak_planks');\n  var LAMPS = [x0 + 6, x0 + 16, x0 + 26];\n  for (var lp = 0; lp < LAMPS.length; lp++) put(LAMPS[lp], 19, 128, 'glowstone');\n}\ncar(113);\ncar(79);\ncar(45);\n// couplers\nfill(164, 9, 128, 166, 9, 128, 'iron_block');   // tender to loco\nfill(145, 9, 128, 146, 9, 128, 'iron_block');   // tender to car 1\nfill(111, 9, 128, 112, 9, 128, 'iron_block');\nfill(77, 9, 128, 78, 9, 128, 'iron_block');\n\n// ---------- smoke trail, shrinking puffs drifting back over the train ----------\nfunction puff(cx, cy, cz, r) {\n  var n = Math.ceil(r) + 1;\n  for (var dx = -n; dx <= n; dx++)\n    for (var dy = -n; dy <= n; dy++)\n      for (var dz = -n; dz <= n; dz++) {\n        var pr = r + (hash(cx + dx, cy + dy, cz + dz) - 0.5) * 1.2;\n        if (dx * dx + dy * dy + dz * dz <= pr * pr) put(cx + dx, cy + dy, cz + dz, 'white_wool');\n      }\n}\nfor (var sp = 0; sp < 7; sp++) {\n  puff(Math.round(202 - sp * 5 - sp * sp * 0.4), 34 + sp * 2, Math.round(128 + Math.sin(sp * 1.9) * 1.2), 3.6 - sp * 0.4);\n}\n\n// ---------- write everything out ----------\nvar count = 0;\nfor (var key in V) {\n  var p = key.split(',');\n  block(+p[0], +p[1], +p[2], V[key]);\n  count++;\n}\n","gridSize":256,"palette":"simple","seed":123}}
