Someone just wanted to animate boxes in diagonally. The key is mapping ℕ✕ℕ → ℕ by the Cantor pairing function! This version additionally zigzags by using the inverse of the triangular number equation to find the row of the triangle you’re on and then invert the order of the arguments to the Cantor pairing function every other row.

This does not depend on data initially being sorted, or in any particular shape or arrangement; it could be square, rectangular, sparse, etc.

See also:

- Straight diagonal using comparator on existing data
- Stepped diagonal using Cantor pairing comparator on existing data
- Zigzag diagonal using alternating Cantor pairing comparator on existing data
- Generating by triangular numbers