chrisphan.com

“10 PRINT” in PostScript

An analog clock reading 10:002019-02-18 / 2019-W08-1T22:00:40-06:00 / 0x5c6b7f68

Categories: PostScript

Back in May, I posted a LaTeX document using TikZ to implement the Commodore 64 BASIC program:

BASIC
10 PRINT CHR$(205.5+RND(1)); : GOTO 10

The amusement factor (for me) is due to LaTeX's ability to generate pseudorandom numbers, which may be surprising to some, especially those who think of LaTeX documents as static (deterministic) documents and not computer programs.

PostScript can also generate pseudorandom numbers, and hence I present "10 PRINT" in PostScript:

PostScript
%!

% Implementation of "10 PRINT" in PostScript
% Christopher Phan, cphan@chrisphan.com
% 2019-02-17

% Draw frame around page

newpath
  36 36 moveto % 36 pt = 0.5 in
  36 756 lineto % 756 pt = 10.5 in
  576 756 lineto % 576 pt = 8 in
  576 36 lineto
  closepath
stroke

% each slash will occupy a 0.25 in x 0.25 in square

36 18 558 { % 18 pt = 0.25 in
  /x exch def
  36 18 738 {
    /y exch def
    newpath
      /u rand 2 mod 18 mul def
      x y u add moveto
      x 18 add y 18 u sub add lineto
    closepath stroke
  } for
} for

showpage

Example output:

A maze created by randomly placing walls. Each wall is in one of two perpendicular orientations.