Ejemplo n.º 1
0
    def decorate(self, dp, texrunner):
        dp.ensurenormpath()
        l = dp.path.arclen()

        colors = [self.grad.select(n, self.steps) for n in range(self.steps)]
        colors.reverse()
        params = dp.path.arclentoparam([l*i/float(self.steps) for i in range(self.steps)])
        params.reverse()

        c = canvas.canvas()
        # treat the end pieces separately
        c.stroke(dp.path.split(params[1])[1], attr.mergeattrs([colors[0]] + self.attrs))
        for n in range(1,self.steps-1):
            c.stroke(dp.path.split([params[n-1],params[n+1]])[1], attr.mergeattrs([colors[n]] + self.attrs))
        c.stroke(dp.path.split(params[-2])[0], attr.mergeattrs([colors[-1]] + self.attrs))
        dp.ornaments.insert(c)
Ejemplo n.º 2
0
    def decorate(self, dp, texrunner):
        if self.texrunner:
            texrunner = self.texrunner
        import text as textmodule
        textattrs = attr.mergeattrs([textmodule.halign.center, textmodule.vshift.mathaxis] + self.textattrs)

        dp.ensurenormpath()
        if self.arclenfrombegin is not None:
            param = dp.path.begin() + self.arclenfrombegin
        elif self.arclenfromend is not None:
            param = dp.path.end() - self.arclenfromend
        else:
            # relarcpos is used, when neither arcfrombegin nor arcfromend is given
            param = self.relarclenpos * dp.path.arclen()
        x, y = dp.path.at(param)

        if self.relangle is not None:
            a = dp.path.trafo(param).apply_pt(math.cos(self.relangle*math.pi/180), math.sin(self.relangle*math.pi/180))
            b = dp.path.trafo(param).apply_pt(0, 0)
            angle = math.atan2(a[1] - b[1], a[0] - b[0])
        else:
            angle = self.angle*math.pi/180
        t = texrunner.text(x, y, self.text, textattrs)
        t.linealign(self.textdist, math.cos(angle), math.sin(angle))
        dp.ornaments.insert(t)
Ejemplo n.º 3
0
    def decorate(self, dp, texrunner):
        if self.texrunner:
            texrunner = self.texrunner
        import text as textmodule
        textattrs = attr.mergeattrs(
            [textmodule.halign.center, textmodule.vshift.mathaxis] +
            self.textattrs)

        dp.ensurenormpath()
        if self.arclenfrombegin is not None:
            param = dp.path.begin() + self.arclenfrombegin
        elif self.arclenfromend is not None:
            param = dp.path.end() - self.arclenfromend
        else:
            # relarcpos is used, when neither arcfrombegin nor arcfromend is given
            param = self.relarclenpos * dp.path.arclen()
        x, y = dp.path.at(param)

        if self.relangle is not None:
            a = dp.path.trafo(param).apply_pt(
                math.cos(self.relangle * math.pi / 180),
                math.sin(self.relangle * math.pi / 180))
            b = dp.path.trafo(param).apply_pt(0, 0)
            angle = math.atan2(a[1] - b[1], a[0] - b[0])
        else:
            angle = self.angle * math.pi / 180
        t = texrunner.text(x, y, self.text, textattrs)
        t.linealign(self.textdist, math.cos(angle), math.sin(angle))
        dp.ornaments.insert(t)
Ejemplo n.º 4
0
    def draw(self, path, attrs):
        """draw path on canvas using the style given by args

        The argument attrs consists of PathStyles, which modify
        the appearance of the path, PathDecos, which add some new
        visual elements to the path, or trafos, which are applied
        before drawing the path.

        """

        attrs = attr.mergeattrs(attrs)
        attr.checkattrs(attrs, [
            deco.deco, deformer.deformer, style.fillstyle, style.strokestyle,
            style.fillrule
        ])

        for adeformer in attr.getattrs(attrs, [deformer.deformer]):
            path = adeformer.deform(path)

        styles = attr.getattrs(attrs, [style.fillstyle, style.strokestyle])
        fillrule, = attr.getattrs(
            attrs, [style.fillrule]) or [style.fillrule.nonzero_winding]
        dp = deco.decoratedpath(path, styles=styles, fillrule=fillrule)

        # add path decorations and modify path accordingly
        for adeco in attr.getattrs(attrs, [deco.deco]):
            adeco.decorate(dp, self.texrunner)

        self.insert(dp)
Ejemplo n.º 5
0
 def __init__(self, dist, angle, strokestyles=[]):
     pattern.__init__(self, painttype=1, tilingtype=1, xstep=dist, ystep=100*unit.t_pt, bbox=None, trafo=trafo.rotate(angle))
     self.strokestyles = attr.mergeattrs([style.linewidth.THIN] + strokestyles)
     attr.checkattrs(self.strokestyles, [style.strokestyle])
     self.dist = dist
     self.angle = angle
     self.stroke(path.line_pt(0, -50, 0, 50), self.strokestyles)
Ejemplo n.º 6
0
    def draw(self, path, attrs):
        """draw path on canvas using the style given by args

        The argument attrs consists of PathStyles, which modify
        the appearance of the path, PathDecos, which add some new
        visual elements to the path, or trafos, which are applied
        before drawing the path.

        """

        attrs = attr.mergeattrs(attrs)
        attr.checkattrs(attrs, [deco.deco, deformer.deformer, style.fillstyle, style.strokestyle, style.fillrule])

        for adeformer in attr.getattrs(attrs, [deformer.deformer]):
            path = adeformer.deform(path)

        styles = attr.getattrs(attrs, [style.fillstyle, style.strokestyle])
        fillrule, = attr.getattrs(attrs, [style.fillrule]) or [style.fillrule.nonzero_winding]
        dp = deco.decoratedpath(path, styles=styles, fillrule=fillrule)

        # add path decorations and modify path accordingly
        for adeco in attr.getattrs(attrs, [deco.deco]):
            adeco.decorate(dp, self.texrunner)

        self.insert(dp)
Ejemplo n.º 7
0
 def __init__(self, dist, angle, strokestyles=[], cross=0):
     attr.clearclass.__init__(self, _filled)
     attr.exclusiveattr.__init__(self, linehatched)
     self.dist = dist
     self.angle = angle
     self.strokestyles = attr.mergeattrs([style.linewidth.THIN] + strokestyles)
     attr.checkattrs(self.strokestyles, [style.strokestyle])
     self.cross = cross
Ejemplo n.º 8
0
 def __init__(self, attrs=[], pos=1, reversed=0, size=_base, angle=45, constriction=0.8):
     self.attrs = attr.mergeattrs([style.linestyle.solid, filled] + attrs)
     attr.checkattrs(self.attrs, [deco, style.fillstyle, style.strokestyle])
     self.pos = pos
     self.reversed = reversed
     self.size = size
     self.angle = angle
     self.constriction = constriction
Ejemplo n.º 9
0
 def __init__(self, dist, angle, strokestyles=[], cross=0):
     attr.clearclass.__init__(self, _filled)
     attr.exclusiveattr.__init__(self, linehatched)
     self.dist = dist
     self.angle = angle
     self.strokestyles = attr.mergeattrs([style.linewidth.THIN] +
                                         strokestyles)
     attr.checkattrs(self.strokestyles, [style.strokestyle])
     self.cross = cross
Ejemplo n.º 10
0
    def decorate(self, dp, texrunner):
        dp.ensurenormpath()
        l = dp.path.arclen()

        colors = [self.grad.select(n, self.steps) for n in range(self.steps)]
        colors.reverse()
        params = dp.path.arclentoparam(
            [l * i / float(self.steps) for i in range(self.steps)])
        params.reverse()

        c = canvas.canvas()
        # treat the end pieces separately
        c.stroke(
            dp.path.split(params[1])[1],
            attr.mergeattrs([colors[0]] + self.attrs))
        for n in range(1, self.steps - 1):
            c.stroke(
                dp.path.split([params[n - 1], params[n + 1]])[1],
                attr.mergeattrs([colors[n]] + self.attrs))
        c.stroke(
            dp.path.split(params[-2])[0],
            attr.mergeattrs([colors[-1]] + self.attrs))
        dp.ornaments.insert(c)
Ejemplo n.º 11
0
 def __init__(self,
              attrs=[],
              pos=1,
              reversed=0,
              size=_base,
              angle=45,
              constriction=0.8):
     self.attrs = attr.mergeattrs([style.linestyle.solid, filled] + attrs)
     attr.checkattrs(self.attrs, [deco, style.fillstyle, style.strokestyle])
     self.pos = pos
     self.reversed = reversed
     self.size = size
     self.angle = angle
     self.constriction = constriction
Ejemplo n.º 12
0
    def decorate(self, dp, texrunner):
        if self.texrunner:
            texrunner = self.texrunner
        import text as textmodule
        textattrs = attr.mergeattrs([textmodule.halign.center, textmodule.vshift.mathaxis] + self.textattrs)

        dp.ensurenormpath()
        if self.arclenfrombegin is not None:
            x, y = dp.path.at(dp.path.begin() + self.arclenfrombegin)
        elif self.arclenfromend is not None:
            x, y = dp.path.at(dp.path.end() - self.arclenfromend)
        else:
            # relarcpos is used, when neither arcfrombegin nor arcfromend is given
            x, y = dp.path.at(self.relarclenpos * dp.path.arclen())

        t = texrunner.text(x, y, self.text, textattrs)
        t.linealign(self.textdist, math.cos(self.angle*math.pi/180), math.sin(self.angle*math.pi/180))
        dp.ornaments.insert(t)
Ejemplo n.º 13
0
    def __init__(self, attrs=[], pos=1, reversed=0, size=_base, angle=45, constriction=0.8):
        self.attrs = attr.mergeattrs([style.linestyle.solid, filled] + attrs)
        attr.checkattrs(self.attrs, [deco, style.fillstyle, style.strokestyle])
        self.pos = pos
        self.reversed = reversed
        self.size = size
        self.angle = angle
        self.constriction = constriction

        # calculate absolute arc length of constricition
        # Note that we have to correct this length because the arrowtemplates are rotated
        # by self.angle/2 to the left and right. Hence, if we want no constriction, i.e., for
        # self.constriction = 1, we actually have a length which is approximately shorter
        # by the given geometrical factor.
        if self.constriction is not None:
            self.constrictionlen = self.size * self.constriction * math.cos(math.radians(self.angle/2.0))
        else:
            # if we do not want a constriction, i.e. constriction is None, we still
            # need constrictionlen for cutting the path
            self.constrictionlen = self.size * 1 * math.cos(math.radians(self.angle/2.0))
Ejemplo n.º 14
0
    def decorate(self, dp, texrunner):
        if self.texrunner:
            texrunner = self.texrunner
        import text as textmodule
        textattrs = attr.mergeattrs(
            [textmodule.halign.center, textmodule.vshift.mathaxis] +
            self.textattrs)

        dp.ensurenormpath()
        if self.arclenfrombegin is not None:
            x, y = dp.path.at(dp.path.begin() + self.arclenfrombegin)
        elif self.arclenfromend is not None:
            x, y = dp.path.at(dp.path.end() - self.arclenfromend)
        else:
            # relarcpos is used, when neither arcfrombegin nor arcfromend is given
            x, y = dp.path.at(self.relarclenpos * dp.path.arclen())

        t = texrunner.text(x, y, self.text, textattrs)
        t.linealign(self.textdist, math.cos(self.angle * math.pi / 180),
                    math.sin(self.angle * math.pi / 180))
        dp.ornaments.insert(t)
Ejemplo n.º 15
0
 def __init__(self, styles=[]):
     attr.exclusiveattr.__init__(self, _filled)
     self.styles = attr.mergeattrs(styles)
     attr.checkattrs(self.styles, [style.fillstyle])
Ejemplo n.º 16
0
 def __init__(self, styles=[]):
     attr.exclusiveattr.__init__(self, _filled)
     self.styles = attr.mergeattrs(styles)
     attr.checkattrs(self.styles, [style.fillstyle])