code wiki / _hdl_build / nx_glyph_word.nx

nx_glyph_word.nx source

↩ module page · 70 lines · 3421 B

1// nx_glyph_word.nx -- RUNG 1 proof: render "nishi" (lowercase, the brand) with the STROKE PEN. Each letter is 2// just centerline polylines + a width -> the n/h arches and the s-spine (the HARD curvy bits) are trivial. 3// Renders AA -> _offc/nx_aa_nishi.png. This is the builder unit that scales to kanji (kanji strokes are the same). 4import "nx_glyph_stroke.nx" 5import "nx_aa_raster.nx" 6import "nx_png_write.nx" 7const K_MAGIC_8192: i64 = 8192 8const K_MAGIC_1024: i64 = 1024 9 10// helper: set a 2-point vertical stem path and stroke it 11func put_stroke(xs: *i64, ys: *i64, cstart: *i64, clen: *i64, np: *i64, nc: *i64, cs: *i64, sn: *i64, ptsx: *i64, ptsy: *i64, n: i64, w: i64) -> i64 { 12 gs_stroke(xs, ys, cstart, clen, np, nc, cs, sn, ptsx, ptsy, n, w) 13 return 0 14} 15 16func main() -> i64 { 17 let W: i64 = 170 18 let H: i64 = 120 19 let ss: i64 = 4 // grid 680 x 480 20 21 let cs: *i64 = sys_mmap(8*16) as *i64 22 let sn: *i64 = sys_mmap(8*16) as *i64 23 gs_init_trig(cs, sn) 24 25 let xs: *i64 = sys_mmap(8*K_MAGIC_8192) as *i64 26 let ys: *i64 = sys_mmap(8*K_MAGIC_8192) as *i64 27 let cstart: *i64 = sys_mmap(8*K_MAGIC_1024) as *i64 28 let clen: *i64 = sys_mmap(8*K_MAGIC_1024) as *i64 29 let np: *i64 = sys_mmap(16) as *i64; np[0]=0 30 let nc: *i64 = sys_mmap(16) as *i64; nc[0]=0 31 32 let WID: i64 = 34 // stroke weight 33 let ax: *i64 = sys_mmap(8*16) as *i64 // scratch path x 34 let ay: *i64 = sys_mmap(8*16) as *i64 // scratch path y 35 36 // ---- n @ 50 ---- stem + arch 37 ax[0]=50; ay[0]=360; ax[1]=50; ay[1]=180 38 put_stroke(xs,ys,cstart,clen,np,nc,cs,sn, ax,ay,2, WID) 39 ax[0]=50; ay[0]=215; ax[1]=62;ay[1]=188; ax[2]=88;ay[2]=178; ax[3]=114;ay[3]=178; ax[4]=140;ay[4]=188; ax[5]=150;ay[5]=215; ax[6]=150;ay[6]=360 40 put_stroke(xs,ys,cstart,clen,np,nc,cs,sn, ax,ay,7, WID) 41 // ---- i @ 190 ---- stem + dot 42 ax[0]=190; ay[0]=360; ax[1]=190; ay[1]=180 43 put_stroke(xs,ys,cstart,clen,np,nc,cs,sn, ax,ay,2, WID) 44 gs_disc(xs,ys,cstart,clen,np,nc, cs,sn, 190, 130, 20, 0) 45 // ---- s @ 250 ---- s-spine 46 ax[0]=322;ay[0]=192; ax[1]=296;ay[1]=178; ax[2]=270;ay[2]=186; ax[3]=262;ay[3]=210 47 ax[4]=282;ay[4]=228; ax[5]=312;ay[5]=244; ax[6]=320;ay[6]=270; ax[7]=310;ay[7]=292; ax[8]=282;ay[8]=302; ax[9]=252;ay[9]=292 48 put_stroke(xs,ys,cstart,clen,np,nc,cs,sn, ax,ay,10, 30) 49 // ---- h @ 360 ---- ascender stem + arch 50 ax[0]=360; ay[0]=360; ax[1]=360; ay[1]=80 51 put_stroke(xs,ys,cstart,clen,np,nc,cs,sn, ax,ay,2, WID) 52 ax[0]=360; ay[0]=215; ax[1]=372;ay[1]=188; ax[2]=398;ay[2]=178; ax[3]=424;ay[3]=178; ax[4]=450;ay[4]=188; ax[5]=460;ay[5]=215; ax[6]=460;ay[6]=360 53 put_stroke(xs,ys,cstart,clen,np,nc,cs,sn, ax,ay,7, WID) 54 // ---- i @ 500 ---- stem + dot 55 ax[0]=500; ay[0]=360; ax[1]=500; ay[1]=180 56 put_stroke(xs,ys,cstart,clen,np,nc,cs,sn, ax,ay,2, WID) 57 gs_disc(xs,ys,cstart,clen,np,nc, cs,sn, 500, 130, 20, 0) 58 59 let cov: *u8 = sys_mmap(W*H) 60 aa_render(xs, ys, cstart, clen, nc[0], cov, W, H, ss) 61 62 let rgb: *u8 = sys_mmap(W*H*3) 63 var i: i64 = 0 64 while i < W*H*3 { rgb[i]=255 as u8; i=i+1 } 65 aa_blit(rgb, W, H, 0, 0, cov, W, H, 25, 35, 60) // near-black ink 66 67 nx_png_write_rgb("_offc/nx_aa_nishi.png\x00" as *u8, rgb, W, H) 68 sys_write(1, "nx_glyph_word: wrote _offc/nx_aa_nishi.png\n\x00" as *u8, 43) 69 return 0 70}