omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / aienux / allen / tests / font-render.om
| 1 | note Actual native 768x384 printable-ASCII specimen; no image generator. |
| 2 | note Uses the shared bounded RGB surface storage. |
| 3 | global Fpose long 2 |
| 4 | text Fontppm "P6\n768 384\n255\n" |
| 5 | fn fblend bg ulong fg ulong a ulong to uchar |
| 6 | n = mul bg sub ulong 255 a |
| 7 | n = add n mul fg a |
| 8 | ret uchar div n 255 |
| 9 | end |
| 10 | fn fpixel x long y long a uchar to void |
| 11 | if or lt x 0 ge x 768 |
| 12 | ret |
| 13 | end |
| 14 | if or lt y 0 ge y 384 |
| 15 | ret |
| 16 | end |
| 17 | at = mul add mul ulong y 768 ulong x 3 |
| 18 | alpha = ulong a |
| 19 | put Canvas at fblend 6 236 alpha |
| 20 | put Canvas add at 1 fblend 8 240 alpha |
| 21 | put Canvas add at 2 fblend 18 252 alpha |
| 22 | end |
| 23 | fn frow yy ulong to void |
| 24 | y = add get Fpose 1 long yy |
| 25 | at = mul yy get Af 3 |
| 26 | for x ulong get Af 3 |
| 27 | px = add get Fpose 0 long x |
| 28 | a = get Alpha add at x |
| 29 | fpixel px y a |
| 30 | end |
| 31 | end |
| 32 | fn fdraw px long py long to void |
| 33 | put Fpose 0 add px get Ab 0 |
| 34 | put Fpose 1 add py get Ab 1 |
| 35 | for y ulong get Af 4 |
| 36 | frow y |
| 37 | end |
| 38 | end |
| 39 | fn foutput to bool |
| 40 | p = ulong 0 |
| 41 | while lt p len Fontppm |
| 42 | n = write 1 Fontppm p sub len Fontppm p |
| 43 | if le n 0 |
| 44 | ret false |
| 45 | end |
| 46 | p = add p ulong n |
| 47 | end |
| 48 | p = 0 |
| 49 | while lt p len Canvas |
| 50 | n = write 1 Canvas p sub len Canvas p |
| 51 | if le n 0 |
| 52 | ret false |
| 53 | end |
| 54 | p = add p ulong n |
| 55 | end |
| 56 | ret true |
| 57 | end |
| 58 | fn main to int |
| 59 | if not afinit 30 1250 |
| 60 | ret 1 |
| 61 | end |
| 62 | for i ulong mul ulong 768 384 |
| 63 | put Canvas mul i 3 6 |
| 64 | put Canvas add mul i 3 1 8 |
| 65 | put Canvas add mul i 3 2 18 |
| 66 | end |
| 67 | for i ulong 95 |
| 68 | if not afglyph uchar add i 32 |
| 69 | ret 1 |
| 70 | end |
| 71 | x = long add mul rem i 16 48 8 |
| 72 | y = long add mul div i 16 64 45 |
| 73 | fdraw x y |
| 74 | end |
| 75 | if not foutput |
| 76 | ret 74 |
| 77 | end |
| 78 | ret 0 |
| 79 | end |