PostScript

2007-04-13

I want to have some real Hex and TwixT boards, so I’ve been playing around with PostScript a bit.

I found Larry Doolittle’s Hex board and started editing it without knowing almost anything about PostScript. The results were – you guessed it – disastrous. PostScript is not really intuitive language (for me, at least). But then I found a great PostScript tutorial, which helped me immensely.

First I edited Larry’s Hex board – I added black outline to two opposite sides (for the sides not to get confused), and scaled and rotated the 13x13 board (which is littlegolem standard, therefore defacto universal standard) so that it’s playable with normal sized go stones and fits on A3 sized paper (I am very happy that it fits). You can download my 13x13 hex board on A3 for use with go stones.

The next thing I needed was a TwixT board. This time I only found a pdf, which was exactly not what I wanted. So, with a lot more help of the PostScript tutorial mentioned earlier, I created a PostScript TwixT board.

I made it to be highly customizable, you can find parameters on lines 10 to 21. You can easily change size of the board (the number of holes), the space between holes, holesize, color of holes, filling of holes, color of the guiding lines (or whatever they are called, you know, those lines that help you choose the right move ;-)), width and color of the border, basic line width, and finally horizontal and vertical offset. I sincerely think all those settings could be quite useful to anyone who wants to print a customized TwixT board.

I agree that the code is not really great (I stay true to the “it was difficult to write, so it should be difficult to read” principle), but it works and I think that’s what counts.

Here is a short example of PostScript language:

1 step mul dup moveto
boardsize 2 div 1 sub step mul bs 2 sub step mul lineto stroke

Which means, rewritten to human language:

move_to(1step, 1step);
draw_line_to((boardsize/2 – 1)step, (bs – 2)step);

In PostScript, everything is based on LIFO (last in first out) stacks, so when you want to do 3+4, you have to write 3 4 add (3 and 4 are put into the stack and the function “add” takes two values from the top of the stack and returns their sum back on the top).

I could show a lot of other PostScript examples but I think it’s better for you to have a look at the code yourself (it’s heavily uncommented, I didn’t want to take the fun out of it).

← Friday the thirteenth tech support Thank God I'm an atheist →

One thought on “PostScript”

Keo 2007-04-13

No jo, zásobníkový jazyky jsou vtipný. Kromě PostScriptu (btw, ten je i v PDF) je asi nejznámější FORTH. Kdysi se dokonce vyráběly čipy, který přímo prováděly jeho kód. V současnosti se tato třída jazyků většinou používá pouze jako backend pro překladače. Např. JVM a myslím i .NET nejsou nic jiného než interprety zásobníkového kódu (i když samozřejmě binárního) a teoreticky by asi nebyl problém psát programy v “Javě” podobně úchylným způsobem, jaký jsi popsal v článku. Výhodou těchto jazyků je totiž naprostá primitivnost parsování – žádné priority operátorů a tak.

Add your commentHow does this work?