# How to colorize particles by rules

I am having pipes where I have liquid go through it. I want to simulate/show the water and show some blue to red color animation. Blue for cold, red for heat/warmth.

For best control, it would be great to define some kind of color change areas on the path of the water simulation and when a water particle goes through this area, I want to change the color for this particle. The color needs to be kept, until the next color-change area is there and changes the color again.

So I could control and simulate a heat-transfer simulation.

Any ideas how to do this the best way?

Thank you guys!

EDIT: Here is a screenshot of the animation. You can see the position by Particial works in general. But I want to colorize the blue particles inside the 3 red circles to the color red and they should in their color. I somehow lost my fluid simulation data, so I can't share the .blend file. Sorry.

• If you can define any function f(xyz) that return the values in the field, you can do it in shader nodes.. Circles aren't volumes.. do you mean cylinders, or spheres? Sep 12, 2020 at 16:24
• @RobinBetts Hi Robin, do you have an example of those shader nodes? Yes, I mean cylinders. Was just to make things easier. Sep 13, 2020 at 15:39

You can shade an object in another object's space, so perhaps, rather than do all the math to figure out where your red-zone cylinders should be, it would be more user-friendly to make actual cylinders that control the colour of your particles.

I've called mine 'RedZone'. Their Object texture coordinates are used in the shader for the particles, to make a mask, as follows:

The XY lengths from the cylinder's centres, clamped, return a 0-1 mask inside them, and 1 outside. (The cylinders must have their scale applied at creation radius, 1) If you scale the Cylinders in Object Mode, the masks will follow. Combining the masks with a minimum, and putting them through an (inverting) colour ramp, lets you soften the masks. The combination controls the mix of colors.

You could add more cylinders and use more minimums to mix those in.

The .blend file is only good for the nodes, I haven't packed the particles.

• @Felix, I've taken you very literally.. If you need a less simple-minded answer, just ask. Sep 13, 2020 at 20:36
• Thanks for your very helpful answer! Is there a reason why you set the Z axis to 0? Also: "The cylinders must have their scale applied at creation radius". What does that mean? Am I free to just scale up, move, rotate those RedZones like I wish or do I have to look out for something? Thanks! Sep 13, 2020 at 22:41
• @Felix For the red patch to match the cylinder, with this set up, the radius of the cylinder must be 1, when the cylinder's scale is 1. That's all.. that's the way a cylinder is when you create it. Z is set to 0 because we're not interested in it.. it shouldn't make a contribution to the length. If we did include it, the red zones would be spherical, not infinitely-high cylindrical. If we need to cap the cylinders, the Z would be included later.. something like 'XY length < 1 AND abs(Z) < whatever'. Yes, you can move, scale, rotate the cylinders in Object mode. Sep 13, 2020 at 22:51
• Hey guys can make the cylinder that changes the particle colours hollow and will this still work ? I only want my particles to change colour on the outside of the cylinder and not the inside. May 29, 2023 at 11:28
• Hi, Casey, you should just be able to use the color-ramp to do that-- you may need to map the actual distances in your simulation down to 0-1 to fit into the ramp, using a Map Range node May 29, 2023 at 14:47

You can just use a Particle Info node and use it's Position output to control the color of the particles

• Hi, this work only partially. Because so I can only create a simple gradient effect from 1 source. I somehow need a way to use some kind of color force field the particles go through and then change color like I wish... Sep 12, 2020 at 12:08
• Yes, you can do it. To determine a color field you can use a 3D texture (like noise or a gradient) or math. If you want to do a heat-transfer simulation you probably have some math data/formula that say "in coordinates x,y and z the color is k", and to do that you just need the particle position. Sep 12, 2020 at 12:13
• @Felix Blendend Basically, share your .blend file or some pictures, so we know what you want Sep 12, 2020 at 12:14
• I updated the question above. Sep 12, 2020 at 22:08