04-05-2024, 09:39 PM
Here's another one to stare at.
Code: (Select All)
' DrawBoxes.BAS
'
' DRAW example using paint feature
' by Terry Ritchie 04/05/24
' Using the paint feature in DRAW can be very taxing on the CPU.
' Change boxsize to 20 below and see the result.
CONST BOXSIZE = 100 ' side length of rotating squares
DIM Angle AS INTEGER ' pen rotation angle
DIM Gray AS INTEGER ' paint color
DIM Direction AS INTEGER ' paint color direction
DIM s AS STRING ' side length of square in string format
DIM s2 AS STRING ' 1/2 side length of square in string format
DIM Box AS STRING ' string used to draw a square
DIM White AS STRING ' color white in string format
DIM Black AS STRING ' color black in string format
SCREEN _NEWIMAGE(800, 600, 32) ' enter a graphics screen
White = STR$(_RGB(255, 255, 255)) ' create white string
Black = STR$(_RGB(0, 0, 0)) ' create black string
s = STR$(BOXSIZE) ' create side length string
s2 = STR$(BOXSIZE \ 2) ' create 1/2 side length string
Box = "D" + s2 + "L" + s + "U" + s + "R" + s + "D" + s2 ' create string to draw a square
Direction = 1 ' set paint color direction
Gray = 0 ' set paint color
DO ' begin main program loop
CLS ' clear the screen
_LIMIT 60 ' no faster than 60 FPS
FOR y = BOXSIZE \ 2 TO 600 - BOXSIZE \ 2 STEP BOXSIZE ' cycle square x center points
FOR x = BOXSIZE \ 2 TO 800 - BOXSIZE \ 2 STEP BOXSIZE ' cycle square y center points
DRAW "BM" + STR$(x) + "," + STR$(y) ' move pen to square center point
DRAW "TA" + STR$(Angle) ' rotate pen
DRAW "C" + Black ' make pen color black
DRAW "R" + s2 ' move pen to square border
DRAW "C" + White ' make pen color white
DRAW Box ' draw a square
DRAW "BM" + STR$(x) + "," + STR$(y) ' move pen back to center of square
DRAW "P" + STR$(_RGB(Gray, Gray, Gray)) + "," + White ' paint inside the square
NEXT x
NEXT y
_DISPLAY ' update the screen with changes
Gray = Gray + Direction ' increase/decrease gray color level
IF Gray = 255 OR Gray = 0 THEN Direction = -Direction ' reverse gray level direction
Angle = Angle + 1 ' increase pen angle
IF Angle = 360 THEN Angle = 0 ' reset angle when needed
LOOP UNTIL _KEYDOWN(27) ' leave when ESC key pressed
SYSTEM ' return to operating system