On each iteration, it prints the current number followed by a special escape sequence.
This escape sequence,
\033[38;5;${N}m
is used to change the color of the terminal text. In this case, `${N}` is substituted with the current number, thus changing the color according to it. After the color escape sequence, it prints `$` and then another escape sequence, `\033[0m`, to reset the color back to normal. This line generates a list of colored `$` symbols.
Then `| xargs` pipes this list as arguments to the xargs command. However, without an explicit command after `xargs`, xargs puts all args on a single line making it fill the screen compactly
I've played around with a few of these types of things. Pastel is really a good utility for playing with color:
https://github.com/sharkdp/pastel