Optimized border-coloring.

Created function to convert directions.