A 3D model pipeline, pushed by GPT-6.2-Astra

agent (cont.)

+11:45
  • exec_commandsed -n '923,944p' tools/gear.py && sed -n '251,304p' tools/outfit.py && rg -n 'def (limb_lames|side_of|loops|pipe)' tools/outfit.py && sed -n '417,460p' review/vroid-02/index.html

    command

    sed -n '923,944p' tools/gear.py && sed -n '251,304p' tools/outfit.py && rg -n 'def (limb_lames|side_of|loops|pipe)' tools/outfit.py && sed -n '417,460p' review/vroid-02/index.html

    result, 4 lines

    Script completed
    Wall time 0.0 seconds
    Output:
    {"chunk_id":"7df7d5","wall_time_seconds":0.00000433,"exit_code":0,"original_token_count":1881,"output":"    return _group([pc], \"dress\")\n\n\ndef cuffs(fit, role=\"glove\", name=\"cuff\", length=0.38, flare=0.030, lift=0.010):\n    \"\"\"Big flared gauntlet cuffs over the lower forearm (oversized, as the study's units wear them).\"\"\"\n    B = fit.bone\n    out = []\n    for side in (\"L\", \"R\"):\n        la, hd = B[f\"J_Bip_{side}_LowerArm\"], B[f\"J_Bip_{side}_Hand\"]\n        fore = O.limb_surface(fit, (f\"{side}_LowerArm\",), side)\n        lc = LimbChart(fore, la, hd, front=(0, 0, -1))\n        pc, ex = outline_plate(f\"{name}_{side}\", role, lc, -180, 180, lambda u: 1.04, lambda u: 1.0 - length, offset=lift,\n                               flare=lambda u, v, s, t: flare * t ** 1.5, thickness=0.005, nu=40, nv=10, roll=0.004,\n                               roll_edges=(\"top\",))\n        fit.bind(pc, rigid=f\"J_Bip_{side}_LowerArm\")\n        for p in ex:\n            fit.bind(p, rigid=f\"J_Bip_{side}_LowerArm\")\n        out += [pc] + ex\n    return _group(out, \"gloves\")\n\n\ndef round_shield(fit, side=\"L\", radius=0.24, wood=\"wood\", rim=\"steel\", name=\"shield\"):\ndef wrap(fit, name, role, bones, offset, min_w=0.5, exclude=(), y_min=None, y_max=None, subdiv=0,\n         base=None, hems=(), smooth=15, cut=None, refloor=False, clamp=False):\n    \"\"\"A garment shrink-wrapped onto the body region that follows `bones`. cut: (normal, d), keep only\n    the skin below that plane (n.p < d, give or take a centimetre; pair it with a hem on the same plane).\n    refloor: after the hems, push out whatever a hem pulled into the skin (a hem moves its edge straight\n    along the plane's normal, which sinks it into a sloping hip; off by default so finished costumes\n    don't drift). clamp: every vertex past a hem's plane goes onto it, not just the edge's (pass y_min\n    and y_max a few centimetres past the hems: large skin triangles crossing a hem line otherwise leave\n    notches as deep as a triangle).\"\"\"\n    T = fit.tris_for(bones, min_w, exclude, y_min, y_max)\n    if cut is not None:\n        n_ = np.asarray(cut[0], float) / np.linalg.norm(cut[0])\n        T = T[(fit.pos[T] @ n_).max(1) < cut[1] + 0.01]\n    if not len(T):\n        return None\n    pos, tri, used = compact(fit.pos, T)\n    levels = []\n    for _ in range(subdiv):\n        pos, tri, par = subdivide(pos, tri, with_parents=True)\n        levels.append(par)\n    out = shrink_wrap(pos, tri, base or fit.surf, offset, smooth=smooth)\n    for n, d in hems:\n        out = flatten_hem(out, tri, n, d)\n        if clamp:\n            n_ = np.asarray(n, float) / np.linalg.norm(n)\n            over = out @ n_ - d\n            out = out - np.outer(np.maximum(over, 0.0), n_)\n    if refloor and hems:\n        surf = base or fit.surf\n        d2, cp2, ti2 = surf.query(out)\n        low = d2 < offset * 0.75\n        out[low] = cp2[low] + surf.fn[ti2[low]] * offset * 0.75\n    pc = piece(name, role, out, tri)\n    # weights come from the exact skin each vertex grew from: copying from the nearest skin instead\n    # let the inside of one boot pick up the other leg's bones\n    pc[\"J\"], pc[\"W\"] = blend_weights(fit.J[used], fit.W[used], int(fit.J.max()) + 1, levels)\n    pc[\"jnames\"] = fit.jnames\n    if getattr(fit, \"cloth_hull\", False):             # a body with muscle relief: sleeves span the hollows\n        hw = lambda b: (np.array([b == n for n in fit.jnames])[pc[\"J\"]] * pc[\"W\"]).sum(1)\n        axes = []\n        for sd in (\"L\", \"R\"):\n            for b0, b1 in ((\"UpperArm\", \"LowerArm\"), (\"LowerArm\", \"Hand\"), (\"UpperLeg\", \"LowerLeg\"), (\"LowerLeg\", \"Foot\"),\n                           (\"Foot\", \"ToeBase\")):                  # (boots over the foot: no toes showing)\n                n0, n1 = f\"J_Bip_{sd}_{b0}\", f\"J_Bip_{sd}_{b1}\"\n                if n0 in fit.bone and n1 in fit.bone:\n                    m = hw(n0) + (hw(n1) if b0 == \"Foot\" else 0.0)    # the foot's segment takes the toes too\n                    axes.append((m >= 0.6, fit.bone[n0], fit.bone[n1], b0 == \"Foot\"))\n        pc[\"pos\"] = limb_hull(pc[\"pos\"], tri, axes)\n        pc[\"nrm\"] = vertex_normals(pc[\"pos\"], tri)\n    pc[\"loops\"] = boundary_loops(tri)\n    return pc\n\n\ndef loop_trim(name, role, garment, pick, width=0.008, lift=0.0015):\n552:def pipe(name, role, curve, r=0.0026, seg=6, closed=False):\n589:def side_of(pc, side):\n595:def limb_lames(fit, name, role, over, top, bottom, lames, arc=(-180, 180), front=(0, 0, -1), thickness=0.0035,\n  }\n  void main() {\n    vec4 tex = texture2D(uMap, vUv);\n    if (uAlpha == 1 && tex.a < 0.5) discard;\n    if (uAlpha == 2 && (tex.a < 0.5 || dot(tex.rgb, vec3(1.0 / 3.0)) >= 0.42)) discard;\n    if (uPass == 1) { gl_FragColor = uInfo; return; }\n    vec3 n = normalize(vN); if (!gl_FrontFacing) n = -n;\n    vec3 v = normalize(vView);\n    float lit = dot(n, uKey) * 0.5 + 0.5;\n    if (uShadeOnly == 1) lit = min(lit, 0.37);                        // shadow cards only ever darken skin, to a soft shade\n    else if (uCastOn == 1 && uKind == 1 && int(uInfo.x * 255.0 + 0.5) == 2 && castShadow() > 0.5)\n      lit = min(lit, 0.37);                                           // body skin under the jaw's or the hair's shadow\n    float g1 = vnoise(vObj * 40.0), g2 = vnoise(vObj * 150.0);\n    vec3 col;\n    if (uKind == 0 || uKind == 5 || uKind == 6) {                    // cloth, leather, ground\n      vec3 hb = rgb2hsv(uBase);\n      bool cool = hb.x > 0.42 && hb.x < 0.86;\n      float sh = uKind == 5 ? 0.93 : (cool ? 0.70 : 0.96);\n      float li = cool ? 0.52 : 0.13;\n      vec3 c0 = tone(uBase, sh, 0.09, 1.12, 0.40), c1 = tone(uBase, sh, 0.05, 1.08, 0.64);\n      vec3 c3 = tone(uBase, li, 0.03, 0.80, 1.20);\n      float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.22 : 0.0);  // ground: a flat top sits at the base colour\n      col = mix(c0, c1, st(l, 0.30)); col = mix(col, uBase, st(l, 0.50)); col = mix(col, c3, st(l, 0.91));\n      if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0);       // mottled leather\n    } else if (uKind == 1) {                                           // skin: pale, nearly unshaded from the front\n      vec3 sL = vec3(0.973, 0.882, 0.835), sS = vec3(0.776, 0.659, 0.608), sC = vec3(0.451, 0.322, 0.310);\n      if (uSkinRamp == 1) { sL = uSkinL; sS = uSkinS; sC = uSkinC; }   // the character's tone, designed per tone\n      col = mix(sC, sS, st(lit, 0.20)); col = mix(col, sL, st(lit, 0.38));\n      if (uFaceTex == 1) col *= clamp(tex.rgb / uSkinRef, 0.55, 1.05);\n      if (uFaceTex == 1 && vUv.x > 0.38 && vUv.x < 0.62 && vUv.y > 0.68 && vUv.y < 0.84) {\n        // the closed mouth: VRoid paints a 2-texel line that the clamp above leaves faint; ink it and widen it\n        // (the darkest of a few taps), so it follows the mouth's shape keys as a drawn line\n        float d = 0.0, sl = dot(uSkinRef, vec3(1.0 / 3.0));\n        for (int k = -2; k <= 2; k++) for (int j = -1; j <= 1; j++) {\n          vec3 t = texture2D(uMap, vUv + vec2(float(j) * 1.2, float(k) * 0.8) / 512.0).rgb;\n          d = max(d, 1.0 - dot(t, vec3(1.0 / 3.0)) / sl);\n        }\n        float taper = 1.0 - 0.55 * smoothstep(0.035, 0.065, abs(vUv.x - 0.5));   // a brush stroke: lighter at the corners\n        col = mix(col, vec3(0.42, 0.22, 0.22), smoothstep(0.10, 0.22, d) * taper);\n      }\n      if (uSkinRamp == 0) col *= uSkinTone;                            // older builds: one tint over the light skin\n    } else if (uKind == 2) {                                           // hair: four even bands, hard strand highlights\n      float strand = dot(tex.rgb, vec3(1.0 / 3.0));\n      vec3 c0 = tone(uBase, 0.72, 0.07, 1.10, 0.45), c1 = tone(uBase, 0.72, 0.035, 1.05, 0.68);\n"}
  • exec_commandsed -n '589,628p' tools/outfit.py

    command

    sed -n '589,628p' tools/outfit.py
    sed -n '1007,1026p' tools/vroid_portrait.py
    ls -lah review/out/high-water | head -20

    result, 4 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    {"chunk_id":"16c166","wall_time_seconds":0.00000366,"exit_code":0,"original_token_count":1066,"output":"def side_of(pc, side):\n    \"\"\"A piece's triangles on one side of the body (the character's left is -x).\"\"\"\n    cx = pc[\"pos\"][pc[\"tri\"]][:, :, 0].mean(1)\n    return Surface(pc[\"pos\"], pc[\"tri\"][cx < 0.0] if side == \"L\" else pc[\"tri\"][cx > 0.0])\n\n\ndef limb_lames(fit, name, role, over, top, bottom, lames, arc=(-180, 180), front=(0, 0, -1), thickness=0.0035,\n               seg=30, rows=5, rmax=0.13):\n    \"\"\"Bands of plate around a limb: each lame covers fractions (s0, s1) of the segment top->bottom\n    and sits off `over` (ray cast out of the bone axis) by an offset that grows toward its lower\n    rim. Lames are stacked like roof tiles: the upper one's rim sits outside the next one's top.\n    arc: degrees around the limb that the plate covers (0 = front, + toward the character's right).\"\"\"\n    top, bottom = np.asarray(top, float), np.asarray(bottom, float)\n    ax = bottom - top\n    L = np.linalg.norm(ax)\n    ax /= L\n    f = np.asarray(front, float) - ax * (np.asarray(front, float) @ ax)\n    f /= np.linalg.norm(f)\n    sd = np.cross(ax, f)\n    ph = np.radians(np.linspace(arc[0], arc[1], seg))\n    out, rims = [], []\n    for k, (s0, s1, o0, o1) in enumerate(lames):\n        rows = max(rows, int(L * (s1 - s0) / 0.015) + 1)     # sparse rows let the limb bulge through between them\n        G = np.zeros((seg, rows, 3))\n        for j, t in enumerate(np.linspace(s0, s1, rows)):\n            o = top + ax * L * t\n            D = np.outer(np.cos(ph), f) + np.outer(np.sin(ph), sd)\n            r = np.array([over.cast(o, d, rmax=rmax, far=True) for d in D])\n            r = np.where(np.isnan(r), np.nanmedian(r) if np.isfinite(r).any() else 0.05, r)\n            r = np.convolve(np.pad(r, 2, mode=\"wrap\" if arc[1] - arc[0] >= 359 else \"edge\"), np.ones(5) / 5, \"valid\")\n            G[:, j] = o + D * (r + o0 + (o1 - o0) * j / (rows - 1))[:, None]\n        pos, tri, outer = thick_grid(G, thickness, outward_from=top, axis=ax)\n        out.append(piece(f\"{name}{k}\" if len(lames) > 1 else name, role, pos, tri))\n        rims.append((outer[:, 0], outer[:, -1]))\n    return out, rims\n\n\ndef dome(name, role, centre, normal, up, r, depth, thickness=0.003, seg=20, rows=6, scallop=0.0):\n    \"\"\"A shallow cap (couter, poleyn, shield boss): an ellipsoid section rising `depth` along\n    `normal` over a base of radius r.\"\"\"\n                p[\"tri\"] = p[\"tri\"][(wv[p[\"tri\"]] >= 0.5).all(1)]\n                if getattr(fit, \"drop_skin\", None) is not None:      # a costume may hide the skin it covers\n                    p[\"tri\"] = p[\"tri\"][~fit.drop_skin(p)[p[\"tri\"]].all(1)]\n            else:\n                T = p[\"pos\"][p[\"tri\"]]\n                head = T[:, :, 1].min(1) > cy - 0.02\n                neck = (T[:, :, 1].min(1) > cy - 0.14) & (np.abs(T[:, :, 0]).max(1) < 0.055)\n                p[\"tri\"] = p[\"tri\"][head | neck]\n        for pc in world or []:              # scenery: does not turn with the character\n            self.prims.append(pc)\n            self.roles.append(pc[\"role\"])\n        # framing uses the unshaped face at the base head size, so head-size changes still show\n        self.span = (self.lm[\"eye_y\"] - self.lm[\"chin\"][1]) / sh[\"head\"]\n        reshape(self.prims, self.roles, self.lm, sh)\n        strip_blush(self.prims, self.roles, self.v, sh[\"blush\"])\n        face_lines(self.prims, self.roles, self.v, sh[\"age_lines\"])\n        lm_now = landmarks(self.prims, self.roles)          # after the sculpt\n        names, Wn = self.v.nodes_by_name(), self.v.node_world(pose)\n        neck = (Wn[names[\"J_Bip_C_Neck\"]][:3, 3], Wn[names[\"J_Bip_C_Head\"]][:3, 3]) \\\n            if \"J_Bip_C_Neck\" in names and \"J_Bip_C_Head\" in names else None\ntotal 5.8M\ndrwx------ 3 runner runner 4.0K Nov 17 22:55 .\ndrwx------ 3 runner runner 4.0K Nov 17 22:47 ..\ndrwx------ 2 runner runner 4.0K Nov 17 22:53 browser\n-rw------- 1 runner runner    0 Nov 17 22:47 build.log\n-rw------- 1 runner runner 9.9K Nov 17 22:53 camera.json\n-rw------- 1 runner runner  30K Nov 17 22:52 check.jpg\n-rw------- 1 runner runner 421K Nov 17 22:55 crossing.jpg\n-rw------- 1 runner runner  69K Nov 17 22:50 detail.png\n-rw------- 1 runner runner 4.6M Nov 17 22:53 figure.glb\n-rw------- 1 runner runner 564K Nov 17 22:53 figure.png\n-rw------- 1 runner runner  55K Nov 17 22:55 marsh-check.jpg\n"}
  • exec_commandpython3 - <<'PY'

    command

    python3 - <<'PY'
    p='review/high-water/figure.py'
    s=open(p).read().replace('    for side in "LR":\n        shoe','''    pieces += gear.cuffs(fit, length=.45, flare=.009, lift=.009)
        boots = next(p for p in pieces if p["material"] == "OUTFIT_boots")
        for side in "LR":
            knee, ankle = [fit.bone[f"J_Bip_{side}_{joint}"] for joint in ("LowerLeg","Foot")]
            straps, rims = outfit.limb_lames(fit, f"gaiter_{side}", "gaiter", outfit.side_of(boots,side),
                                             knee, ankle, ((.29,.38,.007,.009),(.67,.74,.006,.006),(.86,.93,.006,.006)))
            for strap, (edge, _) in zip(straps,rims):
                pieces.append(fit.bind(strap, rigid=f"J_Bip_{side}_LowerLeg"))
                pieces.append(fit.bind(outfit.pipe("stitch","gold",edge,r=.0017,closed=True), rigid=f"J_Bip_{side}_LowerLeg"))
            shoe''').replace('boot="#514343"', 'boot="#514343", gaiter="#826548"')
    s=s.replace('grip, axis, _, _, _ = gear._hand_frame(fit)','''grip, axis, lateral, flat, _ = gear._hand_frame(fit)
        # Keep the kit shaft and set a little open brass dial into its head.
        shaft = next(p for p in pieces if p["material"] == "OUTFIT_staff_shaft")
        height = (shaft["pos"] - grip) @ axis
        shaft["pos"] -= np.outer(np.maximum(height,0)*(.21/.90),axis)
        pieces = [p for p in pieces if not p["material"].startswith(("OUTFIT_staff_orb","OUTFIT_staff_prong"))]
        centre = grip + axis*.75
        angle = np.linspace(0,2*np.pi,72,endpoint=False)
        for k,across in enumerate([.64*lateral+.77*flat, -.55*lateral+.83*flat]):
            hoop = centre + .061*np.outer(np.cos(angle),axis) + (.055-.012*k)*np.outer(np.sin(angle),across)
            pieces.append(fit.bind(outfit.pipe(f"dial_{k}","gold",hoop,r=.0047,closed=True),rigid="J_Bip_R_Hand"))
        for radius, offset in [(.019,0),(.008,.065),(.011,-.064)]:
            pieces.append(fit.bind(outfit.ball("bead","gold",centre+axis*offset,radius),rigid="J_Bip_R_Hand"))
        pieces.append(fit.bind(outfit.tube("spindle","gold",centre-axis*.064,axis,.128,.0028),rigid="J_Bip_R_Hand"))''')
    s=s.replace('[.015, -.24, -.47]','[-.080, -.245, -.54]').replace('[.035, 1, .16]','[-.16, 1, .035]')
    # Incline the action and lower the arm a little to the brim.
    s=s.replace('[-.193, .073, -.048]', '[-.203, .027, -.080]').replace('[.26, .84, -.18]','[.54, .66, -.13]')
    s=s.replace('    return pieces\n','''    # Ease the side of the coat around the forward thigh as it steps. The
        # trousers stay close to the hip underneath the fitted waist.
        trousers = next(p for p in pieces if p["material"] == "OUTFIT_trousers")
        hips = fit.bone["J_Bip_C_Hips"]
        ease = np.clip((trousers["pos"][:,1] - hips[1]+.28)/.20, 0, 1)
        trousers["pos"][:,0] *= 1-.16*ease
        trousers["pos"][:,2] = hips[2] + (trousers["pos"][:,2]-hips[2])*(1-.22*ease)
        return pieces
    ''')
    open(p,'w').write(s)
    p='review/high-water/shot.js'
    s=open(p).read().replace('render();','''for (const mesh of actor.meshes) {
      mesh.userData.mats.painted.uniforms.uKey.value.set(.43, .56, .70).normalize();
    }
    render();''')
    open(p,'w').write(s)
    PY
    OPENBLAS_NUM_THREADS=1 python3 review/high-water/figure.py && node review/high-water/shoot.cjs && python3 review/high-water/marsh.py review/out/high-water/crossing.jpg

    result, 4 lines

    Script completed
    Wall time 0.4 seconds
    Output:
    {"chunk_id":"a5c16b","wall_time_seconds":0.250689518,"session_id":93828,"original_token_count":0,"output":""}
  • write_stdinpoll session 93828

    input

    text(await tools.write_stdin({session_id:93828,chars:"",yield_time_ms:400,max_output_tokens:400}))
    

    result, 4 lines

    Script completed
    Wall time 0.0 seconds
    Output:
    {"chunk_id":"3a9ce7","wall_time_seconds":0.00000331,"exit_code":0,"original_token_count":0,"output":""}
  • view_image~/work/lowmarch/review/out/high-water/crossing.jpg

    input

    image((await tools.view_image({path:"~/work/lowmarch/review/out/high-water/crossing.jpg"})).image_url)
    

    result, 4 lines

    Script completed
    Wall time 0.0 seconds
    Output:
    
    crossing_2.jpg
    crossing_2.jpg
  • exec_commandsed -n '99,115p' tools/outfit.py

    command

    sed -n '99,115p' tools/outfit.py
    sed -n '435,485p' tools/plates.py
    sed -n '35,160p' review/high-water/figure.py

    result, 4 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    {"chunk_id":"6936b6","wall_time_seconds":0.00000577,"exit_code":0,"original_token_count":2576,"output":"def box(name, role, centre, axes, half):\n    c = np.asarray(centre, float)\n    ax = [np.asarray(v, float) * h for v, h in zip(axes, half)]\n    corners = np.array([c + sx * ax[0] + sy * ax[1] + sz * ax[2]\n                        for sx in (-1, 1) for sy in (-1, 1) for sz in (-1, 1)])\n    quads = [(0, 1, 3, 2), (4, 6, 7, 5), (0, 4, 5, 1), (2, 3, 7, 6), (0, 2, 6, 4), (1, 5, 7, 3)]\n    pos, tri = [], []\n    for q in quads:\n        base = len(pos)\n        pos += [corners[i] for i in q]\n        tri += [(base, base + 1, base + 2), (base, base + 2, base + 3)]\n    return piece(name, role, np.array(pos), np.array(tri), outward_from=c)\n\n\ndef tube(name, role, start, axis, length, r0, r1=None, seg=16, rows=2):\n    r1 = r0 if r1 is None else r1\n    a, b, c = frame_axes(axis)\n                continue\n            tri.append((i0, i1, i2))\n            idx.pop(k)\n            break\n    if len(idx) == 3:\n        tri.append(tuple(idx))\n    return np.array(tri, int)\n\n\ndef flat_piece(name, role, outline, origin, ex, ey, thickness=0.002, decal=(), px=4000):\n    \"\"\"A flat convex shape (outline: (x, y) points in metres, in order) on the plane origin + x ex + y ey,\n    given thickness along ex x ey, with an optional decal in the same (x, y) coordinates.\"\"\"\n    from outfit import piece\n    O, ex, ey = (np.asarray(a, float) for a in (origin, ex, ey))\n    nz = np.cross(ex, ey)\n    nz /= np.linalg.norm(nz)\n    P2 = np.asarray(outline, float)\n    c2 = P2.mean(0)\n    m = len(P2)\n    lo, hi = P2.min(0), P2.max(0)\n    span = np.maximum(hi - lo, 1e-6)\n    pts = np.vstack([c2, P2])\n    top = O + pts[:, :1] * ex + pts[:, 1:] * ey + nz * thickness / 2\n    bot = top - nz * thickness\n    k = np.arange(m)\n    fan = 1 + _ear_clip(P2)                            # any simple outline, concave too (an axe's crescent)\n    nn = m + 1\n    wall = np.concatenate([np.stack([1 + k, 1 + (k + 1) % m, nn + 1 + (k + 1) % m], 1),\n                           np.stack([1 + k, nn + 1 + (k + 1) % m, nn + 1 + k], 1)])\n    tri = np.concatenate([fan, fan[:, ::-1] + nn, wall])\n    pos = np.concatenate([top, bot])\n    if np.cross(pos[tri[0, 1]] - pos[tri[0, 0]], pos[tri[0, 2]] - pos[tri[0, 0]]) @ nz < 0:\n        tri = np.concatenate([fan[:, ::-1], fan + nn, wall[:, ::-1]])\n    pc = piece(name, role, pos, tri)\n    if decal:\n        cv = Canvas(min(1024, max(32, span[0] * px)), min(1024, max(32, span[1] * px)))\n        st = lambda xy: (np.atleast_2d(np.asarray(xy, float)) - lo) / span\n        for sh in decal:\n            if sh[0] == \"poly\":\n                cv.poly(st(sh[1]), sh[2])\n            elif sh[0] == \"line\":\n                cv.line(st(sh[1]), sh[2] * cv.w / span[0], sh[3])\n        pc[\"decal\"] = cv.array()\n        pc[\"uv\"] = np.concatenate([st(pts), st(pts)])\n    return pc\n\n\ndef taper(pc, n_along, n_round, scale):\n    \"\"\"Scale a pipe's cross-section along its length (scale: one factor per centreline point).\"\"\"\n    P = pc[\"pos\"].reshape(n_along, n_round, 3)\n    C = P.mean(1, keepdims=True)\n        cloth.poly([(x + u / 14, v) for u, v in crest], \"paint\")\n        cloth.dot((x + .79 / 14, .184), 2.3, 2.3, \"gold\")\n    for v in (.035, .046, .245):\n        cloth.line([(0, v), (1, v)], 1.6, \"gold\")\n    return cloth.array()\n\n\ndef costume(fit):\n    pieces = mobs.witch(fit)\n    # Recut the stock cone. A higher front gives the forward boot room and the\n    # slack runs behind the wearer. Use the angle before moving the hem for UVs.\n    skirt = next(p for p in pieces if p[\"material\"] == \"OUTFIT_robe_skirt\")\n    pos = skirt[\"pos\"]\n    angle = np.mod(np.arctan2(pos[:, 0], -(pos[:, 2] - fit.bone[\"J_Bip_C_Hips\"][2])), 2 * np.pi)\n    t = skirt[\"plate\"][:, 3]\n    fall = (1 - t) ** 1.6\n    front = (1 + np.cos(angle)) / 2\n    fold = (.010 * np.cos(9 * angle + t) + .008 * np.sin(5 * angle - t)) * fall\n    pos[:, 0] += np.sin(angle) * fold - .025 * fall\n    pos[:, 2] += (.175 - .09 * front) * fall - np.cos(angle) * fold\n    pos[:, 1] += (.12 + .16 * front + .024 * np.cos(5 * angle)) * fall\n    skirt[\"uv\"] = np.column_stack([angle / (2 * np.pi), t])\n    skirt[\"decal\"] = hem_pattern()\n    skirt[\"nrm\"] = vertex_normals(pos, skirt[\"tri\"])\n    skirt[\"role\"] = \"tidecoat\"\n    for p in pieces:\n        if p[\"material\"].startswith(\"OUTFIT_hat\"):\n            if p[\"material\"] == \"OUTFIT_hat\":\n                pos = p[\"pos\"]\n                tip = np.clip((pos[:, 1] - pos[:, 1].min()) / .32, 0, 1)\n                pos[:, 2] += .20 * tip ** 2\n                pos[:, 1] -= .115 * tip ** 2\n                p[\"nrm\"] = vertex_normals(pos, p[\"tri\"])\n            if p[\"role\"] == \"signature\":\n                p[\"role\"] = \"tidecoat\"\n\n    body = next(p for p in pieces if p[\"material\"] == \"OUTFIT_robe\")\n    over = merge_surfaces((fit.pos, fit.tri), (body[\"pos\"], body[\"tri\"]))\n    mantle, grid, hood = outfit.mantle(fit, \"wrap\", \"scarf\", over)\n    pieces.extend([mantle, hood])\n    pieces += gear.cuffs(fit, length=.45, flare=.009, lift=.009)\n    boots = next(p for p in pieces if p[\"material\"] == \"OUTFIT_boots\")\n    for side in \"LR\":\n        knee, ankle = [fit.bone[f\"J_Bip_{side}_{joint}\"] for joint in (\"LowerLeg\",\"Foot\")]\n        straps, rims = outfit.limb_lames(fit, f\"gaiter_{side}\", \"gaiter\", outfit.side_of(boots,side),\n                                         knee, ankle, ((.29,.38,.007,.009),(.67,.74,.006,.006),(.86,.93,.006,.006)))\n        for strap, (edge, _) in zip(straps,rims):\n            pieces.append(fit.bind(strap, rigid=f\"J_Bip_{side}_LowerLeg\"))\n            pieces.append(fit.bind(outfit.pipe(\"stitch\",\"gold\",edge,r=.0017,closed=True), rigid=f\"J_Bip_{side}_LowerLeg\"))\n        shoe = outfit.sabaton(fit, f\"shoe_{side}\", side, role=\"boot\", pad=.017, ridges=0)[0]\n        pieces.append(shoe)\n    clasp = outfit.ball(\"mantle_pin\", \"gold\", grid[0, 5] + [0, 0, -.007], .016, squash=(1, 1.15, .45))\n    pieces.append(fit.bind(clasp, rigid=\"J_Bip_C_UpperChest\"))\n    # A long and a short end of the same scarf lift together in the crosswind.\n    anchor = grid[len(grid)//2, 0].copy()\n    for j, length in enumerate((.66, .43)):\n        t = np.linspace(0, 1, 55)\n        c = anchor + np.column_stack([.10*t + .045*np.sin(2*np.pi*t + j)*t,\n                                      -.12*t + .09*np.sin(2*np.pi*t+.6*j)*t - .065*j*t,\n                                      length*t])\n        breadth = .052*(1 - .36*t) * (1 - .75*t**9)\n        axis = np.column_stack([.55*np.cos(3*np.pi*t), np.ones_like(t), .12*np.sin(4*t)])\n        sheet = np.stack([c + u*breadth[:,None]*axis for u in (-1, -.5, 0, .5, 1)], axis=1)\n        sheet[:,2,0] += .009*np.sin(np.pi*t)\n        pos, tri = outfit.grid_mesh(sheet)\n        flag = outfit.piece(f\"scarf_end_{j}\", \"scarf\", pos, tri)\n        pieces.append(fit.bind(flag, rigid=\"J_Bip_C_UpperChest\"))\n        edge = fit.bind(outfit.pipe(f\"woven_edge_{j}\", \"gold\", sheet[:,0], r=.0023), rigid=\"J_Bip_C_UpperChest\")\n        pieces.append(edge)\n\n    # Marks on the part of the sounding staff that goes into the water.\n    grip, axis, lateral, flat, _ = gear._hand_frame(fit)\n    # Keep the kit shaft and set a little open brass dial into its head.\n    shaft = next(p for p in pieces if p[\"material\"] == \"OUTFIT_staff_shaft\")\n    height = (shaft[\"pos\"] - grip) @ axis\n    shaft[\"pos\"] -= np.outer(np.maximum(height,0)*(.21/.90),axis)\n    pieces = [p for p in pieces if not p[\"material\"].startswith((\"OUTFIT_staff_orb\",\"OUTFIT_staff_prong\"))]\n    centre = grip + axis*.75\n    angle = np.linspace(0,2*np.pi,72,endpoint=False)\n    for k,across in enumerate([.64*lateral+.77*flat, -.55*lateral+.83*flat]):\n        hoop = centre + .061*np.outer(np.cos(angle),axis) + (.055-.012*k)*np.outer(np.sin(angle),across)\n        pieces.append(fit.bind(outfit.pipe(f\"dial_{k}\",\"gold\",hoop,r=.0047,closed=True),rigid=\"J_Bip_R_Hand\"))\n    for radius, offset in [(.019,0),(.008,.065),(.011,-.064)]:\n        pieces.append(fit.bind(outfit.ball(\"bead\",\"gold\",centre+axis*offset,radius),rigid=\"J_Bip_R_Hand\"))\n    pieces.append(fit.bind(outfit.tube(\"spindle\",\"gold\",centre-axis*.064,axis,.128,.0028),rigid=\"J_Bip_R_Hand\"))\n    # Lengthen the lower end so it reaches past the forward foot.\n    extension = outfit.tube(\"staff_lower\", \"wood\", grip - axis*1.19, axis, .45, .012, .014)\n    pieces.append(fit.bind(extension, rigid=\"J_Bip_R_Hand\"))\n    for i in range(12):\n        length = .030 if i % 3 == 0 else .014\n        mark = outfit.tube(f\"staff_mark_{i}\", \"heraldry\", grip + axis * (-1.17 + .078*i),\n                           axis, length, .0162, .0162)\n        pieces.append(fit.bind(mark, rigid=\"J_Bip_R_Hand\"))\n    # Ease the side of the coat around the forward thigh as it steps. The\n    # trousers stay close to the hip underneath the fitted waist.\n    trousers = next(p for p in pieces if p[\"material\"] == \"OUTFIT_trousers\")\n    hips = fit.bone[\"J_Bip_C_Hips\"]\n    ease = np.clip((trousers[\"pos\"][:,1] - hips[1]+.28)/.20, 0, 1)\n    trousers[\"pos\"][:,0] *= 1-.16*ease\n    trousers[\"pos\"][:,2] = hips[2] + (trousers[\"pos\"][:,2]-hips[2])*(1-.22*ease)\n    return pieces\n\n\ndef make_pose(model, shape):\n    ref = vp.BUST_POSE\n    skeleton = rig.Rig(model, shape, ortho=True)\n    pose = poses.merge(poses.BATTLE_IDLE, {\n        \"J_Bip_C_Hips\": poses.move(dy=-.043),\n        \"J_Bip_C_Spine\": poses.rot((1, 0, 0), -12),\n        \"J_Bip_C_Head\": poses.rot((0, 1, 0), -32) @ poses.rot((1, 0, 0), 7),\n        \"J_Bip_L_UpperArm\": poses.rot((0, 1, 0), 25),\n        \"J_Bip_L_LowerArm\": poses.rot((0, 1, 0), -16),\n    })\n    for side, dz in ((\"L\", -.17), (\"R\", .135)):\n        foot = skeleton.pos(ref, f\"J_Bip_{side}_Foot\")\n        pose = skeleton.leg_ik(pose, side, foot + [0, .015 if side == \"R\" else 0, dz])\n    # Catch the brim with the far hand. The elbow opens to the side so the\n    # glove and the bent sleeve separate from her face in three-quarter view.\n    head = skeleton.pos(pose, \"J_Bip_C_Head\")\n    pose = skeleton.arm_ik(pose, \"L\", head + [-.203, .027, -.080], [-.95, -.35, .15])\n    pose = skeleton.aim(pose, \"J_Bip_L_Hand\", [-1, 0, 0], [.54, .66, -.13])\n    hand = rig.grip_points(model, shape, ref)[\"R\"][\"point\"]\n    shoulder = skeleton.pos(pose, \"J_Bip_R_UpperArm\")\n    # Wrist extended ahead of her as she takes a sounding. The staff points\n    # back toward her at the top, planting its foot away from her front boot.\n    return skeleton.grip(pose, \"R\", ref, hand, shoulder + [-.080, -.245, -.54],\n"}
  • exec_commandpython3 - <<'PY'

    command

    python3 - <<'PY'
    p='review/high-water/marsh.py'
    s=open(p).read()
    a=s.index('    u = np.linspace(0, 1, 176)'); b=s.index('    pts = np.column_stack',a)
    s=s[:a]+'''    u = np.linspace(0, 1, 340)
        shape = np.sin(np.pi*u)**.83
        # Wind pulls a long thin veil off the high side of each billow.
        bank = np.zeros_like(u)
        for _ in range(38):
            c, width = r.uniform(-.06, 1.06), r.uniform(.025, .16)
            high = r.uniform(.14,.95) * (.48+.52*math.sin(math.pi*np.clip(c,0,1)))
            ellipse = high*np.sqrt(np.maximum(0, 1-((u-c)/width)**2))
            bank = np.maximum(bank,ellipse)
        top = y - height*shape*bank - 16*u + 3*np.sin(3*np.pi*u)
        low = y + height*shape*(.08+.07*np.sin(16*u)) - 16*u + 3*np.sin(3*np.pi*u)
    ''' + s[b:]
    s=s.replace('reflectivity = (.30*(1-.5*f))','reflectivity = (.32*(1-.76*f))')
    s=s.replace('field += (2.7*np.sin','field += (1.75*np.sin')
    s=s.replace('path = [(764,759,96),(862,707,70),(942,661,55),(1003,629,47),\n            (1061,600,32),(1110,579,26),(1147,560,21),(1176,546,17),(1200,535,12)]','''path = [(660,728,67),(818,698,52),(920,660,45),(998,629,40),(1055,601,36),
                (1100,579,26),(1134,561,23),(1161,545,19),(1180,529,14),(1192,515,12),
                (1199,503,10),(1205,492,8),(1207,483,7),(1210,475,5),(1210,470,3)]''')
    s=s.replace('    shore(im)\n    for i in range(30):','''    for i in range(30):''')
    # Place washes and reflections on the water before drawing the bank.
    a=s.index('    for i in range(30):',s.index('def compose')); b=s.index('    # Figure reflection',a)
    reeds=s[a:b]
    s=s[:a]+s[b:]
    a=s.index('    im.alpha_composite(actor,(anchor_x,anchor_y))')
    s=s[:a]+'''    shore(im)
    '''+reeds+'''    field_markers(im)
        # Cast the silhouette toward the near bank. Keep the staff shadow faint in
        # the water while the two soles make short, dark marks on the stone.
        contact = Image.new("L", im.size)
        contact.paste(actor.getchannel("A"), (anchor_x,anchor_y))
        shear, slope, baseline = .49, .065, 743
        shadow = contact.transform(im.size,Image.Transform.AFFINE,
                                   (1,shear/slope,-shear*baseline/slope,0,-1/slope,baseline*(1+1/slope)),
                                   resample=Image.Resampling.BILINEAR).filter(ImageFilter.GaussianBlur(2))
        im.paste("#405851", (0,0,W,H), shadow.point(lambda a: a*.37))
        d=ImageDraw.Draw(im)
        d.ellipse((622,724,706,731),fill="#626f66")
        d.polygon([(543,747),(564,749),(573,752),(566,755),(528,753)],fill="#525e59")
        surface_rings(im,737,730,53,"#cecfb7")
        surface_rings(im,737,731,40,"#779490")
        im.alpha_composite(actor,(anchor_x,anchor_y))
        # Submerge the bottom few centimetres and break the reflection at the surface.
        d.polygon([(731,730),(740,729),(747,731),(739,735),(727,735)],fill="#99afaa")
        d.line([(715,731),(729,730),(738,731),(746,730),(756,731)],fill="#e0dbbb",width=2)
    ''' + s[a+len('    im.alpha_composite(actor,(anchor_x,anchor_y))\n'):]
    # Periodic tide posts on the far side of the channel and a fleeting reflection.
    a=s.index('def surface_rings(')
    s=s[:a]+'''def field_markers(im):
        d = ImageDraw.Draw(im)
        for x,y,h in [(1272,507,39),(1316,530,55),(1398,583,89)]:
            w = h*.087
            lean = h*.065
            pole = [(x-w*.4,y),(x+lean-w*.50,y-h+2),(x+lean+w*.15,y-h-2),
                    (x+lean+w*.55,y-h),(x+w*.52,y)]
            for k in range(0,int(h*.60),3):
                u = k/h
                xx=x+lean*u+math.sin(k*.46)*u*4
                d.line([(xx-w*.58,y+k),(xx+w*.48,y+k)],fill="#8a9c8e")
            d.polygon(pole,fill="#738781")
            d.line([(x+lean+w*.45,y-h+1),(x+w*.48,y)],fill="#b2ae8e",width=2)
            for k in range(3):
                t=.45+k*.17
                xx=x+lean*t
                d.line([(xx-w*.43,y-h*t),(xx+w*.42,y-h*t)],fill="#c0b595",width=2)
            surface_rings(im,x,y,w*2.3,"#a4b5a7")
    
    
    def distant_trees(im):
        # Clumps of cypress follow the far shore toward the tower; atmospheric
        # perspective keeps them close to the value of the hills behind them.
        d=ImageDraw.Draw(im)
        r=random.Random(312)
        for cx,cy,size,n in [(85,409,17,11),(256,421,11,9),(420,429,6,8),(1308,420,12,12),
                             (1440,402,18,9),(1491,391,16,6),(1575,388,22,14)]:
            for _ in range(n):
                x=cx+r.gauss(0,size*1.7)
                h=size*r.uniform(.55,1.2)
                y=cy+r.uniform(0,3)
                w=h*r.uniform(.1,.21)
                d.polygon([(x-w*.2,y),(x-w*.35,y-h*.15),(x-w,y-h*.28),(x-w*.9,y-h*.55),
                           (x-w*.5,y-h*.79),(x,y-h),(x+w*.4,y-h*.73),(x+w*.95,y-h*.49),
                           (x+w*.7,y-h*.2),(x+w*.2,y-h*.12),(x+w*.3,y)],fill="#93a49a")
    
    
    '''+s[a:]
    s=s.replace('    gate(im)\n','    distant_trees(im)\n    gate(im)\n')
    open(p,'w').write(s)
    PY
    python3 review/high-water/marsh.py review/out/high-water/crossing.jpg
    python3 - <<'PY'
    from PIL import Image
    im=Image.open('review/out/high-water/crossing.jpg'); im.thumbnail((1040,600)); im.save('review/out/high-water/marsh-check.jpg')
    PY

    result, 4 lines

    Script completed
    Wall time 2.1 seconds
    Output:
    {"chunk_id":"ccbd07","wall_time_seconds":1.928580476,"exit_code":0,"original_token_count":0,"output":""}
  • view_image~/work/lowmarch/review/out/high-water/marsh-check.jpg

    input

    image((await tools.view_image({path:"~/work/lowmarch/review/out/high-water/marsh-check.jpg"})).image_url)
    

    result, 4 lines

    Script completed
    Wall time 0.0 seconds
    Output:
    
    marsh-check_2.jpg
    marsh-check_2.jpg
  • exec_commandpython3 - <<'PY'

    command

    python3 - <<'PY'
    p='review/high-water/figure.py'
    s=open(p).read().replace('from plates import Canvas','from plates import Canvas, flat_piece')
    i=s.index('def costume(')
    s=s[:i]+'''def chart_bag(fit, skirt):
        hips = fit.bone["J_Bip_C_Hips"]
        waist = hips[1] + .06
        side = skirt["pos"]
        side = side[(side[:,1] < waist) & (side[:,1] > waist-.22)]
        centre = np.array([side[:,0].max()+.010, waist-.110, hips[2]+.028])
        # A little waxed chart bag hung from two loops on the existing belt.
        ex = np.array([-.12,.20,-.972])
        ey = np.array([-.055,.976,.207])
        normal = np.cross(ex,ey)
        corners = [(-.103,.066),(.091,.072),(.100,.044),(.094,-.064),
                   (.076,-.084),(-.074,-.087),(-.104,-.067)]
        flap = [(-.104,.071),(.094,.075),(.100,.043),(.074,.001),
                (.018,-.023),(-.067,-.012),(-.099,.014)]
        parts = [flat_piece("map_bag","leather",corners,centre,ex,ey,thickness=.040),
                 flat_piece("map_flap","gaiter",flap,centre+.027*normal,ex,ey,thickness=.012)]
        for sx in (-.068,.068):
            loop = [centre + sx*ex + ey*.065 + normal*.005,
                    centre + sx*ex + ey*.113 - normal*.010,
                    centre + sx*ex + ey*.118 - normal*.042]
            parts.append(outfit.pipe("bag_loop","leather",loop,r=.009))
        seam = [centre + x*.94*ex + y*.92*ey + normal*.0335 for x,y in flap]
        parts.append(outfit.pipe("bag_seam","leather",seam,r=.0018,closed=True))
        seal = centre + .01*ex + normal*.036 + .003*ey
        parts.append(outfit.ball("map_button","gold",seal,.010))
        return [fit.bind(part,rigid="J_Bip_C_Hips") for part in parts]
    
    
    '''+s[i:]
    s=s.replace('    for p in pieces:\n        if p["material"].startswith("OUTFIT_hat")','    pieces.extend(chart_bag(fit, skirt))\n    for p in pieces:\n        if p["material"].startswith("OUTFIT_hat")')
    s=s.replace('    # Wrist extended ahead of her', '''    for side in "LR":
            pose[f"J_Adj_{side}_FaceEye"] = poses.rot((0,1,0), 8) @ poses.rot((1,0,0), -9)
        # Wrist extended ahead of her''')
    s=s.replace('poses.rot((1, 0, 0), 7)','poses.rot((1, 0, 0), 5)')
    open(p,'w').write(s)
    PY
    OPENBLAS_NUM_THREADS=1 python3 review/high-water/figure.py && node review/high-water/shoot.cjs

    result, 4 lines

    Script completed
    Wall time 0.5 seconds
    Output:
    {"chunk_id":"6ecfea","wall_time_seconds":0.251499499,"session_id":68609,"original_token_count":0,"output":""}
  • exec_commanddate -u && ls -lt review/out/high-water/figure* && ls -l ~/out

    command

    date -u && ls -lt review/out/high-water/figure* && ls -l ~/out
    git status --short

    result, 4 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    {"chunk_id":"ec20cb","wall_time_seconds":0.00000537,"exit_code":0,"original_token_count":56,"output":"Tue Nov 17 23:01:07 UTC 2026\n-rw------- 1 runner runner  593847 Nov 17 22:57 review/out/high-water/figure.png\n-rw------- 1 runner runner 5372700 Nov 17 22:57 review/out/high-water/figure.glb\ntotal 0\n?? review/high-water/\n"}
  • exec_commandpython3 - <<'PY'

    command

    python3 - <<'PY'
    p='review/high-water/marsh.py'
    s=open(p).read()
    a=s.index('def cloud(');b=s.index('def ridge(',a)
    s=s[:a]+'''def wash_clouds(im):
        """Three windswept banks, with a light upper edge and a cool underside."""
        w,h=W,350
        y,x=np.mgrid[:h,:w]
        cloud_rng=np.random.default_rng(83)
        def noise(sx,sy):
            grid=cloud_rng.integers(0,256,(max(2,h//sy), max(2,w//sx)),dtype=np.uint8)
            return np.asarray(Image.fromarray(grid).resize((w,h),Image.Resampling.BICUBIC))/255.-.5
        waviness = 27*noise(210,52) + 12*noise(60,31) + 4*noise(25,11) + 1.3*noise(9,5)
        wash=np.asarray(im.convert("RGB"),dtype=float)[:h].copy()
        for cx,cy,rx,ry,tilt in [(-15,100,453,65,-.09),(235,128,426,22,-.085),
                                 (110,188,337,18,-.07),(1300,139,416,35,-.055),
                                 (1480,189,290,17,-.07),(640,236,332,12,-.08)]:
            dx=(x-cx)/rx
            dy=(y-cy-tilt*(x-cx)-waviness*.45)/ry
            mass=1.-dx**2-dy**2+1.1*noise(190,21)+.52*noise(65,13)+.20*noise(23,6)+.075*noise(9,3)
            opacity=np.clip(mass*2.8,0,1)
            # Bright patches keep a harder edge than the receding shadow beneath.
            bright=np.clip(.55-.41*dy+.8*noise(163,22)+.45*noise(53,13),0,1)
            bright=.65*bright+.35*np.floor(bright*4)/4
            col=rgb("#bac0bb") + bright[...,None]*(rgb("#fae6c7")-rgb("#bac0bb"))
            wash += (col-wash)*(.78*opacity)[...,None]
        im.paste(Image.fromarray(np.uint8(np.clip(wash,0,255))), (0,0))
    
    
    '''+s[b:]
    a=s.index('    air = Image.new',s.index('def compose'));b=s.index('    ridge(im,',a)
    s=s[:a]+'''    wash_clouds(im)
        d = ImageDraw.Draw(im)
        d.ellipse((1046,195,1174,323),fill="#fce8be")
        d.polygon([(1020,299),(1080,297),(1149,298),(1206,295),(1171,301),(1088,300)],fill="#ebd8b7")
    '''+s[b:]
    # Remove conspicuous polygon-edge seams from around the bank, then paint ancient cracked flags
    # and patches of lichen into its surface.
    a=s.index('    d.line([(265,832)');b=s.index('def reeds(',a)
    s=s[:a]+'''    bank_mask = Image.new("L",im.size)
        ImageDraw.Draw(bank_mask).polygon(shorepts,fill=255)
        # Pigment and lichens on the paving use short streaks that follow the causeway.
        texture = Image.new("RGBA",im.size)
        strokes = ImageDraw.Draw(texture)
        r=random.Random(72)
        for _ in range(1750):
            x,y = r.uniform(-25,680),r.uniform(680,865)
            width = r.uniform(1,13)
            strokes.polygon([(x,y),(x+width*.58,y-1.6),(x+width,y-1),(x+width*.7,y+.3)],
                            fill=r.choice([("#cacc9f35"),("#d0bb914a"),("#42535435"),("#bdb6945a")]))
        for cx,cy,length in [(115,748,58),(250,763,43),(367,748,37),(438,733,34),
                             (470,761,22),(577,742,28),(262,788,21),(59,831,35)]:
            for j in range(19):
                x=cx+r.uniform(-length,length)
                y=cy+r.gauss(0,3)
                strokes.ellipse((x,y,x+r.uniform(2,8),y+r.uniform(.5,2.5)),fill="#adb18877")
        tint=texture.getchannel("A")
        texture.putalpha(Image.composite(tint,Image.new("L",im.size),bank_mask))
        im.alpha_composite(texture)
        for pts in [[(265,832),(300,824),(357,801),(424,794),(484,776)],
                    [(488,781),(556,780),(603,767),(638,762),(686,749)]]:
            d.line(pts,fill="#b7bba2",width=2)
        for x,y in [(483,775),(351,801),(202,851),(138,872),(585,764)]:
            d.arc((x-45,y-3,x+46,y+3),8,117,fill="#bfc3ab",width=2)
    
    
    '''+s[b:]
    open(p,'w').write(s)
    PY
    python3 review/high-water/marsh.py review/out/high-water/crossing.jpg && python3 - <<'PY'
    from PIL import Image
    im=Image.open('review/out/high-water/crossing.jpg'); im.thumbnail((1040,600)); im.save('review/out/high-water/marsh-check.jpg')
    PY

    result, 4 lines

    Script completed
    Wall time 3.5 seconds
    Output:
    {"chunk_id":"ebd746","wall_time_seconds":3.281916759,"exit_code":0,"original_token_count":0,"output":""}
  • view_image~/work/lowmarch/review/out/high-water/marsh-check.jpg

    input

    image((await tools.view_image({path:"~/work/lowmarch/review/out/high-water/marsh-check.jpg"})).image_url)
    

    result, 4 lines

    Script completed
    Wall time 0.0 seconds
    Output:
    
    marsh-check_3.jpg
    marsh-check_3.jpg
  • exec_commandpython3 - <<'PY'

    command

    python3 - <<'PY'
    from PIL import Image
    im=Image.open('review/out/high-water/crossing.jpg'); im.crop((475,60,805,475)).save('review/out/high-water/detail.jpg')
    PY

    result, 4 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    {"chunk_id":"44e1e2","wall_time_seconds":0.00000369,"exit_code":0,"original_token_count":0,"output":""}
  • view_image~/work/lowmarch/review/out/high-water/detail.jpg

    input

    image((await tools.view_image({path:"~/work/lowmarch/review/out/high-water/detail.jpg"})).image_url)
    

    result, 4 lines

    Script completed
    Wall time 0.0 seconds
    Output:
    
    detail.jpg
    detail.jpg
  • exec_commandpython3 - <<'PY'

    command

    python3 - <<'PY'
    from PIL import Image
    im=Image.open('review/out/high-water/crossing.jpg'); im.crop((0,635,910,900)).save('review/out/high-water/shore.jpg')
    PY

    result, 4 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    {"chunk_id":"7d9264","wall_time_seconds":0.00000471,"exit_code":0,"original_token_count":0,"output":""}
  • view_image~/work/lowmarch/review/out/high-water/shore.jpg

    input

    image((await tools.view_image({path:"~/work/lowmarch/review/out/high-water/shore.jpg"})).image_url)
    

    result, 4 lines

    Script completed
    Wall time 0.0 seconds
    Output:
    
    shore.jpg
    shore.jpg
  • exec_commandpython3 - <<'PY'

    command

    python3 - <<'PY'
    p='review/high-water/figure.py'
    s=open(p).read().replace('def chart_bag(fit, skirt):','def chart_bag(fit, skirt, belt):').replace('hips[2]+.028','hips[2]+.013')
    s=s.replace('''        loop = [centre + sx*ex + ey*.065 + normal*.005,
                    centre + sx*ex + ey*.113 - normal*.010,
                    centre + sx*ex + ey*.118 - normal*.042]
            parts.append(outfit.pipe("bag_loop","leather",loop,r=.009))''','''        start = centre + sx*ex + ey*.053 + normal*.009
            points = belt["pos"]
            above = points[(points[:,0]>0) & (points[:,1]>np.median(points[:,1]))]
            buckle = above[np.argmin((above[:,0]-start[0])**2 + 2*(above[:,2]-start[2])**2)]
            path = np.array([start, start+[.002,.025,0], buckle+[.006,.008,0], buckle+[-.007,.002,0]])
            strap = np.stack([path-ex*.009,path+ex*.009],axis=1)
            pos, tri = outfit.grid_mesh(strap)
            parts.append(outfit.piece("bag_loop","leather",pos,tri))
            parts.append(outfit.ball("bag_stud","gold",start+[.003,0,0],.0045))''')
    s=s.replace('pieces.extend(chart_bag(fit, skirt))','belt = next(p for p in pieces if p["material"] == "OUTFIT_sash")\n    pieces.extend(chart_bag(fit, skirt, belt))')
    s=s.replace('rot((0,1,0), 8) @ poses.rot((1,0,0), -9)','rot((0,1,0), 2) @ poses.rot((1,0,0), -3)')
    s=s.replace('    # Wrist extended ahead of her as she takes a sounding. The staff points\n    # back toward her at the top, planting its foot away from her front boot.','    # Extend the wrist far enough to give the brim and the sounding staff separate silhouettes.')
    open(p,'w').write(s)
    PY
    OPENBLAS_NUM_THREADS=1 python3 review/high-water/figure.py && node review/high-water/shoot.cjs

    result, 4 lines

    Script completed
    Wall time 0.4 seconds
    Output:
    {"chunk_id":"57284f","wall_time_seconds":0.251039261,"session_id":2573,"original_token_count":0,"output":""}
  • exec_commandcommand -v ruff || command -v black || true

    command

    command -v ruff || command -v black || true
    python3 -c 'import importlib.util; print(importlib.util.find_spec("black"),importlib.util.find_spec("ruff"))'
    git status --short --branch
    ls -lt review/out/high-water/figure.png

    result, 4 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    {"chunk_id":"5be312","wall_time_seconds":0.00000602,"exit_code":0,"original_token_count":105,"output":"ModuleSpec(name='black', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7e3a90a63d90>, origin='~/.local/lib/python3.10/site-packages/black/__init__.cpython-310-x86_64-linux-gnu.so', submodule_search_locations=['~/.local/lib/python3.10/site-packages/black']) None\n## astra62\n?? review/high-water/\n-rw------- 1 runner runner 604962 Nov 17 23:01 review/out/high-water/figure.png\n"}
  • exec_commandpython3 - <<'PY'

    command

    python3 - <<'PY'
    p='review/high-water/marsh.py'
    s=open(p).read()
    a=s.index('def field_markers(')
    s=s[:a]+'''def sea_lavender(im, cx, cy, length, count, seed):
        """Wind-leaning sprays on the brackish bank, picked out against open water."""
        r = random.Random(seed)
        d = ImageDraw.Draw(im)
        for i in range(count):
            bx = cx + r.gauss(0,length*.33)
            by = cy + r.uniform(-6,4)
            height = length*r.uniform(.36,1.)
            lean = r.uniform(-.48,-.12)*height
            for k in range(3):
                leaf_tip = bx+r.uniform(-.21,.12)*height
                d.polygon([(bx,by),(bx-5,by-5),(leaf_tip,by-r.uniform(.08,.24)*height),
                           (bx+2,by-9)],fill=r.choice(["#697768","#667463","#839077"]))
            path=[(bx,by),(bx+lean*.18,by-height*.40),(bx+lean*.63,by-height*.77),(bx+lean,by-height)]
            d.line(path,fill="#50655e",width=2)
            for j in range(2,7):
                t=j/7
                x=bx+lean*(.38+.62*t)
                y=by-height*(.56+.44*t)
                side = -1 if j%2 else 1
                tx=x+side*height*(1.05-t)*r.uniform(.15,.30)
                ty=y-height*(1.05-t)*r.uniform(.16,.34)
                d.line([(x,y),(tx,ty)],fill="#657165",width=1)
                for k in range(3):
                    u=k/3
                    sx,sy=tx+(x-tx)*u,ty+(y-ty)*u
                    w=r.uniform(1.6,3.4)
                    d.polygon([(sx-w,sy),(sx-w*1.5,sy-w*1.2),(sx,sy-w*.6),(sx+w*.45,sy-w),
                               (sx+w,sy)],fill=r.choice(["#b79d94","#cbb29d","#8f8886","#b4a899"]))
    
    
    '''+s[a:]
    s=s.replace('    # A fine common paper tooth', '''    sea_lavender(im,94,821,123,11,22)
        sea_lavender(im,27,877,91,7,85)
        sea_lavender(im,1480,899,70,5,9)
        # A fine common paper tooth''')
    s=s.replace('fill="#4e6769")','fill="#4e6769")\n    for k,(x,y) in enumerate(shorepts[12:-1]):\n        xx,yy = shorepts[k+13]\n        if xx<x and k%2==0:\n            d.polygon([(x,y),(xx,yy),(xx,yy+15),(x,y+14)], fill="#687977")')
    s=s.replace('    ymid = sum(y for x,y in pts)//len(pts)','''    ymid = sum(y for x,y in pts)//len(pts)
        for k in range(2):
            x = r.uniform(left,right)
            d.arc((x-12-k*2,ymid+depth+1,x+12+k*2,ymid+depth+4),0,140,fill="#b1beae")''')
    s=s.replace('    d.line([(715,731)', '    d.line([(715,731)')
    open(p,'w').write(s)
    PY
    python3 review/high-water/marsh.py review/out/high-water/crossing.jpg

    result, 4 lines

    Script completed
    Wall time 1.1 seconds
    Output:
    {"chunk_id":"7d7835","wall_time_seconds":0.952740203,"exit_code":0,"original_token_count":0,"output":""}
  • exec_commandls -l review/high-water

    command

    ls -l review/high-water
    rg -n 'OV|dangling|raise ' review/high-water/*.py
    python3 - <<'PY'
    from PIL import Image
    im=Image.open('review/out/high-water/crossing.jpg'); im.thumbnail((1024,576)); im.save('review/out/high-water/last-check.jpg')
    PY

    result, 4 lines

    Script completed
    Wall time 0.3 seconds
    Output:
    {"chunk_id":"e82067","wall_time_seconds":0.052460438,"exit_code":0,"original_token_count":58,"output":"total 40\n-rw------- 1 runner runner 11427 Nov 17 23:03 figure.py\n-rw------- 1 runner runner 20310 Nov 17 23:04 marsh.py\n-rw------- 1 runner runner  2994 Nov 17 22:49 shoot.cjs\n-rw------- 1 runner runner   742 Nov 17 22:57 shot.js\n"}