30 lines
844 B
Plaintext
30 lines
844 B
Plaintext
REM Dragon curve
|
|
REM SIN, COS in arrays for PI/4 multipl.
|
|
DECLARE SUB Dragon (BYVAL Insize!, BYVAL Level%, BYVAL RQ%)
|
|
DIM SHARED S(7), C(7), X, Y, RotQPi%
|
|
CONST QPI = .785398163397448# ' PI / 4
|
|
FOR I = 0 TO 7
|
|
S(I) = SIN(I * QPI)
|
|
C(I) = COS(I * QPI)
|
|
NEXT I
|
|
X = 112: Y = 70
|
|
SCREEN 2: CLS
|
|
CALL Dragon(128, 15, 1) ' Insize = 2^WHOLE_NUM (looks better)
|
|
END
|
|
|
|
SUB Dragon (BYVAL Insize, BYVAL Level%, BYVAL RQ%)
|
|
CONST SQ = 1.4142135623731# ' SQR(2)
|
|
IF Level% <= 1 THEN
|
|
XN = C(RotQPi%) * Insize + X
|
|
YN = S(RotQPi%) * Insize + Y
|
|
LINE (2 * X, Y)-(2 * XN, YN) ' For SCREEN 2 doubled x-coords
|
|
X = XN: Y = YN
|
|
ELSE
|
|
RotQPi% = (RotQPi% + RQ%) AND 7
|
|
CALL Dragon(Insize / SQ, Level% - 1, 1)
|
|
RotQPi% = (RotQPi% - RQ% * 2) AND 7
|
|
CALL Dragon(Insize / SQ, Level% - 1, -1)
|
|
RotQPi% = (RotQPi% + RQ%) AND 7
|
|
END IF
|
|
END SUB
|