Color a mesh by height and width

Dear Community,

I am trying to color an object based on the width of this later. I tried to inspire myself from this code But this later is for the height. And I want to set a color map based on the width for each z-slice, like the figure below

Can you please help me.
Thank you

Duplicate: Color a vtk object by width