Dragon curve: Difference between revisions
Content deleted Content added
→{{header|QuickBASIC}}: Added a solution. |
→{{header|QuickBASIC}}: Introduced some parameters in the recursive subroutine (especially for a level and instead of the array simulating a stack). |
||
Line 977:
==={{header|QuickBASIC}}===
{{trans|GW-BASIC|Introduced some parameters in the recursive subroutine (especially for a level and instead of the array simulating a stack).}}
<syntaxhighlight lang="basic">
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 *
C(I) = COS(I *
NEXT I
Insize = 128: REM 2^WHOLE_NUM (looks better)▼
X = 112: Y = 70
SCREEN 2: CLS
END
SUB Dragon (BYVAL Insize, BYVAL Level%, BYVAL RQ%)
CONST SQ = 1.4142135623731# ' SQR(2)
IF Level% <= 1 THEN
YN = S(RotQPi%) * Insize + Y▼
XN = C(RotQPi%) * Insize + X
▲ YN = S(RotQPi%) * Insize + Y
LINE (2 * X, Y)-(2 * XN, YN)
X = XN: Y = YN
ELSE
RotQPi% = (RotQPi% + RQ%) AND 7
CALL Dragon(Insize / SQ, Level% - 1, -1)
RotQPi% = (RotQPi% + RQ%) AND 7
END IF
END SUB
|