16 segment display inspired font rendering

I’ve been using Codea to eat up some of my free time and learn Lua. The quick and dirty font solution I came up with was to simulate the geometry of 16-segment alphanumeric displays drawn as line segments, I will post the character drawing routine for your amusement; note it has to be used with noSmooth() on or else it looks pretty funny. It does only uppercase letters and digits and a few symbols.


Example usage, measuring and centering a string:




I really like the system you have for this.

This will work great for my BlackTower game!

I added a “?” (abgil), changed all the x coordinates for the segments to a variable “n” and use n or n*2 for those coordinates. That way I can change the relative width of the characters. I haven’t figured out the correct method of adjusting the spacing yet, but if = .25 (instead of the original .5) then multiplying x by .75 gives pretty good letter spacing.

One thing I haven’t figured out is why my characters have a dot at each place that the segments touch, and the line isn’t as thin and clear as yours. You can see an example at jlslate.posterous.com/BlackTower

Anyway, thanks, SifakaMon!

You need to do a noSmooth() before drawing the characters because the smooth lines have line end points which are double-drawn using this method thus look pretty bad. As for the aspect ratio of the characters I too decided they were too wide and put an aspect parameter into the draw routine; I will update the pastebin post with it.

I did have the noSmooth in, but it wasn’t in the draw() function. Weird stuff happens when you put that in other places!

Also, I changed the “?” to be “angilq” and changed q to be {n,-.1,n,-.2}. It actually looks ok.

If it helps you can try to translate between my system and yours


I didn’t see a code link there Ipda but it’s not surprising someone else thought of this too! I initially thought about implementing it using bits but it wasn’t fun doing the math in my head or typing “2+4+16” into the editor so I used tables with string keys instead. Easy to change and update too, but probably slower than bit manipulation; then again I don’t know how fast that is in Lua.

Sry :">