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


include c:\cxpl\codes;          \intrinsic 'code' declarations
 
proc DrawPat(X0, Y0, S);        \Draw 3x3 pattern with hole in middle
int  X0, Y0, S;                 \coordinate of upper-left corner, size
int  X, Y;
[for Y:= 0 to 2 do
    for X:= 0 to 2 do
        if X#1 or Y#1 then      \don't draw middle pattern
           [if S>1 then         \recurse
                DrawPat(X*S+X0, Y*S+Y0, S/3)
           else Point(X+X0, Y+Y0, 4\red\);
           ];
];
 
[SetVid($13);                   \set 320x200 graphic video mode
DrawPat(0, 0, 3*3*3);           \draw Sierpinski carpet
if ChIn(1) then [];             \wait for keystroke
SetVid($3);                     \restore normal text mode
]