RogueLike line of sigth(Resolve)

Hello everyone , im making a roguelike game just for exercise myself , i come to a problem when i come to the line of sigth.

Am unable to find a equation/formula for getting the number of purple “square/node” like in this schema:

i think i can resolve this by a exponential equation (y = ab^x) but im not sure on that because i cant get the “b” right when checking it with multiple points.

Thanks for your future responds and help.

You have an arithmetic progression there.

1 → 0
2 → 0 + 2 = 2
3 → 0 + 2 + 4 = 6
4 → 0 + 2 + 4 + 6 = 12
5 → 0 + 2 + 4 + 6 + 8 = 20

yes indeed, the goal would be to have some sort of formula for it to be inside a loop.

I dont get it. Doesnt this formula fit your needs?

It should if all you need is the number of purple squares.

well the number of purple square are base on the range of the line of sight(in red)

If that’s the pattern this will handle it.

int purpleSquares = lengthOfSight * (lengthOfSight - 1);

thank you