move coordinate calculation out of the draw block.