Count how many spaces each line have. In this case it is 5,*; 4,*,2; 3,*,4; 4,*,2; 6,*;. Try to express these numbers in functions of n (total number of lines) and i (number of the current line). There are just linear functions, so you shouldn't have problems with it.
Notice that you can use one set of functions to draw first 3 lines, and use another set for the rest or etc.