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
ID | Author/Program | Comment | Date | |
---|---|---|---|---|
878 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { fontEnv = newCleanEnv() loadSnippet("#92", fontEnv)() get("#109") -- copyRect -- size of chars cw, ch = 16, 16 -- original text otext = {"!\"#$%&'()*+,-./0123456789:;<=>?@", "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`", "abcdefghijklmnopqrstuvwxyz{|}~ " } function render(text) newtext = text or "Hello world!" width=cw*#newtext height=ch pixels={} for i=1, #newtext do j = nil for line=1, #otext do local c = newtext:sub(i, i) j = otext[line]:find(c, 1, true) --print("line="..tostring(line)..", c="..c..", j="..tostring(j)) if j then l = line; break end end if j then --print("j="..tostring(j)..", l="..tostring(l)) copyRect(fontEnv, _G, (j-1)*cw, (l-1)*ch, cw, ch, (i-1)*cw, 0) end end end }} | 2015-08-19 22:48:37 | delete |
753 | #1000604 (pitcher) | 2015-08-18 00:07:22 |
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: | 1445 / 824 |
Referenced in: | [show references] |