B
B
bqio2018-12-25 09:14:01
Mathematics
bqio, 2018-12-25 09:14:01

How to get the row and column of a matrix by element number?

There is a matrix, let's say 16x16 (starting from 0)

a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l
a b j i o p y h g b n m m j k l

How do I get element 18 without using arrays in action. Because in this form I have sprites in the picture. And in order to draw them on the canvas, I want to write the sprite number, say, 18, and he gave me the coordinates 2x1 (x, y). How would it be implemented?
Then I just multiply the obtained coordinates by the sprite size (48x48) and get the picture I need.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2018-12-25
@bqio

x = 18 mod 16  # (2)
y = 18 div 16  # (1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question