Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

16 segment display inspired font rendering

edited December 2011 in Code Sharing Posts: 4

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.



  • edited December 2011 Posts: 4

    Example usage, measuring and centering a string:


    say = "HELLO WORLD. 2012 IS ALMOST HERE"


  • I really like the system you have for this.

  • Posts: 176

    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

    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.

  • Posts: 176

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

  • Posts: 176

    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.

Sign In or Register to comment.