Implemented painter's algorithm.