Log In  

This is a replacement for print() that draws a customizable 5x6 font. It encodes each character as one number, and then loops through each pixel checking to see if that bit is set. So it's not very fast, but is handy if you just want a quick solution for some text larger than 3x5.

Cartridge for generating and testing font:

Cart #font_5x6-4 | 2019-01-13 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
31

The spritesheet and the convert() function is not needed in the release version of a cart. Paste the following snippet into your code (and optionally replace fdat with your own data):

fdat = [[  0000.0000! 739c.e038" 5280.0000# 02be.afa8$ 23e8.e2f8% 0674.45cc& 6414.c934' 2100.0000( 3318.c618) 618c.6330* 012a.ea90+ 0109.f210, 0000.0230- 0000.e000. 0000.0030/ 3198.cc600 fef7.bdfc1 f18c.637c2 f8ff.8c7c3 f8de.31fc4 defe.318c5 fe3e.31fc6 fe3f.bdfc7 f8cc.c6308 feff.bdfc9 fefe.31fc: 0300.0600; 0300.0660< 0199.8618= 001c.0700> 030c.3330? f0c6.e030@ 746f.783ca 76f7.fdecb f6fd.bdf8c 76f1.8db8d f6f7.bdf8e 7e3d.8c3cf 7e3d.8c60g 7e31.bdbch deff.bdeci f318.c678j f98c.6370k def9.bdecl c631.8c7cm dfff.bdecn f6f7.bdeco 76f7.bdb8p f6f7.ec60q 76f7.bf3cr f6f7.cdecs 7e1c.31f8t fb18.c630u def7.bdb8v def7.b710w def7.ffecx dec9.bdecy defe.31f8z f8cc.cc7c[ 7318.c638\ 630c.618c] 718c.6338^ 2280.0000_ 0000.007c``4100.0000`a001f.bdf4`bc63d.bdfc`c001f.8c3c`d18df.bdbc`e001d.be3c`f3b19.f630`g7ef6.f1fa`hc63d.bdec`i6018.c618`j318c.6372`kc6f5.cd6c`l6318.c618`m0015.fdec`n003d.bdec`o001f.bdf8`pf6f7.ec62`q7ef6.f18e`r001d.bc60`s001f.c3f8`t633c.c618`u0037.bdbc`v0037.b510`w0037.bfa8`x0036.edec`ydef6.f1ba`z003e.667c{ 0188.c218| 0108.4210} 0184.3118~ 02a8.0000`*013e.e500]]
cmap={}
for i=0,#fdat/11 do
 local p=1+i*11
 cmap[sub(fdat,p,p+1)]=
  tonum("0x"..sub(fdat,p+2,p+10))
end

function pr(str,sx,sy,col)
 local sx0=sx
 local p=1
 while (p <= #str) do
  local c=sub(str,p,p)
  local v 

  if (c=="\n") then
   -- linebreak
   sy+=9 sx=sx0 
  else
      -- single (a)
      v = cmap[c.." "] 
      if not v then 
       -- double (`a)
       v= cmap[sub(str,p,p+1)]
       p+=1
      end

   --adjust height
   local sy1=sy
   if (band(v,0x0.0002)>0)sy1+=2

   -- draw pixels
   for y=sy1,sy1+5 do
       for x=sx,sx+4 do
        if (band(v,0x8000)<0) pset(x,y,col)
        v=rotl(v,1)
       end
      end
      sx+=6
  end
  p+=1
 end
end

The fdat in that snippet has lower case letters and a star character mapped to `a..`z and `*
Unlike print(), you need to specify all 4 parameters (string,x,y,col):

pr("`*`* H`e`l`l`o W`o`r`l`d `*`*",10,60,11)
P#60769 2019-01-13 08:50

Again, this is great stuff - thanks @zep! :D

And I see that it's customisable too
(for those that can decipher the fdat!)
Nice!

P#60788 2019-01-13 10:07 ( Edited 2019-01-13 10:07)

Nice! Lower caaaaase! I remember jumping through hoops on the Apple ][+ for lowercase, before the glory of the Apple //e!

P#62857 2019-03-17 18:06
1

nice-looking font! I've formatted it for use with load #font_snippet (https://www.lexaloffle.com/bbs/?tid=41544) which might be useful to someone:

edit: and here's the poke code:

poke(unpack(split"0x5600,6,8,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,7,7,7,7,0,0,0,0,7,7,7,0,0,0,0,0,7,5,7,0,0,0,0,0,5,2,5,0,0,0,0,0,5,0,5,0,0,0,0,0,5,5,5,0,0,0,0,4,6,7,6,4,0,0,0,1,3,7,3,1,0,0,0,7,1,1,1,0,0,0,0,0,4,4,4,7,0,0,0,5,7,2,7,2,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,2,0,0,0,0,0,0,3,3,0,0,0,5,5,0,0,0,0,0,0,2,5,2,0,0,0,0,0,0,0,0,0,0,0,0,0,14,14,14,14,0,14,0,0,10,10,0,0,0,0,0,0,0,10,31,10,31,10,0,0,4,30,5,14,20,15,0,0,0,19,11,4,26,25,0,0,6,1,10,6,9,22,0,0,4,4,0,0,0,0,0,0,12,6,6,6,6,12,0,0,6,12,12,12,12,6,0,0,0,4,21,14,21,4,0,0,0,4,4,31,4,4,0,0,0,0,0,0,4,6,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,6,0,0,12,12,6,6,3,3,0,0,31,27,27,27,27,31,0,0,15,12,12,12,12,31,0,0,31,24,31,3,3,31,0,0,31,24,30,24,24,31,0,0,27,27,31,24,24,24,0,0,31,3,31,24,24,31,0,0,31,3,31,27,27,31,0,0,31,24,12,6,6,6,0,0,31,27,31,27,27,31,0,0,31,27,31,24,24,31,0,0,0,6,0,0,6,0,0,0,0,6,0,0,6,3,0,0,0,12,6,3,6,12,0,0,0,0,14,0,14,0,0,0,0,6,12,24,12,6,0,0,15,24,24,14,0,6,0,0,14,17,29,29,1,30,0,0,0,0,30,27,27,23,0,0,3,3,15,27,27,31,0,0,0,0,30,3,3,30,0,0,24,24,30,27,27,30,0,0,0,0,14,27,7,30,0,0,28,6,6,31,6,6,0,0,0,0,30,27,27,30,24,15,3,3,15,27,27,27,0,0,6,0,6,6,6,12,0,0,0,0,12,12,12,12,12,7,3,27,11,7,11,27,0,0,6,6,6,6,6,12,0,0,0,0,10,31,27,27,0,0,0,0,15,27,27,27,0,0,0,0,30,27,27,15,0,0,0,0,15,27,27,15,3,3,0,0,30,27,27,30,24,24,0,0,14,27,3,3,0,0,0,0,30,7,28,15,0,0,6,6,15,6,6,12,0,0,0,0,27,27,27,30,0,0,0,0,27,27,10,4,0,0,0,0,27,27,31,10,0,0,0,0,27,14,27,27,0,0,0,0,27,27,27,30,24,14,0,0,31,12,6,31,0,0,14,6,6,6,6,14,0,0,6,6,12,12,24,24,0,0,14,12,12,12,12,14,0,0,4,10,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2,4,0,0,0,0,0,0,14,27,27,31,27,27,0,0,15,27,15,27,27,15,0,0,14,27,3,3,27,14,0,0,15,27,27,27,27,15,0,0,30,3,15,3,3,30,0,0,30,3,15,3,3,3,0,0,30,3,3,27,27,30,0,0,27,27,31,27,27,27,0,0,15,6,6,6,6,15,0,0,31,12,12,12,12,7,0,0,27,27,7,27,27,27,0,0,3,3,3,3,3,31,0,0,27,31,31,27,27,27,0,0,15,27,27,27,27,27,0,0,14,27,27,27,27,14,0,0,15,27,27,15,3,3,0,0,14,27,27,27,15,30,0,0,15,27,27,7,27,27,0,0,30,3,14,24,24,15,0,0,31,6,6,6,6,6,0,0,27,27,27,27,27,14,0,0,27,27,27,27,14,4,0,0,27,27,27,31,31,27,0,0,27,27,4,27,27,27,0,0,27,27,31,24,24,15,0,0,31,24,12,6,3,31,0,0,12,4,6,6,4,12,0,0,6,6,6,6,6,6,0,0,12,8,24,24,8,12,0,0,0,10,5,0,0,0,0,0,0,4,31,14,10,0,0,0,127,127,127,127,127,0,0,0,85,42,85,42,85,0,0,0,65,127,93,93,62,0,0,0,62,99,99,119,62,0,0,0,17,68,17,68,17,0,0,0,4,60,28,30,16,0,0,0,28,46,62,62,28,0,0,0,54,62,62,28,8,0,0,0,28,54,119,54,28,0,0,0,28,28,62,28,20,0,0,0,28,62,127,42,58,0,0,0,62,103,99,103,62,0,0,0,127,93,127,65,127,0,0,0,56,8,8,14,14,0,0,0,62,99,107,99,62,0,0,0,8,28,62,28,8,0,0,0,0,0,85,0,0,0,0,0,62,115,99,115,62,0,0,0,8,28,127,62,34,0,0,0,62,28,8,28,62,0,0,0,62,119,99,99,62,0,0,0,0,5,82,32,0,0,0,0,0,17,42,68,0,0,0,0,62,107,119,107,62,0,0,0,127,0,127,0,127,0,0,0,85,85,85,85,85,0,0,0,14,4,30,45,38,0,0,0,17,33,33,37,2,0,0,0,12,30,32,32,28,0,0,0,8,30,8,36,26,0,0,0,78,4,62,69,38,0,0,0,34,95,18,18,10,0,0,0,30,8,60,17,6,0,0,0,16,12,2,12,16,0,0,0,34,122,34,34,18,0,0,0,30,32,0,2,60,0,0,0,8,60,16,2,12,0,0,0,2,2,2,34,28,0,0,0,8,62,8,12,8,0,0,0,18,63,18,2,28,0,0,0,60,16,126,4,56,0,0,0,2,7,50,2,50,0,0,0,15,2,14,16,28,0,0,0,62,64,64,32,24,0,0,0,62,16,8,8,16,0,0,0,8,56,4,2,60,0,0,0,50,7,18,120,24,0,0,0,122,66,2,10,114,0,0,0,9,62,75,109,102,0,0,0,26,39,34,115,50,0,0,0,60,74,73,73,70,0,0,0,18,58,18,58,26,0,0,0,35,98,34,34,28,0,0,0,12,0,8,42,77,0,0,0,0,12,18,33,64,0,0,0,125,121,17,61,93,0,0,0,62,60,8,30,46,0,0,0,6,36,126,38,16,0,0,0,36,78,4,70,60,0,0,0,10,60,90,70,48,0,0,0,30,4,30,68,56,0,0,0,20,62,36,8,8,0,0,0,58,86,82,48,8,0,0,0,4,28,4,30,6,0,0,0,8,2,62,32,28,0,0,0,34,34,38,32,24,0,0,0,62,24,36,114,48,0,0,0,4,54,44,38,100,0,0,0,62,24,36,66,48,0,0,0,26,39,34,35,18,0,0,0,14,100,28,40,120,0,0,0,4,2,6,43,25,0,0,0,0,0,14,16,8,0,0,0,0,10,31,18,4,0,0,0,0,4,15,21,13,0,0,0,0,4,12,6,14,0,0,0,62,32,20,4,2,0,0,0,48,8,14,8,8,0,0,0,8,62,34,32,24,0,0,0,62,8,8,8,62,0,0,0,16,126,24,20,18,0,0,0,4,62,36,34,50,0,0,0,8,62,8,62,8,0,0,0,60,36,34,16,8,0,0,0,4,124,18,16,8,0,0,0,62,32,32,32,62,0,0,0,36,126,36,32,16,0,0,0,6,32,38,16,12,0,0,0,62,32,16,24,38,0,0,0,4,62,36,4,56,0,0,0,34,36,32,16,12,0,0,0,62,34,45,48,12,0,0,0,28,8,62,8,4,0,0,0,42,42,32,16,12,0,0,0,28,0,62,8,4,0,0,0,4,4,28,36,4,0,0,0,8,62,8,8,4,0,0,0,0,28,0,0,62,0,0,0,62,32,40,16,44,0,0,0,8,62,48,94,8,0,0,0,32,32,32,16,14,0,0,0,16,36,36,68,66,0,0,0,2,30,2,2,28,0,0,0,62,32,32,16,12,0,0,0,12,18,33,64,0,0,0,0,8,62,8,42,42,0,0,0,62,32,20,8,16,0,0,0,60,0,62,0,30,0,0,0,8,4,36,66,126,0,0,0,64,40,16,104,6,0,0,0,30,4,30,4,60,0,0,0,4,62,36,4,4,0,0,0,28,16,16,16,62,0,0,0,30,16,30,16,30,0,0,0,62,0,62,32,24,0,0,0,36,36,36,32,16,0,0,0,20,20,20,84,50,0,0,0,2,2,34,18,14,0,0,0,62,34,34,34,62,0,0,0,62,34,32,16,12,0,0,0,62,32,60,32,24,0,0,0,6,32,32,16,14,0,0,0,0,21,16,8,6,0,0,0,0,4,30,20,4,0,0,0,0,0,12,8,30,0,0,0,0,28,24,16,28,0,0,0,8,4,99,16,8,0,0,0,8,16,99,4,8,0,0,0"))
P#101394 2021-12-04 00:45 ( Edited 2021-12-05 11:02)
1

Thanks for the picture! Could you share the resulting poke code?

I have my own unfinished font tool, it produces poke4 calls with hex literals; I should generate both formats and compare character size!

P#101414 2021-12-04 02:42 ( Edited 2021-12-04 02:42)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 12:26:01 | 0.015s | Q:23