The answer by Ramesh works almost fine. However the white glitch at the end is caused by rounding errors from casting float to int. Simply change the type of "temp" to float, and remove the cast to (int) at the end when "temp += value_degree[i-1]" and it's perfect.