Skip to content

Instantly share code, notes, and snippets.

@strathmeyer
Forked from hdznrrd/gist:656996
Created August 12, 2012 04:59

Revisions

  1. strathmeyer revised this gist Aug 12, 2012. 1 changed file with 9 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    void HSV_to_RGB(float h, float s, float v, byte &r, byte &g, byte &b)
    {
    int i,f,p,q,t;
    int i;
    float f,p,q,t;

    h = constrain(h, 0.0, 360.0);
    s = constrain(s, 0.0, 100.0);
    @@ -9,18 +10,18 @@ void HSV_to_RGB(float h, float s, float v, byte &r, byte &g, byte &b)
    s /= 100;
    v /= 100;

    if(s == 0) {
    if (s == 0) {
    // Achromatic (grey)
    r = g = b = round(v*255);
    return;
    }

    h /= 60; // sector 0 to 5
    i = floor(h);
    f = h - i; // factorial part of h
    p = v * (1 - s);
    q = v * (1 - s * f);
    t = v * (1 - s * (1 - f));
    h /= 60.0;
    i = floor(h); // sector 0 to 5
    f = h - (float)i; // factorial part of h
    p = v * (1.0 - s);
    q = v * (1.0 - s * f);
    t = v * (1.0 - s * (1 - f));
    switch(i) {
    case 0:
    r = round(255*v);
  2. strathmeyer revised this gist Aug 12, 2012. 1 changed file with 20 additions and 20 deletions.
    40 changes: 20 additions & 20 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    void HSV_to_RGB(float h, float s, float v, byte *r, byte *g, byte *b)
    void HSV_to_RGB(float h, float s, float v, byte &r, byte &g, byte &b)
    {
    int i,f,p,q,t;

    @@ -11,7 +11,7 @@ void HSV_to_RGB(float h, float s, float v, byte *r, byte *g, byte *b)

    if(s == 0) {
    // Achromatic (grey)
    *r = *g = *b = round(v*255);
    r = g = b = round(v*255);
    return;
    }

    @@ -23,33 +23,33 @@ void HSV_to_RGB(float h, float s, float v, byte *r, byte *g, byte *b)
    t = v * (1 - s * (1 - f));
    switch(i) {
    case 0:
    *r = round(255*v);
    *g = round(255*t);
    *b = round(255*p);
    r = round(255*v);
    g = round(255*t);
    b = round(255*p);
    break;
    case 1:
    *r = round(255*q);
    *g = round(255*v);
    *b = round(255*p);
    r = round(255*q);
    g = round(255*v);
    b = round(255*p);
    break;
    case 2:
    *r = round(255*p);
    *g = round(255*v);
    *b = round(255*t);
    r = round(255*p);
    g = round(255*v);
    b = round(255*t);
    break;
    case 3:
    *r = round(255*p);
    *g = round(255*q);
    *b = round(255*v);
    r = round(255*p);
    g = round(255*q);
    b = round(255*v);
    break;
    case 4:
    *r = round(255*t);
    *g = round(255*p);
    *b = round(255*v);
    r = round(255*t);
    g = round(255*p);
    b = round(255*v);
    break;
    default: // case 5:
    *r = round(255*v);
    *g = round(255*p);
    *b = round(255*q);
    r = round(255*v);
    g = round(255*p);
    b = round(255*q);
    }
    }
  3. strathmeyer revised this gist Aug 12, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,9 @@ void HSV_to_RGB(float h, float s, float v, byte *r, byte *g, byte *b)
    {
    int i,f,p,q,t;

    h = max(0.0, min(360.0, h));
    s = max(0.0, min(100.0, s));
    v = max(0.0, min(100.0, v));
    h = constrain(h, 0.0, 360.0);
    s = constrain(s, 0.0, 100.0);
    v = constrain(v, 0.0, 100.0);

    s /= 100;
    v /= 100;
    @@ -52,4 +52,4 @@ void HSV_to_RGB(float h, float s, float v, byte *r, byte *g, byte *b)
    *g = round(255*p);
    *b = round(255*q);
    }
    }
    }
  4. @hdznrrd hdznrrd revised this gist Oct 31, 2010. 1 changed file with 18 additions and 18 deletions.
    36 changes: 18 additions & 18 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -23,33 +23,33 @@ void HSV_to_RGB(float h, float s, float v, byte *r, byte *g, byte *b)
    t = v * (1 - s * (1 - f));
    switch(i) {
    case 0:
    *r = v;
    *g = t;
    *b = p;
    *r = round(255*v);
    *g = round(255*t);
    *b = round(255*p);
    break;
    case 1:
    *r = q;
    *g = v;
    *b = p;
    *r = round(255*q);
    *g = round(255*v);
    *b = round(255*p);
    break;
    case 2:
    *r = p;
    *g = v;
    *b = t;
    *r = round(255*p);
    *g = round(255*v);
    *b = round(255*t);
    break;
    case 3:
    *r = p;
    *g = q;
    *b = v;
    *r = round(255*p);
    *g = round(255*q);
    *b = round(255*v);
    break;
    case 4:
    *r = t;
    *g = p;
    *b = v;
    *r = round(255*t);
    *g = round(255*p);
    *b = round(255*v);
    break;
    default: // case 5:
    *r = v;
    *g = p;
    *b = q;
    *r = round(255*v);
    *g = round(255*p);
    *b = round(255*q);
    }
    }
  5. @hdznrrd hdznrrd created this gist Oct 31, 2010.
    55 changes: 55 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    void HSV_to_RGB(float h, float s, float v, byte *r, byte *g, byte *b)
    {
    int i,f,p,q,t;

    h = max(0.0, min(360.0, h));
    s = max(0.0, min(100.0, s));
    v = max(0.0, min(100.0, v));

    s /= 100;
    v /= 100;

    if(s == 0) {
    // Achromatic (grey)
    *r = *g = *b = round(v*255);
    return;
    }

    h /= 60; // sector 0 to 5
    i = floor(h);
    f = h - i; // factorial part of h
    p = v * (1 - s);
    q = v * (1 - s * f);
    t = v * (1 - s * (1 - f));
    switch(i) {
    case 0:
    *r = v;
    *g = t;
    *b = p;
    break;
    case 1:
    *r = q;
    *g = v;
    *b = p;
    break;
    case 2:
    *r = p;
    *g = v;
    *b = t;
    break;
    case 3:
    *r = p;
    *g = q;
    *b = v;
    break;
    case 4:
    *r = t;
    *g = p;
    *b = v;
    break;
    default: // case 5:
    *r = v;
    *g = p;
    *b = q;
    }
    }