$11 GRAYBYTE WORDPRESS FILE MANAGER $83

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python37/lib/python3.7/site-packages/svgwrite/

HOME
Current File : /opt/alt/python37/lib/python3.7/site-packages/svgwrite//gradients.py
#coding:utf-8
# Author:  mozman --<mozman@gmx.at>
# Purpose: gradients module
# Created: 26.10.2010
# Copyright (C) 2010, Manfred Moitzi
# License: MIT License
"""
Gradients consist of continuously smooth color transitions along a vector
from one color to another, possibly followed by additional transitions along
the same vector to other colors. SVG provides for two types of gradients:
linear gradients and radial gradients.
"""

from svgwrite.base import BaseElement
from svgwrite.mixins import Transform, XLink
from svgwrite.utils import is_string


class _GradientStop(BaseElement):
    elementname = 'stop'

    def __init__(self, offset=None, color=None, opacity=None, **extra):
        super(_GradientStop, self).__init__(**extra)

        if offset is not None:
            self['offset'] = offset
        if color is not None:
            self['stop-color'] = color
        if opacity is not None:
            self['stop-opacity'] = opacity


class _AbstractGradient(BaseElement, Transform, XLink):
    transformname = 'gradientTransform'

    def __init__(self, inherit=None, **extra):
        super(_AbstractGradient, self).__init__(**extra)
        if inherit is not None:
            if is_string(inherit):
                self.set_href(inherit)
            else:
                self.set_href(inherit.get_iri())

    def get_paint_server(self, default='none'):
        """ Returns the <FuncIRI> of the gradient. """
        return "%s %s" % (self.get_funciri(), default)

    def add_stop_color(self, offset=None, color=None, opacity=None):
        """ Adds a stop-color to the gradient.

        :param offset: is either a <number> (usually ranging from 0 to 1) or
          a `<percentage>` (usually ranging from 0% to 100%) which indicates where
          the gradient stop is placed. Represents a location along the gradient
          vector. For radial gradients, it represents a percentage distance from
          (fx,fy) to the edge of the outermost/largest circle.
        :param color: indicates what color to use at that gradient stop
        :param opacity: defines the opacity of a given gradient stop
        """
        self.add(_GradientStop(offset, color, opacity, factory=self))
        return self

    def add_colors(self, colors, sweep=(0., 1.), opacity=None):
        """ Add stop-colors from colors with linear offset distributuion
        from sweep[0] to sweep[1].

        i.e. colors=['white', 'red', 'blue']
          'white': offset = 0.0
          'red': offset = 0.5
          'blue': offset = 1.0
        """
        start = float(sweep[0])
        end = float(sweep[1])
        delta = (end-start) / float(len(colors) - 1)
        offset = start
        for color in colors:
            self.add_stop_color(round(offset, 3), color, opacity)
            offset += delta
        return self

    def get_xml(self):
        if hasattr(self, 'href'):
            self.update_id()
        return super(_AbstractGradient, self).get_xml()


class LinearGradient(_AbstractGradient):
    """ Linear gradients are defined by a SVG <linearGradient> element.
    """
    elementname = 'linearGradient'

    def __init__(self, start=None, end=None, inherit=None, **extra):
        """
        :param 2-tuple start: start point of the gradient (**x1**, **y1**)
        :param 2-tuple end: end point of the gradient (**x2**, **y2**)
        :param inherit: gradient inherits properties from `inherit` see: **xlink:href**

        """
        super(LinearGradient, self).__init__(inherit=inherit, **extra)
        if start is not None:
            self['x1'] = start[0]
            self['y1'] = start[1]
        if end is not None:
            self['x2'] = end[0]
            self['y2'] = end[1]


class RadialGradient(_AbstractGradient):
    """ Radial gradients are defined by a SVG <radialGradient> element.
    """
    elementname = 'radialGradient'

    def __init__(self, center=None, r=None, focal=None, inherit=None, **extra):
        """
        :param 2-tuple center: center point for the gradient (**cx**, **cy**)
        :param r: radius for the gradient
        :param 2-tuple focal: focal point for the radial gradient (**fx**, **fy**)
        :param inherit: gradient inherits properties from `inherit` see: **xlink:href**

        """

        super(RadialGradient, self).__init__(inherit=inherit, **extra)
        if center is not None:
            self['cx'] = center[0]
            self['cy'] = center[1]
        if r is not None:
            self['r'] = r
        if focal is not None:
            self['fx'] = focal[0]
            self['fy'] = focal[1]

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
18 Apr 2024 12.35 AM
root / 996
0755
__pycache__
--
31 Aug 2024 6.48 AM
root / 996
0755
data
--
31 Aug 2024 6.48 AM
root / 996
0755
extensions
--
31 Aug 2024 6.48 AM
root / 996
0755
__init__.py
2.335 KB
14 Nov 2023 9.35 PM
root / 996
0644
animate.py
6.307 KB
14 Nov 2023 9.35 PM
root / 996
0644
base.py
8.006 KB
14 Nov 2023 9.35 PM
root / 996
0644
container.py
10.15 KB
14 Nov 2023 9.35 PM
root / 996
0644
drawing.py
5.054 KB
14 Nov 2023 9.35 PM
root / 996
0644
elementfactory.py
2.147 KB
14 Nov 2023 9.35 PM
root / 996
0644
etree.py
1.257 KB
14 Nov 2023 9.35 PM
root / 996
0644
filters.py
7.526 KB
14 Nov 2023 9.35 PM
root / 996
0644
gradients.py
4.498 KB
14 Nov 2023 9.35 PM
root / 996
0644
image.py
2.353 KB
14 Nov 2023 9.35 PM
root / 996
0644
masking.py
1.742 KB
14 Nov 2023 9.35 PM
root / 996
0644
mixins.py
10.185 KB
14 Nov 2023 9.35 PM
root / 996
0644
params.py
1.768 KB
14 Nov 2023 9.35 PM
root / 996
0644
path.py
2.751 KB
14 Nov 2023 9.35 PM
root / 996
0644
pattern.py
1.904 KB
14 Nov 2023 9.35 PM
root / 996
0644
shapes.py
5.614 KB
14 Nov 2023 9.35 PM
root / 996
0644
solidcolor.py
1.632 KB
14 Nov 2023 9.35 PM
root / 996
0644
text.py
7.738 KB
14 Nov 2023 9.35 PM
root / 996
0644
utils.py
7.579 KB
14 Nov 2023 9.35 PM
root / 996
0644
validator2.py
5.872 KB
14 Nov 2023 9.35 PM
root / 996
0644
version.py
1.063 KB
14 Nov 2023 9.35 PM
root / 996
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF