Calculating x-axis displacement points with loop