calculate gradient for rectangles - continue