This requires you to re-do your grid, but it's one way to handle it
without complex math. It seems a simple way would be to make each row of
the grid an array (the entire thing can be an array as well, but make
each row it's own array).  You could do some object mix-in to ease
syntax and allow for storing complex data types:

myGrid = {row:[{cell:[{id:0},{id:1},{id:2},{id:3}], id:0},
                 {cell:[{id:0},{id:1},{id:2},{id:3}], id:1},
                 {cell:[{id:0},{id:1},{id:2},{id:3}], id:2},
                 {cell:[{id:0},{id:1},{id:2},{id:3}], id:3}]}

(you would make that with for-loops, not necessarily hand-type, though
you could)

So the cell at position 3,2 would be: myGrid.row[2].cell[1] (since
arrays start at 0)

So to get surrounding cells of myGrid.row[2].cell[1], it would be:

myGrid.row[1].cell[0]
myGrid.row[1].cell[1]
myGrid.row[1].cell[2]
myGrid.row[2].cell[0]
myGrid.row[2].cell[2]
myGrid.row[3].cell[0]
myGrid.row[3].cell[1]
myGrid.row[3].cell[2]

In other words, for the cell up and to the left of the current cell, it
would be:

        myGrid.row[thisRow.id-1].cell[thisCell.id-1]

the grid cell directly above would be:

        myGrid.row[thisRow.id-1].cell[thisCell.id]

the grid cell directly above and to the right would be:

        myGrid.row[thisRow.id-1].cell[thisCell.id+1]

the grid cell directly to the left would be:

        myGrid.row[thisRow.id].cell[thisCell.id-1]

etc.

get thisRow and thisCell objects with for loops.

for(var i-0; i<myGrid.row.length; i++)
{
        var thisRow:Object = myGrid.row[i]
        for(var n=0; n<thisRow.cell.length; n++)
        {
                var thisCell:Object = thisRow.cell[n]
                //do get grid spaces logic as desc. above here
        }
}

Restructure the grid objects to contain the data you need.  Make sense?
Maybe that's not how you want to handle a grid, but that's what works
for me - less math that way.


Jason Merrill
Bank of America  
GT&O Learning & Leadership Development
eTools & Multimedia Team


 

>>-----Original Message-----
>>From: [EMAIL PROTECTED] 
>>[mailto:[EMAIL PROTECTED] On Behalf 
>>Of Jiri Heitlager | dadata.org
>>Sent: Saturday, June 16, 2007 8:16 AM
>>To: flashcoders@chattyfig.figleaf.com
>>Subject: [Flashcoders] Grid / Math - getting neighbouring positions
>>
>>Hello list,
>>
>>I have the following grid and would like to find the 
>>neighbouring positions of a certain point, going in a radius 
>>from in to out, covering all the positions.
>>
>>[0,0] [1,0] [2,0] [3,0] [4,0]
>>[0,1] [1,1] [2,1] [3,1] [4,1]
>>[0,2] [1,2] [2,2] [3,2] [4,2]
>>[0,3] [1,3] [2,3] [3,3] [4,3]
>>[0,4] [1,4] [2,4] [3,4] [4,4]
>>
>>Let say I take point [2,2] then its neighbours are in the 
>>first ring [1,1] [2,1] [3,1] [3,2] [3,3] [2,3] [1,3] [1,2] I 
>>manage to get the first ring, but getting the other rings I 
>>haven't got a clue on how to do that.
>>
>>Can somebody help me?
>>
>>Thank you,
>>
>>jiri
>>_______________________________________________
>>Flashcoders@chattyfig.figleaf.com
>>To change your subscription options or search the archive:
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>>Brought to you by Fig Leaf Software
>>Premier Authorized Adobe Consulting and Training 
>>http://www.figleaf.com http://training.figleaf.com
>>
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to