However, the problem with making the algorithm to calculate these levels is not that straightforward. I found two algorithms to do this – one and two. One part of the code was to implement the Ramer-Douglas-Peucker algorithm to reduce the number of points needed depending on the set small number. After that it was just simple encoding of the levels using a similar number to character conversion.
The final code is at the same place in bitbucket. It is possible that the new feature may not work correctly. If it is the case, please let me know.