code wiki / _hdl_build / nx_procgen_human_gate.nx

nx_procgen_human_gate.nx source

↩ module page · 193 lines · 10385 B

1// nx_procgen_human_gate.nx -- Gx/PROCGEN: parametric human figures from the eye-keystone ANTHROPOMETRIC CANON 2// (phi/Vitruvian/Loomis). The companion half of "don't overfit to one human": each figure's measurements are 3// canon RATIOS of one keystone (head height), seed-varied WITHIN canon ranges -> diverse but always canon-valid. 4// 5 seeds side-by-side. Integer/sovereign/asset-free. HONEST: this is parametric-PROPORTION diversity (a clean 5// mannequin), NOT photoreal fidelity -- the same clay gap named on /world/graphics. It proves canon-valid variety. 6// D001 MIGRATION 2026-09-02 (procgen PG19): hand-rolled PASS/FAIL prints, a fails counter and sys_exit(1) replaced by gv_check 7// per tooth and gv_verdict, so the exit code IS the verdict; measurements, thresholds and the PNG are unchanged. 8// license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_gate_verdict.nx" 11import "nx_png_write.nx" 12 13func ph_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 14func ph_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 } 15func ph_rng(seed: i64, salt: i64) -> i64 { var a: i64=(seed+1)*2654435761 + (salt+1)*40503; a=a%2147483647; if a<0{a=a+2147483647} a=(a*1103515245+12345)%2147483647; if a<0{a=a+2147483647} return a } 16// pick in [lo,hi] from seed/salt 17func ph_pick(seed: i64, salt: i64, lo: i64, hi: i64) -> i64 { let r: i64=ph_rng(seed,salt); return lo + r%(hi-lo+1) } 18 19func main() -> i64 { 20 ph_puts("=== nx_procgen_human_gate -- parametric canon-diverse human figures (companion, no overfit) ===\n" as *u8) 21 let ctr: *i64=gv_ctr() 22 let CW: i64=180; let W: i64=CW*5; let H: i64=280 23 let rgb: *u8=sys_mmap(W*H*3+16) 24 var i: i64=0 25 while i<W*H { let o: i64=i*3; rgb[o]=16 as u8; rgb[o+1]=18 as u8; rgb[o+2]=26 as u8; i=i+1 } 26 // per-figure canon params, stored for the gate 27 let pheads: *i64=sys_mmap(5*8) as *i64 28 let pshw: *i64=sys_mmap(5*8) as *i64 29 let pwsw: *i64=sys_mmap(5*8) as *i64 30 let phpw: *i64=sys_mmap(5*8) as *i64 31 let pnavel: *i64=sys_mmap(5*8) as *i64 32 var totallit: i64=0 33 var s: i64=0 34 while s<5 { 35 let seed: i64=s*1013 + 7 36 // CANON: total height = heads*head_h ; 1 head = 7 eye-widths ; measures = ratio_ew * head_h / 7 37 let heads10: i64=ph_pick(seed,1,70,80) // 7.0..8.0 heads 38 let Hfig: i64=228 39 let hh: i64=(Hfig*10)/heads10 // head height px 40 let ytop: i64=H-16-Hfig // top of head 41 let base: i64=H-16 // feet baseline 42 let cx: i64=s*CW + CW/2 43 // canon eye-width ratios (x10) -> px half-widths 44 let shoulder_ew10: i64=ph_pick(seed,2,130,180) // 13..18 ew 45 let waist_ew10: i64=ph_pick(seed,3,32,52) // 3.2..5.2 ew 46 let hip_ew10: i64=ph_pick(seed,4,46,66) // 4.6..6.6 ew 47 let sh_hw: i64=(shoulder_ew10*hh)/70/2 // (ew10/10 * hh/7)/2 48 var ws_hw: i64=(waist_ew10*hh)/70/2 49 let hp_hw: i64=(hip_ew10*hh)/70/2 50 if ws_hw<3 { ws_hw=3 } 51 pheads[s]=heads10; pshw[s]=sh_hw*2; pwsw[s]=ws_hw*2; phpw[s]=hp_hw*2 52 // key Y (from top, in head units) 53 let y_chin: i64=ytop+hh 54 let y_shoulder: i64=ytop+(hh*13)/10 55 let y_waist: i64=ytop+hh*3 56 let y_hip: i64=ytop+(hh*35)/10 57 pnavel[s]=(base-y_waist)*1000/Hfig // navel-from-ground / height *1000 (canon ~618) 58 // skin tone (seed-varied) 59 let tone: i64=ph_pick(seed,5,0,4) 60 var skr: i64=224; var skg: i64=172; var skb: i64=138 61 if tone==1 { skr=196; skg=140; skb=108 } 62 if tone==2 { skr=150; skg=100; skb=72 } 63 if tone==3 { skr=110; skg=72; skb=52 } 64 if tone==4 { skr=238; skg=200; skb=170 } 65 // ---- draw torso silhouette (shoulder -> waist -> hip), volume-shaded ---- 66 var py: i64=y_shoulder 67 while py<=y_hip { 68 var hw: i64=0 69 if py<=y_waist { let t: i64=((py-y_shoulder)*1000)/(y_waist-y_shoulder+1); hw=sh_hw+((ws_hw-sh_hw)*t)/1000 } 70 else { let t: i64=((py-y_waist)*1000)/(y_hip-y_waist+1); hw=ws_hw+((hp_hw-ws_hw)*t)/1000 } 71 var px: i64=cx-hw 72 while px<=cx+hw { 73 // simple center-lit volume shade 74 var d: i64=px-cx; if d<0 {d=0-d} 75 var sh: i64=255 - (d*90)/(hw+1) 76 if sh<120 {sh=120} 77 if px>=0 { if px<W { if py>=0 { if py<H { 78 let o: i64=(py*W+px)*3 79 rgb[o]=((skr*sh)/255) as u8; rgb[o+1]=((skg*sh)/255) as u8; rgb[o+2]=((skb*sh)/255) as u8 80 totallit=totallit+1 81 } } } } 82 px=px+1 83 } 84 py=py+1 85 } 86 // ---- legs: hip -> feet, two tapered bars ---- 87 var lg: i64=0 88 while lg<2 { 89 let lx0: i64=cx + (lg*2-1)*(hp_hw/2) 90 var yy: i64=y_hip 91 while yy<=base { 92 let t: i64=((yy-y_hip)*1000)/(base-y_hip+1) 93 let lw: i64=(hp_hw*6)/10 - ((hp_hw*4)/10 * t)/1000 // thigh -> ankle taper 94 var px: i64=lx0-lw 95 while px<=lx0+lw { 96 if px>=0 { if px<W { if yy>=0 { if yy<H { 97 var d: i64=px-lx0; if d<0 {d=0-d} 98 var sh: i64=255-(d*100)/(lw+1); if sh<115 {sh=115} 99 let o: i64=(yy*W+px)*3 100 rgb[o]=((skr*sh)/255) as u8; rgb[o+1]=((skg*sh)/255) as u8; rgb[o+2]=((skb*sh)/255) as u8 101 } } } } 102 px=px+1 103 } 104 yy=yy+1 105 } 106 lg=lg+1 107 } 108 // ---- arms: shoulder -> down the sides, two tapered bars ---- 109 var ar: i64=0 110 while ar<2 { 111 let axs: i64=cx + (ar*2-1)*sh_hw 112 let axe: i64=cx + (ar*2-1)*(hp_hw+ (hh*7)/10) 113 var yy: i64=y_shoulder 114 let armlen: i64=(hh*33)/10 115 let yend: i64=y_shoulder+armlen 116 while yy<=yend { 117 let t: i64=((yy-y_shoulder)*1000)/(armlen+1) 118 let ax: i64=axs + ((axe-axs)*t)/1000 119 let aw: i64=(hh*4)/10 - ((hh*25)/100 * t)/1000 120 var px: i64=ax-aw 121 while px<=ax+aw { 122 if px>=0 { if px<W { if yy>=0 { if yy<H { 123 var d: i64=px-ax; if d<0 {d=0-d} 124 var sh: i64=255-(d*100)/(aw+1); if sh<115 {sh=115} 125 let o: i64=(yy*W+px)*3 126 rgb[o]=((skr*sh)/255) as u8; rgb[o+1]=((skg*sh)/255) as u8; rgb[o+2]=((skb*sh)/255) as u8 127 } } } } 128 px=px+1 129 } 130 yy=yy+1 131 } 132 ar=ar+1 133 } 134 // ---- neck + head (ellipse: w=5ew, h=7ew=hh) ---- 135 let neckw: i64=(hh*13)/100 136 var ny: i64=y_chin-2 137 while ny<=y_shoulder { var px: i64=cx-neckw; while px<=cx+neckw { if px>=0 { if px<W { let o: i64=(ny*W+px)*3; rgb[o]=((skr*220)/255) as u8; rgb[o+1]=((skg*220)/255) as u8; rgb[o+2]=((skb*220)/255) as u8 } } px=px+1 } ny=ny+1 } 138 let hrx: i64=(hh*5)/14; let hry: i64=hh/2; let hcx: i64=cx; let hcy: i64=ytop+hry 139 var ey: i64=hcy-hry 140 while ey<=hcy+hry { 141 var ex: i64=hcx-hrx 142 while ex<=hcx+hrx { 143 let dxv: i64=ex-hcx; let dyv: i64=ey-hcy 144 if (dxv*dxv)*(hry*hry) + (dyv*dyv)*(hrx*hrx) <= (hrx*hrx)*(hry*hry) { 145 if ex>=0 { if ex<W { if ey>=0 { if ey<H { 146 var d: i64=ex-hcx; if d<0 {d=0-d} 147 var sh: i64=255-(d*80)/(hrx+1); if sh<140 {sh=140} 148 let o: i64=(ey*W+ex)*3 149 rgb[o]=((skr*sh)/255) as u8; rgb[o+1]=((skg*sh)/255) as u8; rgb[o+2]=((skb*sh)/255) as u8 150 totallit=totallit+1 151 } } } } 152 } 153 ex=ex+1 154 } 155 ey=ey+1 156 } 157 ph_puts(" fig "); ph_pn(s); ph_puts(": heads="); ph_pn(heads10); ph_puts(" shoulder_ew="); ph_pn(shoulder_ew10); ph_puts(" waist_ew="); ph_pn(waist_ew10); ph_puts(" navel/h*1000="); ph_pn(pnavel[s]); ph_puts("\n" as *u8) 158 s=s+1 159 } 160 nx_png_write_rgb("knowledge/nx_procgen_human.png\x00" as *u8, rgb, W, H) 161 ph_puts(" wrote knowledge/nx_procgen_human.png\n" as *u8) 162 // T1 rendered 163 var t1: i64=0 164 if totallit>3000 { t1=1 } 165 gv_check("T1 five figures rendered (lit pixels over 3000)" as *u8, t1, ctr) 166 // T2 canon-valid: heads in [70,80]; navel/height in golden band [560,680] (~1/phi=618); shoulder>waist 167 var t2: i64=1 168 var k: i64=0 169 while k<5 { 170 if pheads[k]<70 { t2=0 } if pheads[k]>80 { t2=0 } 171 if pnavel[k]<540 { t2=0 } if pnavel[k]>700 { t2=0 } 172 if pshw[k]<=pwsw[k] { t2=0 } 173 k=k+1 174 } 175 ph_puts(" canon check: navel-golden-band + heads 7-8 + shoulder>waist\n" as *u8) 176 gv_check("T2 every figure is canon-valid: navel in the golden band, 7 to 8 heads tall, shoulders wider than waist" as *u8, t2, ctr) 177 // T3 diversity 178 var dmax: i64=0; var dmin: i64=9999 179 k=0 180 while k<5 { if pshw[k]>dmax {dmax=pshw[k]} if pshw[k]<dmin {dmin=pshw[k]} k=k+1 } 181 ph_puts(" shoulder-width spread="); ph_pn(dmax-dmin); ph_puts("\n" as *u8) 182 var t3: i64=0 183 if dmax-dmin>10 { t3=1 } 184 gv_check("T3 figures are diverse: shoulder-width spread over 10 across the five seeds (parametric, no overfit to one human)" as *u8, t3, ctr) 185 // T4 png 186 let szp: *i64=sys_mmap(16) as *i64 187 let rb: *u8=sys_read_file("knowledge/nx_procgen_human.png\x00" as *u8, szp) 188 var t4: i64=0 189 if (rb as i64)!=0 { if szp[0]>1000 { t4=1 } } 190 if (rb as i64)!=0 { ph_puts(" png bytes="); ph_pn(szp[0]); ph_puts("\n" as *u8) } 191 gv_check("T4 the five-figure PNG was written and reads back over 1000 bytes" as *u8, t4, ctr) 192 return gv_verdict("nx_procgen_human_gate" as *u8, ctr, "canon-valid parametric human diversity (companion to the creature and terrain rungs, no overfit), sovereign integer; a clean mannequin, not photoreal" as *u8) 193}