POV-Ray : Newsgroups : povray.text.tutorials : ARRAYS: More possibilities then the manual tells us : ARRAYS: More possibilities then the manual tells us Server Time23 Jun 2021 14:39:46 EDT (-0400)
 ARRAYS: More possibilities then the manual tells us
 From: Jaap Frank Date: 14 Jul 2003 20:02:35 Message: <3f13449b\$1@news.povray.org>
```Hi,

this is a small explanation of advanced use of arrays.
In the manual you will find several limitations in using
arrays, but you can circumvent this.

If you declare a multi-dimensional array the normal way,
#declare A = array[2][2][2]
you can't take a single dimension from it:
#declare B = A[2][2]    // this gives an error

Also you can't put different things in it. Once you have
initiated one entry with some kind of variable type, all the
other entries have to be of the same kind.
But, ... you can put everything what you like in it,
arrays too!

If you declare an array, you give it a name:
#declare Times = array[2]
You then put some values in it:
#declare Times[0] = 23.24;
#declare Times[1] = 12.57;
Compare this with:
#declare Times0 = 23.24;
#declare Times1 = 12.57;
Look at it the following way:
It looks as if POVray uses Times[0] and Times[1]
as a name for a variable.
You can then imagine that you can put everything in it.
Only the way the names are stored in memory is different
for arrays.

Here are two examples:

If you want a very high dimensional array, this can be done.
Further you can extract a peace of an array.

// --------- Start of code ----------------------------------------
#declare A = array[2][2][2]
#declare B = array[2][2][2]
#declare C = array[2][2][2]
//    Connect the arrays
#declare B[0][0][0] = C
#declare A[0][0][0] = B
//    Initiate something
#declare A[0][0][0][0][0][0][0][0][0]=0.345;
//    Extract a piece
#declare D = A[0][0][0][0][0][0]

//#declare E = A[0][0][0][0][0] //<-- this gives an error of coarse

#debug str(A[0][0][0][0][0][0][0][0][0],5,3)
// -------   End of code -----------------------------------------

Amazingly POV does not get confused!!

This way it is also possible to put different things into one total array.
In one subarray you can put objects and in other subarrays some
different kind of variables.
So you can build your own multi variable type of array.

// --------- Start of code ----------------------------------------
#declare Obj = 0;
#declare Var = 1;
#declare Tex = 2;
#declare Total = array[3]

// Make the subarrays
#declare Objects = array[2]
#declare Vars = array[4]
{0,1, -1, +1}
#declare Textur = array[2]
{pigment{color rgb <0,1,0>},
pigment{color rgbt <1,1,1,0.4>} }

// Connect everything
#declare Total[Obj] = Objects
#declare Total[Tex] = Textur
#declare Total[Var] = Vars

// Use it:
#declare  Total[Obj][0] =
sphere{ Total[Var][0], Total[Var][1]
texture { Total[Tex][0]}}
#declare  Total[Obj][1] =
box{    Total[Var][2], Total[Var][3]
texture { Total[Tex][1]}}

// Show it:
object {Total[Obj][0]}
object {Total[Obj][1]}

light_source {
<-20, 40, -20>
color rgb <1,1,1> }
camera {
location <0,0,-3>
look_at 0 }

// -------   End of code -----------------------------------------

Why is this useful?
You can give a macro in one name (Total) a couple
of objects and all his variables and let it do something
with it.
For instance: the macro can reach the textures and
can change them.

I hope someone can use this.

Jaap Frank
```