POV-Ray : Newsgroups : povray.advanced-users : With all the talk of color, HCY : With all the talk of color, HCY Server Time: 23 Jul 2019 12:40:22 GMT
  With all the talk of color, HCY  
From: INVALID ADDRESS
Date: 26 Nov 2016 18:23:53
Here is the code I use for working with HCY in Processing, I know this
isn't SDL but I do not at present have time to convert it and I thought
someone might find it useful.

For me it is wonderful because using only one array I can get the range and
intensity of colors I want far more easily than I can with other models, I
just pipe it into H and set C and Y to the value below...though it really
gets interesting when you plug other arrays into Y in particular. That
works out very well for 2 chemical RD systems obviously, which is what I
use it for.

//    H Varies
//    C = 100 [gives full brightness]
//    Y = 75 or varies. [gives full saturation]
public color HCYtoRGB(float h, float c, float y)
{
    final PVector REC709y = new PVector(0.2126, 0.7152, 0.0722);
    PVector hcy = new PVector(h, c, y);
  
    float r = constrain(abs(6 * h - 3) - 1, 0, 1);
    float g = constrain(2 - abs(6 * h - 2), 0, 1);
    float b = constrain(2 - abs(6 * h - 4), 0, 1);

    PVector rgb = new PVector(r, g, b);
  
    float z = rgb.dot(REC709y);

    if (z >= hcy.z)
    {
        hcy.y *= hcy.z / z;
    }
    else if (z < 1)
    {
        hcy.y *= (1 - hcy.z) / (1 - z);
    }
  
    rgb.sub(z, z, z);
    rgb.mult(hcy.y);
    rgb.add(hcy.z, hcy.z, hcy.z);
  
    rgb.mult(255);

    return color(rgb.x, rgb.y, rgb.z);
}

I hope this is useful to someone. Have fun. :)

I have a render (Processing not Pov) of the predator-prey RD system by
Sirohi et. al. 2015 which will go up on Flickr soon which uses this.

Ian


Post a reply to this message

Copyright 2003-2008 Persistence of Vision Raytracer Pty. Ltd.