fixed issue where the trend constantly changed when the squares approached
the edge of the screen