All pastes #907114 Raw Edit

hex.__set__

public text v1 · immutable
·published 2008-02-17 07:08 UTC
rendered paste body
  property hex :
    def __get__(self) :
      cdef float _top
      cdef float _bottom
      
      _top = self._r
      if self._g > _top :
        _top = self._g
      if self._b > _top :
        _top = self._b
      if self._a > _top :
        _top = self._a
        
      _bottom = self._r
      if self._g < _bottom :
        _bottom = self._g
      if self._b < _bottom :
        _bottom = self._b
      if self._a < _bottom :
        _bottom = self._a
        
      if _top < 0 :
        return '#%.2x%.2x%.2x%.2x * %.2f' % (self._a*255*-1*_bottom,
                                             self._r*255*-1*_bottom,
                                             self._g*255*-1*_bottom,
                                             self._b*255*-1*_bottom)
      if _bottom < 0 :
        return '#%.2x%.2x%.2x%.2x' % (self._a*255-_bottom,self._r*255-_bottom,
                                      self._g*255-_bottom,self._b*255-_bottom)
      
      if _top > 1.0 :
        return '#%.2x%.2x%.2x%.2x * %.2f' % (self._a*255/_top,self._r*255/_top,
                                             self._g*255/_top,self._b*255/_top,
                                             _top)
      else :
        return '#%.2x%.2x%.2x%.2x' % (self._a*255,self._r*255,
                                      self._g*255,self._b*255)