mid point displacement algorithm