Simplified canvas builtin
The golfing languages 05AB1E and Vyxal have a "canvas" builtin that draws a string on a ASCII grid. In this challenge, you'll be implementing a simplified form of this.
You should take a string of ASCII characters, along with a list of directions as integers 0-7, where 0 is directly upwards and the rest continue clockwise - 1 is up-right, 2 is right, etc up to 7 being up-left.
7 0 1
\|/
6-x-2
/|\
5 4 3
For example, given the string abcde
and the directions 0,2,5,6
:
Draw a
at the center, then move up (0) and draw b
:
b
a
Then move right (2) and draw c
:
bc
a
Then move down-left (5) and draw d
, overwriting the a
:
bc
d
And finally move left (6) and draw e
:
bc
ed
For a more complex example that I won't work through, given the string octagon!
and the directions 1,2,3,4,5,6,7
, you should draw:
ct
o a
! g
no
Empty space should be filled with spaces, and you can output with any amount of leading and trailing whitespace so long as the pattern at the centre is still correct. There will always be exactly one more character than directions, so that one character can be drawn at the centre.
You may take directions as 1-8 instead, and/or reorder them in any way. The input string may contain spaces.
This is code-golf, shortest wins!
Testcases
Input | Output |
---|---|
[1,1,1,1], "aaaaa" |
|
[1,2,3,4,5,6,7],"octagon!" |
|
[2,4,2,4,2,4,2,4],"staircase" |
|
[1,1,1,1,1,1],"s s s s" |
|
[2,2,2,2,0,0,6,6,4,4], "overwriting" |
|
[2,2,2,4,4,5,5,6,6,6,0,0,1,5,2,2,2,1,5,4], "+--+|+/+--+|X/+--X/+|" |
|
|
|
Meta
Is this distinct enough from Scribble Pad For Nerds?