This is a fun one!
Updating ampos's code, you could have a maximum rectangles allowed in the array at once, with the older ones getting overwritten in the array. This could be updated to allow for effects for the older rectangles such as fading away, or slowly moving off the screen.
But even at 1000, DRAWRECT could get slow. I would recommend using POLYVECTORS for anything real.
TYPE TRectangle
left%
top%
width%
height%
colour%
FUNCTION Set: l%, t%, w%, h%, colour%
self.left = l
self.top = t
self.width = w
self.height = h
self.colour = colour
ENDFUNCTION
FUNCTION Draw:
// Exit if rectangle hasn't been initialized
IF (self.left=0) AND (self.top=0) AND (self.width=0) AND (self.height=0) THEN RETURN
DRAWRECT self.left, self.top, self.width, self.height, self.colour
ENDFUNCTION
ENDTYPE
CONSTANT RECT_MAX% = 1000
GLOBAL rects[] AS TRectangle
GLOBAL pos%
GLOBAL rx%
DIM rects[RECT_MAX]
REPEAT
// New Rectangle
INC pos
IF pos>=RECT_MAX THEN pos=0
rects[pos].Set(RND(100), RND(100), RND(100), RND(100), RGB(RND(255),RND(255),RND(255)) )
// Draw all rectangles in the reverse order they were added, this controls the 'z-order' so latest is on top
// . . . draw the ones at the end of the array first
FOR rx = pos+1 TO RECT_MAX-1
rects[rx].Draw()
NEXT
// . . . draw the ones at the start of the array next
FOR rx = 0 TO pos
rects[rx].Draw()
NEXT
UNTIL FALSE