| $!
$! Here's an example of a recursive function in DCL, which prints
$! fascinating Hilbert curves. IT REQUIRES A REGIS TERMINAL, SUCH AS
$! VT240.
$!
$! Save this procedure as HILBERT.COM. Then, run it with
$!
$! $ @HILBERT 4
$!
$! Then, you can experiment with other small integers.
$!
$! Author: Eric Osman 12/12/86
$!
$ all_options = p3 + p4 + p5 + p6 + p7 + p8
$ debug_flag = all_options .nes. ""
$ if .not. debug_flag then on control_y then goto leave
$ esc[0,8] = 27
$ if debug_flag then esc = "`"
$ s = p2
$ if s .eqs. "" then s = 15
$ level = 0
$ h0 = 180
$ hx180 = -1
$ hy180 = 0
$ h1 = 90
$ hx90 = 0
$ hy90 = 1
$ h2 = 0
$ hx0 = 1
$ hy0 = 0
$ h3 = 270
$ hx270 = 0
$ hy270 = -1
$ width = 800
$ height = 500
$ h = 270
$ !if .not. debug_flag then -
$ write sys$output "''esc'[2J''"
$ x = 0
$ y = 22 * height / 24
$ write sys$output "''esc'P1pP[''x',''y']"
$ whereto'level = "m0"
$ newarg = p1
$ if newarg .eqs. "" then newarg = 5
$ goto recursing
$m0: goto leave
$!
$recursing: level = level + 1
$ n'level = newarg
$ if n'level .eq. 0 then goto is0
$ a'level = 90 - (n'level .lt. 0) * 180
$ m'level = n'level + (n'level .lt. 0) * 2 - 1
$ h = h + a'level ! turn: a
$ newarg = 0 - m'level
$ whereto'level = "tag1"
$ goto recursing ! hilbert: 0 - m side: s
$tag1: h = h + a'level ! turn: a
$ h = h - h/360*360
$ if h .lt. 0 then h = h + 360
$ x = x + s*hx'h
$ y = y + s*hy'h
$ write sys$output "V[''x',''y']"
$ newarg = m'level
$ whereto'level = "tag2"
$ goto recursing ! hilbert: m side: s
$tag2: h = h - a'level ! turn: 0 - a
$ h = h - h/360*360
$ if h .lt. 0 then h = h + 360
$ x = x + s*hx'h
$ y = y + s*hy'h
$ write sys$output "V[''x',''y']"
$ h = h - a'level ! turn: 0 - a
$ newarg = m'level
$ whereto'level = "tag3"
$ goto recursing ! hilbert: m side: s
$tag3: h = h - h/360*360
$ if h .lt. 0 then h = h + 360
$ x = x + s*hx'h
$ y = y + s*hy'h
$ write sys$output "V[''x',''y']"
$ h = h + a'level ! turn: a
$ newarg = 0 - m'level
$ whereto'level = "tag4"
$ goto recursing ! hilbert: 0 - m side: s
$tag4: h = h + a'level ! turn: a
$ goto exit_please
$is0: h = h + 180 ! ^turn: 180
$exit_please: level = level - 1
$ tag = whereto'level
$ goto 'tag
$!
$!
$leave: write sys$output ";''esc'/''esc'[24;1f''esc'[K''esc'[A"
$ exit
|