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


_Title "Sierpinski Carpet"
 
Screen _NewImage(500, 545, 8)
Cls , 15: Color 1, 15
 
'labels
_PrintString (96, 8), "Order 0"
_PrintString (345, 8), "Order 1"
_PrintString (96, 280), "Order 3"
_PrintString (345, 280), "Order 4"
 
'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)
 
Sleep
System
 
Sub carpet (x As Integer, y As Integer, size As Integer, order As Integer)
    Dim As Integer ix, iy, isize, iorder, side, newX, newY
    ix = x: iy = y: isize = size: iorder = order
    Line (ix, iy)-(ix + isize - 1, iy + isize - 1), 1, BF
 
    side = Int(isize / 3)
    newX = ix + side
    newY = iy + side
    Line (newX, newY)-(newX + side - 1, newY + side - 1), 15, BF
    iorder = iorder - 1
    If iorder >= 0 Then
        Call carpet(newX - side, newY - side + 1, side, iorder)
        Call carpet(newX, newY - side + 1, side, iorder)
        Call carpet(newX + side, newY - side + 1, side, iorder)
        Call carpet(newX + side, newY, side, iorder)
        Call carpet(newX + side, newY + side, side, iorder)
        Call carpet(newX, newY + side, side, iorder)
        Call carpet(newX - side, newY + side, side, iorder)
        Call carpet(newX - side, newY, side, iorder)
    End If
End Sub