PHP, 130 bytes
for($p=30,$s=1,$r=_;$i<51;$r[$p]=chr(90-abs(25-$i++)),$p+=$s*(9-$d))if(!$n||!$c=++$c%$n)($d=8-$d)?$n++:$s=-$s;echo wordwrap($r,8);
literally draws the spiral. Run with -r
breakdown
for($p=30,$s=1,$r=_; // initialize position to 3*9+3, $s(ign) to +1, $r(esult) to string
// implicit $c(ount)=$d(irection)=$i(ndex)=le($n)gth=0
$i<51; // loop $i from 0 to 50
$r[$p]=chr(90-abs(25-$i++)),// 2. set current position in string to correct character
$p+=$s*(9-$d)) // 3. move cursor
if(!$n||!$c=++$c%$n) // 1. if 1st iteration ($n==0) or ++$c has rotated around $n
($d=8-$d) // negate $direction (0=horizontal, 8=vertical)
?$n++ // if vertical: increase length
:$s=-$s // else invert sign
;
// output: wrap to lines of 8 characters
echo wordwrap($r,8); // having left spaces avoids need to provide 3rd and 4th parameter
Easy to extend: For more alphabet,
append %50
after $i++
,
replace 51
with the wanted number,
modify 8-$d
, 9-$d
, $p=30
and the wordwrap
width to the new dimensions.