Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N.



For example, the Sierpinski carpet of order   3   should look like this:

###########################
# ## ## ## ## ## ## ## ## #
###########################
###   ######   ######   ###
# #   # ## #   # ## #   # #
###   ######   ######   ###
###########################
# ## ## ## ## ## ## ## ## #
###########################
#########         #########
# ## ## #         # ## ## #
#########         #########
###   ###         ###   ###
# #   # #         # #   # #
###   ###         ###   ###
#########         #########
# ## ## #         # ## ## #
#########         #########
###########################
# ## ## ## ## ## ## ## ## #
###########################
###   ######   ######   ###
# #   # ## #   # ## #   # #
###   ######   ######   ###
###########################
# ## ## ## ## ## ## ## ## #
###########################

The use of the   #   character is not rigidly required for ASCII art.

The important requirement is the placement of whitespace and non-whitespace characters.



Related task

   Sierpinski triangle


NoMainWin
WindowWidth  = 508
WindowHeight = 575
Open "Sierpinski Carpets" For Graphics_nsb_nf As #g
#g "Down; TrapClose [halt]"
 
'labels
#g "Place  90  15;\Order 0"
#g "Place 340  15;\Order 1"
#g "Place  90 286;\Order 2"
#g "Place 340 286;\Order 3"
'carpets
Call carpet   5,  20, 243, 0
Call carpet 253,  20, 243, 1
Call carpet   5, 293, 243, 2
Call carpet 253, 293, 243, 3
#g "Flush"
Wait
 
[halt]
Close #g
End
 
Sub carpet x, y, size, order
    #g "Color 0 0 128; BackColor 0 0 128"
    #g "Place ";x;" ";y
    #g "BoxFilled ";x+size-1;" ";y+size-1
    #g "Color white; BackColor white"
    side = Int(size/3)
    newX = x+side
    newY = y+side
    #g "Place ";newX;" ";newY
    #g "BoxFilled ";newX+side-1;" ";newY+side-1
    order = order - 1
    If order > -1 Then
        Call carpet newX-side, newY-side+1, side, order
        Call carpet newX,      newY-side+1, side, order
        Call carpet newX+side, newY-side+1, side, order
        Call carpet newX+side, newY,        side, order
        Call carpet newX+side, newY+side,   side, order
        Call carpet newX,      newY+side,   side, order
        Call carpet newX-side, newY+side,   side, order
        Call carpet newX-side, newY,        side, order
    End If
End Sub