Thursday, November 17

Bitmap fonts and the script-fu.


Despite my rant against script-fu, it must be acknowlgeded it's highly useful for getting game art knocked out in double quick time for example, bitmap fonts. Here's a script that can knock one up in a jiffy - it's just a sligtly modified version of a standard script. I'm somewhat dismayed by the size of the .png file.

3 comments:

Christopher Phillips said...

eep.
Please tell me

(define (neon-spline1)
(let* ((a (cons-array 6 'byte)))
(set-pt a 0 0 0)
(set-pt a 1 127 145)
(set-pt a 2 255 255)
a))

isn't idiomatic.

neon_spline1=Numeric.array([[0,0],[127,145],[255,255]])

FWIW,
% wc neon-logo.scm makefont.py
275 972 9368 neon-logo.scm
122 204 2585 makefont.py

makefont is a script of mine that takes a ttf font and builds a blobbily bevelled antialiased png along with some font metrics. (with the help of pysdl and Numeric)

John Connors said...

Depends. If you just want to set a point or two, thats pretty much idiomatic. It's the fact that *everything* uses the (fn arg0 arg1 .. argn) notation that makes things like macros possible.

If you are often doing lot of points in one go, you can use mapcar..

..then you can generalise this again, by adding a function parameter, so that you have a function that does any operation you want on a list of points.

(defun do-points! (function array start-index x-indicies y-indices)
(mapcar (lambda (x y)
((function array start-index x y)
(setf! start-index
(+ 1 start-index)))
(x-indicies)
(y-indicies))

(do-points! #'set-pt a 0 (0 127 255) (0 255 255))

I haven't got a SIOD Repl handy, so I haven't tested it - in particular, I'm not sure I'm quoting #'set-pt right. Not sure what the function quoting syntax is for Scheme, but it's the right principle. Scheme is a *minimal* language, you have to build the constructs that let you express your program elegantly yourself.

Python's is larger and has a bigger syntax - more of the work is done for you. You pays your bytes and you takes your..(I'm aware that the above could pretty much be done in Python with lambda and map, btw..)

This link might be useful

http://www.norvig.com/python-lisp.html

In fact, the whole website itself is bit of a goldmine. There's also his tutorial on good Lisp style,which LtU called "the Strunk and White of Lisp". Not sure how much applies to scheme.
www.cs.umd.edu/~nau/cmsc421/norvig-lisp-style.pdf

John Connors said...

When I grabbed a mo in between screaming babies - I downloaded siod and had a look at siod.scm - the function quote is just a reqular quote without the hash. Makes sense, as this is a Lisp-1 and not a Lisp-2

siod.scm is worth looking at, there's use of the defmac form in there which doesn't seem to be documented anywhere.