Paste: Sam

Author: hsv2rgb
Mode: python
Date: Fri, 18 Sep 2009 23:18:36
Plain Text |
from math import floor

class HSV:

    def __init__(self, h, s, v):
        self.hue = h
        self.saturation = s
        self.value = v

def Hi(hsv):
    return floor(hsv.hue / 60) % 6

def f(hsv):
    return hsv.hue / 60 - Hi(hsv)

def p(hsv):
    return (1 - hsv.saturation) * hsv.value

def q(hsv):
    return (1 - f(hsv) * hsv.saturation) * hsv.value

def t(hsv):
    return (1 - ((1 - f(hsv)) * hsv.saturation)) * hsv.value

def hsv2rgb(hsv):
    h = Hi(hsv)
    if h == 0:
        return hsv.value, t(hsv), p(hsv)
    elif h == 1:
        return q(hsv), hsv.value, p(hsv)
    elif h == 2:
        return p(hsv), hsv.value, t(hsv)
    elif h == 3:
        return p(hsv), q(hsv), hsv.value
    elif h == 4:
        return t(hsv), p(hsv), hsv.value
    else:
        return hsv.value, p(hsv), q(hsv)






New Annotation

Summary:
Author:
Mode:
Body: