fix logic error & handle division by zero edge case in color generation functions