cmeyer@milton.u.washington.edu (Colin Meyer) (11/19/90)
Here is a program to draw dragon curves on the HP48SX. Dragon curves? Yeah, those things that you make by folding a strip of paper in half n times & then unfolding it so all the corners are right angles. Programs: DRAGON: generates a dragon curve of order n (n >= 3). SKETCH: draws a dragon curve. DRAWC: (called by SKETCH). Usage: DRAGON: 1: n Press [DRAGON]. N must be 3 or greater. Dragon returns a string of ones and zeros to 1:. A zero is a left turn & a one is a right turn. SKETCH: 3: "0010011..." (a dragon curve) 2: start 1: r Press [SKETCH]. The string in level 3 is a string generated by DRAGON. Start in level 2 is the point to start drawing from. It can be in complex number form or in a list of binary integers (user units or pixels). R in level one is the radius of the corners (each corner is a quarter circle). Note: the User Units must be in the same ration of x to y as the pixels in PICT. The easiest way to get this is to make the user units the same as the pixels. For examle, if PICT is #131 by #150, make the xrange 0..131 and the yrange 0..150. Example: First, do #131 #150 pdim. Then do 0 131 xrng 0 150 yrng. 1: 8 [DRAGON] 3: "0010011..." (the string generated by DRAGON) 2: { # 65d # 33d } 1: 3 [SKETCH] (Sit back and enjoy.) Code: BYTES: # E34Ch 1202.5 -------cut here-------- %%HP: T(3)A(D)F(.); DIR DRAGON \<< IF DUP 3 == THEN DROP "0010011" ELSE 1 - DRAGON DUP DUP SIZE DUP 1 + 2 / 1 + SWAP SUB OVER 0 + \-> old oldh new \<< 1 oldh SIZE FOR j old j j SUB OBJ\-> R\->B oldh j j SUB OBJ\-> R\->B AND B\->R new SWAP + 'new' STO NEXT new 1 + oldh + \>> END \>> SKETCH \<< ERASE { # 0d # 0d } PVIEW # 0d SWAP R\->B 2 \->LIST PX\->C { # 0d # 0d } PX\->C - ABS SWAP 3 ROLLD \-> drgn d \<< IFERR PX\->C THEN END 4 1 drgn SIZE FOR j drgn j j SUB IF "0" SAME THEN CASE DUP 1 == THEN DROP 0 d 270 0 d DUP DUP DRAWC 2 END DUP 2 == THEN DROP d NEG 0 0 90 d DUP NEG d DRAWC 3 END 3 == THEN 0 d NEG 90 180 d d NEG DUP DRAWC 4 END d 0 180 270 d DUP DUP NEG DRAWC 1 END ELSE CASE DUP 1 == THEN DROP 0 d NEG 0 90 d DUP DUP NEG DRAWC 4 END DUP 2 == THEN DROP d 0 90 180 d DUP DUP DRAWC 1 END 3 == THEN 0 d 180 270 d DUP NEG d DRAWC 2 END d NEG 0 270 0 d DUP NEG DUP DRAWC 3 END END NEXT DROP2 \>> \>> DRAWC \<< \-> x y a b r s t \<< DUP x y R\->C + r a b ARC s t R\->C + \>> \>> PPAR { (0,0) (131,150) X 0 (0,0) FUNCTION Y } END -------end cut-------