[Closed] Nested array
Hi.
Got a little trouble with arrays.
I need to store every pixel color of a very small video into an array so i can access any of them later.
The script is very simple and stores properly a frame of the video into an array like this:
[size=1]work_bmp = openbitmap “e:\pam.mov”
bmp_w = work_bmp.width
bmp_h = work_bmp.height
pixelcanva = #()
for h = 1 to bmp_h do
(
pixel_line = getpixels work_bmp [(0),(h-1)] (bmp_w)
pixelcanva = join pixelcanva pixel_line
)
so if i type “pixelcanva[value]” it returns the color of the pixel i want(all pixels of the frame are stored in this array)
Now i’d like to store the whole video in order to access the pixel i want at the frame i want.
I put a simple loop in it like this:
work_bmp = openbitmap “e:\pam.mov”
bmp_w = work_bmp.width
bmp_h = work_bmp.height
pixelfilm = #()
pixelcanva = #()
lastframe = work_bmp.numframes
for i = 1 to lastframe do
(
work_bmp.frame = i
for h = 1 to bmp_h do
(
[size=1]pixel_line = getpixels work_bmp [(0),(h-1)] (bmp_w)
pixelcanva = join pixelcanva pixel_line
)
[i]pixelfilm= pixelcanva
)
And i’d like to access the pixel of the frame i want by typing “pixelfilm[frame][value].
However it seems that i stored the same frame all the way long.
I think i may have nested the array incorrectly.
If someone could explain me where i’m wrong i would be very grateful.
Thanks.
[/size][/size]
Hey Grenadine, the problem is that you define the pixelcanva array in the wrong place. It should be defined within the first loop so that the pixelcanva array is empty when you check each new frame.
Like this:
work_bmp = openbitmap “e:\pam.mov”
bmp_w = work_bmp.width
bmp_h = work_bmp.height
pixelfilm = #()
–not here
lastframe = work_bmp.numframes
for i = 1 to lastframe do
(
pixelcanva = #() –put it here
work_bmp.frame = i
for h = 1 to bmp_h do
(
[size=1]pixel_line = getpixels work_bmp [(0),(h-1)] (bmp_w)
pixelcanva = join pixelcanva pixel_line
)
[i]pixelfilm= pixelcanva
)[/size]
Hope it works out,
CML
Another thing you will want to change is that the first frame in a .mov file is 0 so you would need to write:
work_bmp.frame = i-1
cheers,
CML
Thank you very much Rivendale, works perfectly.
I was so worried about using arrays i didn’t look around enough to find out.
Must cool myself a bit
thanks again