This makes for a really interesting way to program in BASIC !!!
The "POLYGON" macro generates BASIC code to create a polygon.
Syntax:
<<POLYGON "point coordinates string" "colors string">>
point coordinates string: a string with each point coordinate in parentheses, x comma y, and each point coordinate separated from the next point coordinate by a dash. So each coordinate looks like "(x,y)", and a point coordinate separated from the next point coordinate looks like "(x1,y1) - (x2,y2)"
🔹UPDATE 2023-08-19:
- A point coordinate can be preceded by the STEP keyword, which indicates the next point coordinate is a relative position (relative to the previous point coordinate)
- The macro now knows how to ignore any and all spaces in the coordinates string
- The macro also now knows how to ignore lack of any spaces in the coordinates string
colors string: a string with the numbers (for the currently applied screen mode) for the border color and the fill color, those two numbers separated by a comma. The string looks like: "border-color,fill-color"
🔹UPDATE 2023-08-21:
- fill color is optional; when omitted, the colors string would look like: "border-color"
NOTE: the two POLYGON parameters must be wrapped in double-quotes, and the two parameters must be separated from each other by one or more spaces.
To use the POLYGON macro, a program must include the Polygon Macro Support library. Your program can make use of all things declared in the library.
Remember that a macro generates code just before passing the program to the interpreter.
Links to the sample program below, but first how the test program appears in the BAM IDE (i.e. before the macro gets replaced by the generated BASIC code):
moving_x = 6
adj_x = 5
i = 0
DO
CLS : b = INT(RND*15) + 1 : f = INT(RND*15) + 1
<<POLYGON "(moving_x,10) - (500,100) - (550, 120) - (30,170)" "b,f">>
CIRCLE ( (LeftMostX + LeftMostBuddyX) / 2 + IFF(LeftMostY>LeftMostBuddyY,1,-1) , (LeftMostY + LeftMostBuddyY) / 2 + 1 ),4,12
IF moving_x > 634 OR moving_x < 6 THEN adj_x = - adj_x
moving_x = moving_x + adj_x
i = i + 1
_DELAY 0.25
LOOP
BTW, using the DRAW statement to draw polygons would be just as easy, I think. Pretty sure it would just be about personal preference regarding code readability. Maybe. I need to chew on that for a bit.
ReplyDeleteI just updated the test version of BASIC Anywhere Machine.
ReplyDeleteThe POLYGON macro now knows how to (1) handle the keyword "STEP" in front of any coordinate, (2) handle any number of spaces within the coordinates string, and (3) handle no spaces between the bits in the coordinates string.
I'm in the process of modifying the blog post to reflect this.
Another sample app to test POLYGON, "Star" : https://www.reddit.com/r/BASICAnywhereMachine/comments/15uyy4p/comment/jwsqfim/?utm_source=share&utm_medium=web2x&context=3
ReplyDeleteThe fill color for the polygon macro is now optional. I've updated the blog to reflect that.
ReplyDelete