07-03-2021, 05:22 PM
To celebrate the 4th, I've written a short program to plot a "fireworks star" of four dragons (dragon curves) on one of my calculators, an early 80s "Portable Computer":
[attachment=9613][attachment=9614]
The annotated fourdragons.bas BASIC program:
This program draws four dragon curves from the center at different angles and colors. Each curve is of degree D=10. The degree and line length can be adjusted to create smaller or larger graphs.
- Rob
[attachment=9613][attachment=9614]
The annotated fourdragons.bas BASIC program:
Code:
' DRAGON CURVE 4x NESTED DRAWN COUNTER CLOCKWISE
' For SHARP PC-2500
' S-BASIC has no subroutine arguments, so let's use a stack instead
' S-BASIC supports GOSUB recursions up to 10 levels deep, we use computed
' GOTOs instead with return line number R saved on the stack
' A recursive turtle graphics DragonCurve algorithm:
'
' proc DragonCurve(sign, depth)
' if depth == 0 then
' forward(4)
' else
' DragonCurve(1, depth-1)
' left(sign * 90)
' DragonCurve(-1, depth-1)
' endif
' endproc
' right(depth * 45)
' DragonCurve(1, 10)
' VARIABLES
' D depth parameter (between 2 and 12, recommend 10)
' N line length (recommend 4 for D up to 12)
' X,Y pen cursor position
' A angle of pen direction
' C color rotation
' S sign parameter
' R return line number, to return to the next line
' P stack pointer
' A() auto-array stack starting at 27 (after Z)
' E,F,G,H 4*sin(0,90,180,270) = A(5+A)
' I,J,K,L 4*cos(0,90,180,270) = A(9+A)
10 CLEAR: D=10, N=4, E=0, F=N, G=0, H=-N, I=N, J=0, K=-N, L=0, P=27
20 CONSOLE 160: LPRINT CHR$ 27;"b": LPRINT "M240,-240": LPRINT "I"
30 FOR C=0 TO 3
40 LPRINT CHR$ 27;STR$ C: LPRINT "H": X=0, Y=0, A=D/2+C AND 3
50 R=60, S=1: GOTO "DC"
60 NEXT C
70 LPRINT "M0,-240": LPRINT CHR$ 27;"0": LPRINT CHR$ 27;"a": CONSOLE 39: END
' DragonCurve(S,D) entry
100 "DC" IF D>1 GOTO 130
110 X=X+A(9+A),Y=Y+A(5+A): LPRINT "D";X;",";Y: A=A-S AND 3
120 X=X+A(9+A),Y=Y+A(5+A): LPRINT "D";X;",";Y: GOTO R
' push argument S, return R
130 A(P)=S, A(P+1)=R, P=P+2, D=D-1
140 R=150, S=1: GOTO "DC"
150 A=A-A(P-2) AND 3
160 R=170, S=-1: GOTO "DC"
' DragonCurve exit: pop S, restore D and return
170 P=P-2, S=A(P), D=D+1: GOTO A(P+1)
This program draws four dragon curves from the center at different angles and colors. Each curve is of degree D=10. The degree and line length can be adjusted to create smaller or larger graphs.
- Rob