Let’s do this in stages.
First, let’s make all particles of a certain age have the same value. Then we can look at ways to randomize.
The UVs/gradient map approach is a good idea as it is much easier to get the transitions right.
If you are using Krakatoa MX 2.3.x, the Age and LifeSpan are now Float values representing seconds. In other words, an Age of 1.0 means one second. If you are running an older version, the Age and LifeSpan are Integer ticks (4800 per seconds). Since dividing with two Integers does not produce a Float, on must convert both to Floats first, but otherwise the approach is the same.
If you divide Age by the LifeSpan, you get a value that goes from 0.0 to 1.0 over the life of the particle. Once you have that value, you can convert it to Vector (Convert>ToVector) by connecting to the X in socket only, and output the result as TextureCoord or Mapping2. At this point, your particles will have a mapping coordinate channel contains a value of [0,0,0] when Age is 0, and [1,0,0] when Age is equal to LifeSpan.
This means that if you now assign a Standard Material to the PRT Loader and put a Gradient Ramp in the Diffuse map channel and set the mapping channel to the one output by the Magma (Mapping Channel 1 if you used TextureCoord channel, Mapping Channel 2 if you output to Mapping2 etc.), then the colors from left to right in the gradient ramp will match the Age from birth to death!
[attachment=1]KMX2_AgeLifeSpanMapping_step1.png[/attachment]
You can of course drop another Gradient Ramp map in the Self-Illum. channel of the Standard Material and this will produce an Emission channel if you turn on Use Emission in Krakatoa GUI. You can adjust them independently.
At this point, each particle will have the same color at a given Age. To randomize the value, I would suggest adding a Noise operator to the the Magma flow driven by the ID channel, and a Clamp operator to ensure the adjusted mapping value never exceeds the 0.0 to 1.0 range. This is slightly more complicated because the ID channel (as long as you actually saved it) contains Integers, but if you convert an Integer to Float and pipe in a Noise operator, you will get the SAME noise value for each particle because the Noise pattern repeats in the range between two integers (it is tileable). So you need to
*Select the wire connecting the Divide operator behind the Age/LifeSpan with the ToVector we created in the previous step, and press + on the NumPad to insert an Add operator.
*Drag with the mouse from the second input of the Add operator and release over an empty area of the editor. From the menu, select Function > Noise.
*Press SHIFT+I to create an InputChannel ID node.
*Select the InputChannel ID, Convert>ToFloat (there is also a button in the command panel of the InputChannel that reads “Convert To Float” - it is a shortcut)
*Press 6 on the top row to insert a Power operator, then press Ctrl+2 to connect an InputValue of 2.0 to the Exponent input. We do this because particles generated from PFlow typically have sequential IDs. The ID values of two particles born one after the other will be very close and will produce very similar Noise values, thus resulting in a very smoothed-out randomness. By using the square of the ID, we ensure the IDs are made less sequential…
*Re-select the Power operator, then press the / key on the Numpad to insert a Divide operator.
*Press Ctrl+1 to create an InputValue Float, then type in a divider value like 1000 or so. As result, the Noise will wrap around and produce the same noise value every 1000 particles. You can change this value if you want to have it wrap around at different counts.
*Select the Noise operator and press the * key on the Numpad to insert a Multiply operator.
*Press Ctrl+1 to create another InputValue Float, then type in 0.5 - this will scale the Noise value to a smaller range. By default, the Normalize option of the Noise is on, so it will produce values roughly in the range from -1.0 to 1.0. With the Multiply, it will now produce values between -0.5 and 0.5. You can adjust the InputValue to larger or smaller values between 0.0 and 1.0 to define how much each particle’s Age-based mapping should be shifted left or right along the Gradient Ramp.
*Select the Add operator and press F for Function and then C for Clamp. The defaults for Min and Max are 0.0 and 1.0, so this way we ensure our mapping will never exceed the 0 to 1 mapping range. In fact, you can reduce the 1.0 to 0.99 to avoid dying particles from wrapping around to the left-most color of the Gradient Ramp’s…
You can expose the InputValues 1000.0 and 0.5 and rename them to Wrap Around and Offset Scale to have direct access to them from the Modifier Tab…
[attachment=0]KMX2_AgeLifeSpanMapping_step2.png[/attachment]