Search code examples
pythoncolorsscaleblenderparticles

color scale to illustrate the temperature, Python script


I make an astronomical visualization, which illustrates a birth of a planet from a cloud of particles (which i have over 130.000). Each particle, besides xyz-coordinate, has also a temperature value.

Is it possible to code it like Temperature minimum is green, Temperature maximum is magenta. Dear script, color my particles in scale between green and magenta?

I am working with Python (Blender).

Thank you in advance for any help!


Solution

  • Not familiar with Blender, but assuming you can assign RGB values, this loop will fade from green to magenta:

    counter = 130000        # number of particles in your cloud
    change = 256 / counter  # in-/de-crement for each particle
    
    rgb = [0, 255, 0]       # starting colour (green)
    
    for i in range(0, counter):
        rgb = [rgb[0] + change, rgb[1] - change, rgb[2] + change]
        print("i: %04d; R: %03d, G: %03d, B: %03d" % (i, rgb[0], rgb[1], rgb[2])) # for debugging only, floats to integers for legibility 
    

    There's probably more sophisticated solutions, but hopefully that'll get you started.