How to use the lesscpy.lessc.utility.convergent_round function in lesscpy

To help you get started, we’ve selected a few lesscpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lesscpy / lesscpy / test / test_utility.py View on Github external
def test_convergent_round(self):
        test = utility.convergent_round
        self.assertEqual(-4, test(-4.5))
        self.assertEqual(-4, test(-3.5))
        self.assertEqual(-2, test(-2.5))
        self.assertEqual(-2, test(-1.5))
        self.assertEqual(0, test(-0.5))
        self.assertEqual(0, test(0.5))
        self.assertEqual(2, test(1.5))
        self.assertEqual(2, test(2.5))
        self.assertEqual(3.0, test(10.0 / 3, 0))
        self.assertEqual(4, test(3.5))
        self.assertEqual(4, test(4.5))
github lesscpy / lesscpy / lesscpy / lessc / color.py View on Github external
def hsl(self, *args):
        """ Translate hsl(...) to color string
        raises:
            ValueError
        returns:
            str
        """
        if len(args) == 4:
            return self.hsla(*args)
        elif len(args) == 3:
            h, s, l = args
            rgb = colorsys.hls_to_rgb(
                int(h) / 360.0, utility.pc_or_float(l), utility.pc_or_float(s))
            color = (utility.convergent_round(c * 255) for c in rgb)
            return self._rgbatohex(color)
        raise ValueError('Illegal color values')
github lesscpy / lesscpy / lesscpy / lessc / color.py View on Github external
def hsla(self, *args):
        """ Translate hsla(...) to color string
        raises:
            ValueError
        returns:
            str
        """
        if len(args) == 4:
            h, s, l, a = args
            rgb = colorsys.hls_to_rgb(
                int(h) / 360.0, utility.pc_or_float(l), utility.pc_or_float(s))
            color = [float(utility.convergent_round(c * 255)) for c in rgb]
            color.append(utility.pc_or_float(a))
            return "rgba(%s,%s,%s,%s)" % tuple(color)
        raise ValueError('Illegal color values')
github lesscpy / lesscpy / lesscpy / lessc / color.py View on Github external
args:
            color (str): color
            degree (str): percentage
        raises:
            ValueError
        returns:
            str
        """
        if color and degree:
            if isinstance(degree, string_types):
                degree = float(degree.strip('%'))
            h, l, s = self._hextohls(color)
            h = ((h * 360.0) + degree) % 360.0
            h = 360.0 + h if h < 0 else h
            rgb = colorsys.hls_to_rgb(h / 360.0, l, s)
            color = (utility.convergent_round(c * 255) for c in rgb)
            return self._rgbatohex(color)
        raise ValueError('Illegal color values')
github lesscpy / lesscpy / lesscpy / lessc / color.py View on Github external
def hue(self, color, *args):
        """ Return the hue value of a color
        args:
            color (str): color
        raises:
            ValueError
        returns:
            float
        """
        if color:
            h, l, s = self._hextohls(color)
            return utility.convergent_round(h * 360.0, 3)
        raise ValueError('Illegal color values')