code wiki / _hdl_build / nx_creaturegen_gate.nx

nx_creaturegen_gate.nx source

↩ module page · 72 lines · 4129 B

1// nx_creaturegen_gate.nx -- prove procedural ANIMALS via the shared layered-anatomy method. 2// T1 a creature builds (skeleton+muscle parts) and renders as a coherent quadruped skin envelope 3// T2 ★VARIETY: different seeds -> different creatures (render L1 large -- varied proportions) 4// T3 determinism + gallery PNG knowledge/nx_creaturegen.png (3 creatures) 5// D001 MIGRATION 2026-09-02 (procgen PG19): the verdict was hand-rolled (PASS/FAIL prints, a fails counter, sys_exit(1)), so 6// /api/promote refused it and nothing outside could read its outcome. Every tooth is now a gv_check and the exit code IS the 7// verdict (nx_gate_verdict). The measurements, thresholds and the gallery are unchanged. 8// license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_gate_verdict.nx" 11import "nx_png.nx" 12import "nx_creaturegen.nx" 13 14func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 15func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 } 16func lum(px: i64) -> i64 { return (px&255)+((px>>8)&255)+((px>>16)&255) } 17func L1(a: *i64, b: *i64, n: i64) -> i64 { var s: i64=0; var i: i64=0; while i<n { var d: i64=(a[i]&255)-(b[i]&255); if d<0{d=0-d} s=s+d; i=i+1 } return s } 18 19const YAW: i64 = 4800 20const CZ: i64 = 4 21 22func main() -> i64 { 23 hw("=== nx_creaturegen_gate -- procedural animals via layered anatomy (skeleton->muscle->skin) ===\n" as *u8) 24 let ctr: *i64 = gv_ctr() 25 let W: i64 = as_w(); let H: i64 = as_h(); let npx: i64 = W*H 26 let P: *i64 = sys_mmap(96*AS_STRIDE*8) as *i64 27 let f0: *i64 = sys_mmap(npx*8) as *i64 28 let f1: *i64 = sys_mmap(npx*8) as *i64 29 let f2: *i64 = sys_mmap(npx*8) as *i64 30 31 let n0: i64 = creaturegen_build(P, 4) 32 anatstack_render(P, n0, YAW, CZ, 1, 45, 172, 140, 106, f0) 33 let n1: i64 = creaturegen_build(P, 29) 34 anatstack_render(P, n1, YAW, CZ, 1, 45, 158, 132, 104, f1) 35 let n2: i64 = creaturegen_build(P, 63) 36 anatstack_render(P, n2, YAW, CZ, 1, 45, 180, 150, 116, f2) 37 hw(" parts/creature="); pn(n0); hw("\n" as *u8) 38 39 var body: i64 = 0 40 var i: i64 = 0 41 while i < npx { if lum(f0[i]) > 150 { body = body + 1 } i=i+1 } 42 hw(" creature0 body px="); pn(body); hw("\n" as *u8) 43 var T1: i64 = 0 44 if n0 > 24 { if body > 9500 { T1 = 1 } } 45 gv_check("T1 a quadruped builds and renders: skin envelope over skeleton and muscle (parts over 24, body px over 9500)" as *u8, T1, ctr) 46 47 let d01: i64 = L1(f0, f1, npx); let d02: i64 = L1(f0, f2, npx); let d12: i64 = L1(f1, f2, npx) 48 hw(" variety L1: c0-c1="); pn(d01); hw(" c0-c2="); pn(d02); hw(" c1-c2="); pn(d12); hw("\n" as *u8) 49 var T2: i64 = 0 50 if d01 > 400000 { if d02 > 400000 { if d12 > 400000 { T2 = 1 } } } 51 gv_check("T2 variety: three seeds render three creatures, pairwise L1 apart by more than 400000" as *u8, T2, ctr) 52 53 let chk: *i64 = sys_mmap(npx*8) as *i64 54 let nc: i64 = creaturegen_build(P, 29) 55 anatstack_render(P, nc, YAW, CZ, 1, 45, 158, 132, 104, chk) 56 var ddet: i64 = 0 57 i = 0 58 while i < npx { if chk[i]!=f1[i] { ddet=ddet+1 } i=i+1 } 59 var T3: i64 = 0 60 if ddet == 0 { T3 = 1 } 61 hw(" determinism differing px="); pn(ddet); hw("\n" as *u8) 62 gv_check("T3 determinism: the same seed renders the identical creature, zero differing pixels" as *u8, T3, ctr) 63 64 let GW: i64 = W*3 65 let gal: *i64 = sys_mmap(GW*H*8) as *i64 66 var y: i64 = 0 67 while y < H { var x: i64=0; while x<W { gal[y*GW+x]=f0[y*W+x]; gal[y*GW+W+x]=f1[y*W+x]; gal[y*GW+W*2+x]=f2[y*W+x]; x=x+1 } y=y+1 } 68 write_png(gal, GW, H, "knowledge/nx_creaturegen.png" as *u8) 69 hw("T4 gallery -> knowledge/nx_creaturegen.png (seed4 | seed29 | seed63)\n" as *u8) 70 71 return gv_verdict("nx_creaturegen_gate" as *u8, ctr, "procedural animals from the one layered-anatomy method (skeleton, muscle, skin), sovereign, no ML, no assets; gallery at knowledge/nx_creaturegen.png" as *u8) 72}