RE: [Flashcoders] Grid / Math - getting neighbouring positions
Here is my stab at it... function getGridRing( $r:Number, $c:Number, dist:Number, minRow:Number, minCol:Number, maxRow:Number, maxCol:Number ):Array { // @ $r = start row // @ $c = start column // @ dist = destination ring trace( 'row: ' + $r + ' col: ' + $c + ' ring: ' + dist); // length of ring var len = ( dist * 2 ) + 1; // error check for single point if ( len = 1 ) return [{row:$r, col:$c}]; else var array = []; // return only values in bounds [ optional ] var inBounds = function ( r, c ) { if(!isNaN(minRow)) {if ( minRow r ) return false;} if(!isNaN(minCol)) {if ( minCol c ) return false;} if(!isNaN(maxRow)) {if ( maxRow r ) return false;} if(!isNaN(maxCol)) {if ( maxCol c ) return false;} return true; } // TOP for ( var i = 0; i len ; i++ ) { var c = $c - dist + i var r = $r - dist; if( inBounds( r,c )) array.push ({row:r, col:c }) } // RIGHT for ( var i = 1; i len; i++ ) { var c = $c + dist; var r = $r - dist + i; if( inBounds( r,c )) array.push ({row:r, col:c }) } // BOTTOM for ( var i = 1; i len; i++ ) { var c = $c + dist - i var r = $r + dist; if( inBounds( r,c )) array.push ({row:r, col:c }) } // LEFT for ( var i = 1; i len-1; i++ ) { var c = $c - dist; var r = $r + dist - i; if( inBounds( r,c )) array.push ({row:r, col:c }) } return array; } function getGridRings ( r:Number, c:Number, minR:Number, minC:Number, maxR:Number, maxC:Number ):Array { var maxLen = Math.max( Math.max ( Math.abs(maxC-c), Math.abs(minC-c) ), Math.max ( Math.abs(maxR-r), Math.abs(minR-r) ) ); if ( !isNaN(maxLen) ) { var array = []; for ( var i = 0; i = maxLen; i++ ) { array = array.concat( getGridRing ( r, c, i, minR, minC, maxR, maxC ) ); } return array; } return []; } // // // SINGLE RING // // var array = getGridRing ( 2, 2, 0 ); var result = ''; for ( var i in array ) { result = '[' + array[i].col + ',' + array[i].row +'] ' + result } trace( result + newline ) // [2,2] // [2,2] var array = getGridRing ( 2, 2, 1 ); var result = ''; for ( var i in array ) { result = '[' + array[i].col + ',' + array[i].row +'] ' + result } trace( result + newline ) // [1,1] [2,1] [3,1] [3,2] [3,3] [2,3] [1,3] [1,2] // [1,1] [2,1] [3,1] // [1,2] [2,2] [3,2] // [1,3] [2,3] [3,3] var array = getGridRing ( 2, 2, 2, 0, 0, 4, 4 ); var result = ''; for ( var i in array ) { result = '[' + array[i].col + ',' + array[i].row +'] ' + result } trace( result + newline ) // [0,0] [1,0] [2,0] [3,0] [4,0] [4,1] [4,2] [4,3] [4,4] [3,4] [2,4] [1,4] [0,4] [0,3] [0,2] [0,1] // [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] // // // ALL RINGS // // var array = getGridRings ( 2, 2, 0, 0, 4, 4 ) var result = ''; for ( var i in array ) { result = '[' + array[i].col + ',' + array[i].row +'] ' + result } trace( result + newline ) // [2,2] [1,1] [2,1] [3,1] [3,2] [3,3] [2,3] [1,3] [1,2] [0,0] [1,0] [2,0] [3,0] [4,0] [4,1] [4,2] [4,3] [4,4] [3,4] [2,4] [1,4] [0,4] [0,3] [0,2] [0,1] var array = getGridRings ( 0, 0, 0, 0, 4, 4 ) var result = ''; for ( var i in array ) { result = '[' + array[i].col + ',' + array[i].row +'] ' + result } trace( result + newline ) // [0,0] [1,0] [1,1] [0,1] [2,0] [2,1] [2,2] [1,2] [0,2] [3,0] [3,1] [3,2] [3,3] [2,3] [1,3] [0,3] [4,0] [4,1] [4,2] [4,3] [4,4] [3,4] [2,4] [1,4] [0,4] _ Jesse Graupmann www.jessegraupmann.com www.justgooddesign.com/blog/ _ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jiri Heitlager | dadata.org Sent: Saturday, June 16, 2007 5: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
Re: [Flashcoders] Grid / Math - getting neighbouring positions
Perhaps it is just me but your solution and does not get all the grid locations. All this does is get the grid locations in a direct horizontal, vertical and 45 degree angle from the starter grid. Go out 2 or 3 levels and you quickly find that there are grid spots missing. Charles P. On 6/17/07, Joshua Sera [EMAIL PROTECTED] wrote: The easy way to do this is like so. So you have a square at x,y, and you want to get all the squares n squares away. Get squares x+n, y x-n, y x+n, y+n x-n, y+n x+n, y-n x-n, y-n x, y+n x, y-n I suspect you want to do this for your version of that whale-ey thing though, so what you actually want to do is a bit different. First off, to find out which grid square a point fits into (this being the center of where your user is looking): You need the height and width of your grid squares. Take your point (x, y) Your point fits into grid square [Math.floor(x/squareWidth), Math.floor(y/squareHeight)] Apply this by figuring out where on the big picture your person is looking. After that, move left and up by half the screen width, and height, then right and down by the same amount, and you have the ranges of squares to get in order to display that part of the image. --- Jiri Heitlager | dadata.org [EMAIL PROTECTED] wrote: Please I really need help on this on, I am cracking my head over it. Bresenham algo is also not the way to go, because it is for circle's and to complex! I can only get one ring, arggg If I go one ring further then it results in many double values, calculate allready when doing the first ring. Here is the code.. var row = 0; var c:Number = 3; var ring:Number = 1; //take start pos [2,2] var x:Number = 2; var y:Number = 2; // while (rowc) { for (var i:Number = 0; ic; i++) { var rowID:Number = (x-ring)+i; var colID:Number = (y-ring)+row; if (rowID0 || colID0 /* || (rowID == sR colID == sC)*/) { continue; } trace('['+colID+','+rowID+']'); } row++; } ___ 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 ___ You snooze, you lose. Get messages ASAP with AutoCheck in the all-new Yahoo! Mail Beta. http://advision.webevents.yahoo.com/mailbeta/newmail_html.html ___ 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
RE: [Flashcoders] Grid / Math - getting neighbouring positions
I'll take it ;) thanks for everybody's help. Just catching up on this, you might want to try looking up floodFill algorithms - that's pretty much what you're doing. Danny ___ 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
RE: [Flashcoders] Grid / Math - getting neighbouring positions
That is a nice solution, but it leaves me with the problem that starting from one point (3,2) it only produces a set of points of ring directly around the selected point. I am looking for a solution to get _all_ the points, from a certain point and the move in a ring towerds the outside of a grid. Uh, you can still do that with my code - just modify it as needs be. You know how long each array is, you can move out from the center by moving one place back in the arrray in one direction, one way in the other by increasing the position in the array. Take it or leave it I guess. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team ___ 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
Re: [Flashcoders] Grid / Math - getting neighbouring positions
I'll take it ;) thanks for everybody's help. Jiri Merrill, Jason wrote: That is a nice solution, but it leaves me with the problem that starting from one point (3,2) it only produces a set of points of ring directly around the selected point. I am looking for a solution to get _all_ the points, from a certain point and the move in a ring towerds the outside of a grid. Uh, you can still do that with my code - just modify it as needs be. You know how long each array is, you can move out from the center by moving one place back in the arrray in one direction, one way in the other by increasing the position in the array. Take it or leave it I guess. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team ___ 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
Re: [Flashcoders] Grid / Math - getting neighbouring positions
Please I really need help on this on, I am cracking my head over it. Bresenham algo is also not the way to go, because it is for circle's and to complex! I can only get one ring, arggg If I go one ring further then it results in many double values, calculate allready when doing the first ring. Here is the code.. var row = 0; var c:Number = 3; var ring:Number = 1; //take start pos [2,2] var x:Number = 2; var y:Number = 2; // while (rowc) { for (var i:Number = 0; ic; i++) { var rowID:Number = (x-ring)+i; var colID:Number = (y-ring)+row; if (rowID0 || colID0 /* || (rowID == sR colID == sC)*/) { continue; } trace('['+colID+','+rowID+']'); } row++; } ___ 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
Re: [Flashcoders] Grid / Math - getting neighbouring positions
The easy way to do this is like so. So you have a square at x,y, and you want to get all the squares n squares away. Get squares x+n, y x-n, y x+n, y+n x-n, y+n x+n, y-n x-n, y-n x, y+n x, y-n I suspect you want to do this for your version of that whale-ey thing though, so what you actually want to do is a bit different. First off, to find out which grid square a point fits into (this being the center of where your user is looking): You need the height and width of your grid squares. Take your point (x, y) Your point fits into grid square [Math.floor(x/squareWidth), Math.floor(y/squareHeight)] Apply this by figuring out where on the big picture your person is looking. After that, move left and up by half the screen width, and height, then right and down by the same amount, and you have the ranges of squares to get in order to display that part of the image. --- Jiri Heitlager | dadata.org [EMAIL PROTECTED] wrote: Please I really need help on this on, I am cracking my head over it. Bresenham algo is also not the way to go, because it is for circle's and to complex! I can only get one ring, arggg If I go one ring further then it results in many double values, calculate allready when doing the first ring. Here is the code.. var row = 0; var c:Number = 3; var ring:Number = 1; //take start pos [2,2] var x:Number = 2; var y:Number = 2; // while (rowc) { for (var i:Number = 0; ic; i++) { var rowID:Number = (x-ring)+i; var colID:Number = (y-ring)+row; if (rowID0 || colID0 /* || (rowID == sR colID == sC)*/) { continue; } trace('['+colID+','+rowID+']'); } row++; } ___ 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 ___ You snooze, you lose. Get messages ASAP with AutoCheck in the all-new Yahoo! Mail Beta. http://advision.webevents.yahoo.com/mailbeta/newmail_html.html ___ 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
Re: [Flashcoders] Grid / Math - getting neighbouring positions
Thxn Joshua and others, I have to look into that. In the mean time I came up with the following code. This takes in a vector and then calculates a 'ring' from that position. With this, I can scale up the 'radius' and get recursively get all the rings from a point from in to outer ring. My goal i still to fill an array with all the points of the grid, starting from a center point en then moving outwards in a ring. Here is the code so far, i hope someone can maybe give some commment on it. var i:Number = 0; var cycle:Number = 1; var dir:Number = 1; var count:Number = 3; var row:Number = 0; function getTiles(startX:Number , startY:Number) : Void { //startX -= (count-1); //startY -= (count-1); var x:Number = 0; var y:Number = 0; while (cycle=4) { if (cycle2 dir == 1) { dir = -1; } row = (cycle%2); while (icount) { if (dir == 1) { if (row) { display(startX + x, startY + y); x++; } else { display(startX + x, startY + y); y++; } } else { if (row) { display(startX + x, startY + y); x--; } else { display(startX + x, startY + y); y--; } } i++; } i = 0; cycle++; } } function display(x, y) { trace('['+x+','+y+']'); } getTiles(2,2) ___ 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] 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
Re: [Flashcoders] Grid / Math - getting neighbouring positions
It depends how you define the rings. It is by distance or by connectedness? Is 0,0 in the second ring with 1.0 and 0,1? What is the purpose of knowing this? Ron Jiri Heitlager | dadata.org wrote: 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
RE: [Flashcoders] Grid / Math - getting neighbouring positions
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; imyGrid.row.length; i++) { var thisRow:Object = myGrid.row[i] for(var n=0; nthisRow.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 GTO 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
Re: [Flashcoders] Grid / Math - getting neighbouring positions
The ring is defined by distance not by connectedness. It is used for the following. A big image will be split into tiles of 100x100 pixels, that are loaded from a server. The total image made of these tiles are loaded in a movieclip so that the image is rebuilded. The image is masked by a 100x100 mask and can be scrolled to left and right. Based on the tile that is in the view, i would like to preload the rest of the tiles 'intelligently'. To do this, i take the current tile and start building a loadingQue Array from there. So first the ring around the current tile, the a ring around the first ring and so on, until all the tiles of the total image are in the array. Does that make sense? JIri Ron Wheeler wrote: It depends how you define the rings. It is by distance or by connectedness? Is 0,0 in the second ring with 1.0 and 0,1? What is the purpose of knowing this? Ron Jiri Heitlager | dadata.org wrote: 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 ___ 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
Re: [Flashcoders] Grid / Math - getting neighbouring positions
That is a nice solution, but it leaves me with the problem that starting from one point (3,2) it only produces a set of points of ring directly around the selected point. I am looking for a solution to get _all_ the points, from a certain point and the move in a ring towerds the outside of a grid. Jiri Merrill, Jason wrote: 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; imyGrid.row.length; i++) { var thisRow:Object = myGrid.row[i] for(var n=0; nthisRow.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 GTO 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 ___ 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