1 | fontEnv = newCleanEnv() |
2 | loadSnippet("#92", fontEnv)()
|
3 | |
4 | get("#109") -- copyRect
|
5 | |
6 | -- size of chars |
7 | cw, ch = 16, 16 |
8 | |
9 | -- original text |
10 | otext = {"!\"#$%&'()*+,-./0123456789:;<=>?@",
|
11 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`", |
12 | "abcdefghijklmnopqrstuvwxyz{|}~ "
|
13 | } |
14 | |
15 | function render(text) |
16 | newtext = text or "Hello world!" |
17 | |
18 | width=cw*#newtext |
19 | height=ch |
20 | pixels={}
|
21 | |
22 | for i=1, #newtext do |
23 | j = nil |
24 | for line=1, #otext do |
25 | local c = newtext:sub(i, i) |
26 | j = otext[line]:find(c, 1, true) |
27 | --print("line="..tostring(line)..", c="..c..", j="..tostring(j))
|
28 | if j then l = line; break end |
29 | end |
30 | if j then |
31 | --print("j="..tostring(j)..", l="..tostring(l))
|
32 | copyRect(fontEnv, _G, (j-1)*cw, (l-1)*ch, cw, ch, (i-1)*cw, 0) |
33 | end |
34 | end |
35 | end |
\n\nBegan life as a copy of #178
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
2 comment(s) hidden. show
| Recognizer | Recognition Result | Visualize | Recalc |
|---|---|---|---|
| #308 | 800 | [visualize] |
| Snippet ID: | #186 |
| Snippet name: | Font renderer as function, optimized (Commodore PET font, 16x16) |
| Eternal ID of this version: | #186/1 |
| Text MD5: | 69bfcd501a0007048229bbb2a3118f3f |
| Author: | stefan |
| Category: | font rendering |
| Type: | Lua code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2014-01-25 08:45:47 |
| Source code size: | 800 bytes / 35 lines |
| Pitched / IR pitched: | Yes / Yes |
| Views / Downloads: | 1931 / 905 |
| Referenced in: | [show references] |