-
Populating multidimensional array with numbers
Hi all,
I want to create an array that holds all x and y coordinates of a 168 x 168 grid divided by 4 pixels. So I should end up with someting like this:
[0,0], [0,4], [0,8], [0,12] ... etc.
[4,0], [4,4], [4,8], [4,12] ... etc.
[8,0], [8,4], [8,8], [8,12] ... etc.
... etc.
I've managed to create an x and an y array like this:
Code:
x_array = new Array();
y_array = new Array();
i = 0;
j = 0;
while(i<=(168/4)){
while (j<=168){
x_array.push(j);
y_array.push(j);
//trace("j= "+j);
j = j+4;
}
//trace ("i="+i);
i++
}
This just generates two one dimensional arrays looking like this: 0,4,8,12,16,20 etc. upto 168. But now they need to be put together in one big array...? Is this the way to do it or do you code guru's have other suggestions?
Thanks very much for you help, Danielle.
-
Maybe try something like this...
Code:
xy_array = new Array();
i = 0;
j = 0;
while (i<=168) {
while (j<=168) {
tmp_array = new Array();
tmp_array.push(j);
tmp_array.push(i);
xy_array.push(tmp_array);
j = j+4;
}
i = i+4;
j = 0;
}
trace(xy_array[0]);
trace(xy_array[0][0]);
trace(xy_array[0][1]);
-
thanks
Thanks dawsonk,
Works like a charm! You're an angel!
Danielle.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|