Circular loop through 2D array

FrostyCat

Member
You could have scrolled a little further down and found the C++ answer, which is basically copy-and-paste except for minor syntax adjustments.
Code:
var X = array_length_2d(arr, 0),
    Y = array_height_2d(arr),
    xx = 0,
    yy = 0,
    dx = 0,
    dy = -1;
repeat (sqr(max(X, Y))) {
    if ((-X/2 <= xx) && (xx <= X/2) && (-Y/2 <= yy) && (yy <= Y/2)) {
        // DO STUFF...
    }
    if ((xx == yy) || ((xx < 0) && (xx == -yy)) || ((xx > 0) && (xx == 1-yy))) {
        var t = dx;
        dx = -dy;
        dy = t;
    }
    xx += dx;
    yy += dy;
}
 
Top