Perimeter pick waking

Hello,
I was wondering if someone can help me out. I have a 16x16 array laid out in a grid. The outer rim is 0, next rim is 1 then 2 … ect. Currently, I’m using i = x + width*y to access elements in my gird. What I would like to do it have the left and right arrow keys circle around and the up and down arrow keys shrink in and out

for example, lets say im at x0y0 hitting the left and right arrow keys would return 0 , hitting the up key would return a 1. If i keep hitting the left and right arrow key i would cycle around the 1s. Hope this makes sense

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 1 2 2 2 2 2 2 2 2 2 2 2 2 1 0
0 1 2 3 3 3 3 3 3 3 3 3 3 2 1 0
0 1 2 3 4 4 4 4 4 4 4 4 3 2 1 0
0 1 2 3 4 5 5 5 5 5 5 4 3 2 1 0
0 1 2 3 4 5 6 6 6 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 6 6 6 5 4 3 2 1 0
0 1 2 3 4 5 5 5 5 5 5 4 3 2 1 0
0 1 2 3 4 4 4 4 4 4 4 4 3 2 1 0
0 1 2 3 3 3 3 3 3 3 3 3 3 2 1 0
0 1 2 2 2 2 2 2 2 2 2 2 2 2 1 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

thanks for the help

Can you me more specific? I am not sure I understand what do you want to do.

Are you trying to walk a contour bar?

You can develop a sense of the gradient by taking some neighbor pixels, but remember your motion becomes undefined at high peaks, low points, saddles and also the top of valley clefts and the bottom of mountain “feet.”

If you have a small fixed board, just hard-code what you want each arrow to move given each cell, then you can guarantee it works in all cases.

so the array represents a pyramid. 0 is the base, 1 is one step on the pyramid, 2 another step up, etc … I need a way to return the index from arrow inputs. for example if im at x0y0 and keep hitting the right arrow key im essentially walking anti-clockwise around the base (path of all the 0s). if I press up im now on the 1s and hitting right or left arrow keys should traverse the 1s If i hit up again ill be on the 2s and left and right arrows should now traverse the 2s. And obviously hitting down steps back to 1s

( red show a path ) if i was to hit up 5 times (climb 5 steps) I would circle blue path with right and left arrow keys

(this breaks when i post but i should show the idea)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 1 2 2 2 2 2 2 2 2 2 2 2 2 1 0
0 1 2 3 3 3 3 3 3 3 3 3 3 2 1 0
0 1 2 3 4 4 4 4 4 4 4 4 3 2 1 0
0 1 2 3 4 5 5 5 5 5 5 4 3 2 1 0
0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 6 6 6 5 4 3 2 1 0
0 1 2 3 4 5 5 5 5 5 5 4 3 2 1 0
0 1 2 3 4 4 4 4 4 4 4 4 3 2 1 0
0 1 2 3 3 3 3 3 3 3 3 3 3 2 1 0
0 1 2 2 2 2 2 2 2 2 2 2 2 2 1 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Just look at your neighbors N, S, E , W and decide where to go.

Somehow you have to keep track of going around the circle, because up would go up on one side but down on the other, so that’s what I mean when I say it’s not fully defined.

You can use Mathf.Atan2() to find where you are on the clock around the pyramid, and then decide which way is closer to “clockwise” or “anti-clockwise” based on angles.

Again though, I’d probably just hard-code it into four big tables of where each key goes.

ok I will hardcode this sucker , thanks for the help