##计算一个小正方形的空格区域
function get-Blanks($lev)
{
[string]$blank = ''
[int]$totalWidth = [Math]::pow(3, $lev-1);
$blank = $blank.PadRight($totalWidth, ' ');
$blanks = $blank, $blank, $blank;
while($totalWidth -gt 3)
{
$blanks = $blanks+$blank;
$totalWidth -= 1;
}
return $blanks;
}
##计算n=$lev时的图案
function Get-Stars($lev)
{
if($lev -eq 1)
{
$starts1 = 'x'
return $starts1
}
if($lev -eq 2)
{
$starts2 = 'x x', ' x ', 'x x'
return $starts2
}
$sub = Get-Stars ($lev-1)
$bla = Get-Blanks ($lev-1)
$Line1 = Get-Blanks ($lev-1)
$Line2 = Get-Blanks ($lev-1)
1..$bla.Length | %{ $Line1[$_-1] = $sub[$_-1]+$bla[$_-1]+$sub[$_-1]; $Line2[$_-1] = $bla[$_-1]+$sub[$_-1]+$bla[$_-1]}
$starts = $Line1+$Line2+$Line1
return $starts
}
##输出图案:
'n=1'
Get-Stars 1
'n=2'
Get-Stars 2
'n=3'
Get-Stars 3
'n=4'
Get-Stars 4
'n=5'
Get-Stars 5
|