' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2024.09.10.01.33]) on 2025.03.15 at 21:43 (Coordinated Universal Time)
' This program by Charlie Veniot demonstrates a way to simulate Object-Oriented Programming methods
' with GOSUB statements. This is possible because BAM allows the use of expressions with GOSUB statements.
' - Expressions must be within parentheses to be recognized as expressions.)
' - Expressions that result in a string, the string will be treated as a line label
' - Expressions that result in a number, the number will be treated as a line number
'
' NOTE: this currently only works in the "development" version of BAM found at https://bam-ide.tiddlyhost.com/
' and will be released to "production" on a to-be-determined date.
' 🟠🟠🟠Declarations
CONST ShapeDrawSub$(1 TO 2) = { "A100_CircleSub", "A200_SquareSub" }, _
maxShapes% = 570
TYPE tThingy
x% ' thingy's center coordinate on x axis
y% ' thingy's center coordinate on y axis
r% ' thingy's outermost point
c% ' thingy's colour
shape$ ' thingy's shape-drawing GOSUB routine constant
END TYPE
DIM aThing( 1 TO maxShapes% ) AS tThingy
' 🟠🟠🟠Main Program
SCREEN _NEWIMAGE( 400, 400, 17 )
FOR i% = 1 TO maxShapes%
aThing(i%).x% = INT( RND * ( _WIDTH - 20 ) ) + 10
aThing(i%).y% = INT( RND * ( _HEIGHT - 20 ) ) + 10
aThing(i%).c% = INT( RND * 62 ) + 1
aThing(i%).r% = INT( RND * 10 ) + 1
aThing(i%).shape$ = ShapeDrawSub$( INT( RND * 2 ) + 1 )
NEXT i%
FOR i% = 1 TO maxShapes%
IF LABELEXISTS( aThing(i%).shape$ ) THEN GOSUB ( aThing(i%).shape$ )
NEXT i%
END
' 🟠🟠🟠Gosub Routines
A100_CircleSub:
CIRCLE( aThing(i%).x%, aThing(i%).y% ), aThing(i%).r%, aThing(i%).c%
RETURN
A200_SquareSub:
DRAW "BM" + aThing(i%).x% + "," + aThing(i%).y%
DRAW "BE" + aThing(i%).r%
px1% = POINT( 0 ) : py1% = POINT( 1 )
DRAW "BM" + aThing(i%).x% + "," + aThing(i%).y%
DRAW "BF" + aThing(i%).r%
px2% = POINT( 0 ) : py2% = POINT( 1 )
DRAW "BM" + aThing(i%).x% + "," + aThing(i%).y%
DRAW "BG" + aThing(i%).r%
px3% = POINT( 0 ) : py3% = POINT( 1 )
DRAW "BM" + aThing(i%).x% + "," + aThing(i%).y%
DRAW "BH" + aThing(i%).r%
px4% = POINT( 0 ) : py4% = POINT( 1 )
COLOR aThing(i%).c%
LINE ( px1%, py1% ) TO ( px2%, py2%) : LINE TO ( px3%, py3% ) : LINE TO ( px4%, py4% ) : LINE TO ( px1%, py1% )
RETURN