晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 sh-3ll

HOME


sh-3ll 1.0
DIR:/opt/cloudlinux/venv/lib64/python3.11/site-packages/svgwrite/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/svgwrite/gradients.py
#!/usr/bin/env python
#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
        """
        delta = (sweep[1] - sweep[0]) / (len(colors) - 1)
        offset = sweep[0]
        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]