Answer the question
In order to leave comments, you need to log in
How to determine the coordinates of a cell, knowing its number?
Hello!
I am developing an application that iterates through a set of colors and paints a cell on the field with this color. This is an extremely simplified description of the application, but for the essence of this it will be enough.
So, let's say we have a field (in my case, this is a canvas on which the colors from the set are applied):
# # # # #
# # # # #
# # # # #
# # # = #
# # # # #
Answer the question
In order to leave comments, you need to log in
The row number is the integer part of the cell number divided by the number of elements in the row.
The column number is the remainder of dividing the number by the same number.
Math.ceil( 18 / 5 ) === 3; // строка с индексом 3, считая от 0
18 % 5 === 3; // колонка с индексом 3, считая, опять же, от 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question