Color cubes with e.g. a linear function?

Dear Community,

I’ve constructed a few cubes with indices from 1 to 9. (see Cubes.nb) I would like to color them with e.g. a linear function. Cube 1 should be e.g. blue, cube 9 e.g. red, and the remaining cubes should change color linearly between blue and red. How could I do it? I guess it has something to do with the ColorFunction but its not clear how to use it.

Tx for the help in advance, best regards
Andras

Cubes.nb (6.47 KB)

something like this

cubes[[ic]]     = {Hue[(3i+j)/10],Cuboid[ {i-0.5,j-0.5,1} , {i+0.5,j+0.5,2} ]} ;

Dear Frank,

Perfect, thank you very much :-).

Andras