Ejemplo n.º 1
0
    def __init__(self, style=None, x=0, y=0, r1=80, r2=None):
        if r2 == None:
            r2 = r1
        super(Ellipse, self).__init__(style, Point(x, y))

        pathitems = []
        p1 = Point(x - r1, y)
        p2 = Point(x, y - r2)
        p3 = Point(x + r1, y)
        p4 = Point(x, y + r2)
        self.path = metapost.path.path(
            [
                smoothknot(*p1.toTuple()),
                tensioncurve(),
                smoothknot(*p2.toTuple()),
                tensioncurve(),
                smoothknot(*p3.toTuple()),
                tensioncurve(),
                smoothknot(*p4.toTuple()),
                tensioncurve(),
            ]
        )

        self.addJointPoint(Point(x - r1, y))
        self.addJointPoint(Point(x, y - r2))
        self.addJointPoint(Point(x + r1, y))
        self.addJointPoint(Point(x, y + r2))
Ejemplo n.º 2
0
def drawSin(y):
    x = -0.3

    pg1, pg2, pg3 = (0 + 8 * x*scale, sin(0 + x*scale)*0.3+y), (1 + 8 * x*scale, sin(1 + x*scale)*0.3+y), (2 + 8 * x*scale, sin(2 + x*scale)*0.3+y)
    pg4, pg5, pg6 = (3 + 8 * x+(scale), sin(3 + x+(scale))*0.3+y), (4 + 8 * x+(scale), sin(4 + x+(scale))*0.3+y), (5 + 8 * x+(scale), sin(5 + x+(scale))*0.3+y)
    path = metapost.path.path([
        beginknot(*pg1), tensioncurve(), smoothknot(*pg2), tensioncurve(),
        smoothknot(*pg3), tensioncurve(), smoothknot(*pg4), tensioncurve(),
        smoothknot(*pg5), tensioncurve(), endknot(*pg6)])
    return path
Ejemplo n.º 3
0
    def draw(self, canvas):
        edgepath = pyx.metapost.path.path([
            beginknot(*self.start_point), tensioncurve(),
            smoothknot(*self.mid_point), tensioncurve(),
            endknot(*self.end_point)
        ])

        canvas.stroke(edgepath,
                      [pyx.style.linewidth(self.thickness), pyx.color.rgb(*self.colour), pyx.color.transparency(
                          1-self.alpha)])
Ejemplo n.º 4
0
    def path_SER(cls,
                 ha=-30,
                 tn=1.5,
                 ta=-140,
                 d=-60,
                 dz=P(0, 0),
                 before=None,
                 after=None):
        if before:
            if before.tail_type == 'NER':
                ha = 0
                tn = 1.5
                d = -60

        if after:
            if after.head_type in {'SWR', 'S', 'SR', 'SE'}:
                ta = 160
            elif after.head_type == 'SW':
                ta = after.head_angle
            elif after.head_type in {'NER'}:
                ta = -120
            elif after.head_type in {'SEL', 'N'}:
                ta = -90
            elif before and before.tail_type == 'NER':
                ta = -90

        return path([
            beginknot(0, 0, angle=ha),
            tensioncurve(tn),
            endknot(*(PP(16, d) + dz), angle=ta)
        ])
Ejemplo n.º 5
0
    def path_template(cls, ha=34, tn=1.6, ta=90, d=45, dz=P(0, 0)):
        z0 = P(0, 0)
        z1 = PP(16, d) + dz

        return pyx.metapost.path.path([
            beginknot(*z0, angle=ha),
            tensioncurve(tn),
            endknot(*z1, angle=ta)])
Ejemplo n.º 6
0
    def path_template_reversed(cls, ha=-90, tn=1.6, ta=180, d=-120, dz = P(0, 0)):
        z0 = P(0, 0)
        z1 = PP(16, d) + dz

        return pyx.metapost.path.path([
            beginknot(*z0, angle=ha),
            tensioncurve(tn),
            endknot(*z1, angle=ta)])
Ejemplo n.º 7
0
	def __init__(self, style=None, pos=None):
		if pos==None :
			pos = self.getDefaultPoints();
		super(TensionCurve, self).__init__(style, Point.center(*pos));

		pathitems = []
		i = 0
		for p in pos:
			if i == 0:
				pathitems.append(beginknot(*pos[0].toTuple()))
			elif i == len(pos) - 1:
				pathitems.append(tensioncurve())
				pathitems.append(endknot(*pos[i].toTuple()))
			else:
				pathitems.append(tensioncurve())
				pathitems.append(smoothknot(*pos[i].toTuple()))
			i += 1
		self.path = metapost.path.path(pathitems)
Ejemplo n.º 8
0
    def path_NER(cls, ha=70, tn=1.1, ta=0, d=40, dz=P(0, 0),
                 before=None, after=None):
        if before:
            if before.tail_type == 'SWR':
                ha = 55
                d = 40
            elif before.tail_type in {'NW|SWCR1', 'NEROR4'}:
                ha = 40
                d = 30
            elif before.tail_type == 'SW':
                ha = before.tail_angle + 170
                d = 36
            elif before.tail_type == 'SR':
                ha = 50
                d = 30
                dz = P(1, 0)
            elif before.tail_type in {
                'SRCR1', 'SWLCL1', 'SWLCL4', 'SWLCL8', 'SWCR1', 'SWCL1',
                'SERCR1', 'CNL', 'CNR', 'SWRCL1'}:
                ha = 45
                d = 30
                dz = P(1, 0)
            elif before.tail_type in {'SWRCR1'}:
                ha = 35
                d = 25
                dz = P(1, 0)
            else:
                ha = 70
                d = 40

        if after:
            if after.head_type in {'E', 'ER', 'NE', 'NER', 'SE', 'BE', 'BER'}:
                tn = 1.1
                ta = -70
                d = 35
            elif after.head_type in {'S', 'SR'}:
            #elif after.head_type in {'S', 'SW', 'SR'}:
            #elif after.head_type in {'S', 'SW', 'SWR', 'SR'}:
                ta = after.head_angle
            elif after.head_type == 'SER':
                ha = 90
                d = 60
                tn = 1.5
                ta = 0
            #elif after.head_type in {'SWR', 'NEL|SWR'}:
            elif after.head_type in {'NEL|SWR', 'SWR', 'SWR|NEL'}:
                tn = 1.5
                ta = -40
            else:
                tn = 1.1
                ta = 0

        return mpath([
            beginknot(0, 0, angle=ha),
            tensioncurve(tn), 
            endknot(*(PP(8, d) + dz), angle=ta)])
Ejemplo n.º 9
0
    def path_NER(cls,
                 ha=70,
                 tn=1.7,
                 ta=0,
                 d=45,
                 dz=P(0, 0),
                 before=None,
                 after=None):
        if before:
            if before.tail_type == 'SWR':
                ha = 50
                d = 35
            #elif before.tail_type == 'NW|SWCR1':
            #    ha = 40
            #    d = 30
            #elif before.tail_type == 'SW':
            #    ha = before_tail_angle + 170
            #    d = 30
            elif before.tail_type in {'SR'}:
                ha = 50
                d = 30
                dz = P(1, 0)
            #else:
            #    ha = 70
            #    d = 40

        if after:
            if after.head_type in {'E', 'ER', 'NE', 'NER'}:
                ta = -80
                d = 35
            elif after.head_type in {'S', 'SW', 'SWR', 'SR', 'NEL'}:
                ta = after.head_angle
            elif after.head_type in {'SER'}:
                ha = 90
                ta = 0
                tn = 1.5
                d = 60
            elif after.head_type in {'NEL|SWR'}:
                tn = 1.5
                td = -40
            #else:
            #    tn = 1.1
            #    td = 0

        return path([
            beginknot(0, 0, angle=ha),
            tensioncurve(tn),
            endknot(*(PP(16, d) + dz), angle=ta)
        ])
Ejemplo n.º 10
0
    def bend(cls, paths, a1=10, a2=None, tn=1.0):
        assert isinstance(paths, list) and len(
            paths) > 0, 'Char.bend() takes a list of paths as an argument'
        assert tn >= 0.75, 'Tension value must be greater than or equal to 0.75'

        a2 = a2 if a2 is not None else a1

        rad0 = atan2(*[
            coord / unit.length(1) for coord in pyx.trafo.rotate(a1).apply(
                *paths[0].tangent(0).atend())
        ][::-1])
        z0 = paths[0].at(0)
        rad1 = atan2(*[
            coord / unit.length(1) for coord in pyx.trafo.rotate(-a2).apply(
                *paths[0].tangent(paths[0].end()).atend())
        ][::-1])
        z1 = paths[0].atend()

        return pyx.metapost.path.path([
            beginknot(*z0, angle=degrees(rad0)),
            tensioncurve(tn),
            endknot(*z1, angle=degrees(rad1))
        ])
Ejemplo n.º 11
0
    def path_ELCLne(cls, ta=None, **kwargs):
        #M 47.3414,175.52 C 53.5452,177.417 69.940893,180.963 69.9339,175.52 69.932221,174.21314 64.826189,177.78865 63.927416,178.41801

        #z0 = P(0, -0)
        #c0 = P(2.18039, -0.666719)
        #c1 = P(7.94282, -1.913)
        #z1 = P(7.94036, -0)
        #c2 = P(7.93977, 0.459309)
        #c3 = P(6.1452, -0.797339)
        z2 = P(5.82932, -1.01853)

        #z0 = P(0, -0)
        #c0 = z0 + P(2.18039, -0.666719)
        #z1 = z0 + P(7.94036, 0)
        #c1 = z1 + P(0.00245776, -1.913)
        #c2 = z1 + P(-0.000590101, 0.459309)
        #z2 = z1 + P(-2.11104, -1.01853)
        #c3 = z2 + P(0.315883, 0.221195)

        z0 = P(0, -0)
        c0 = z0 + PP(2.28004, -17)
        z1 = z0 + PP(7.94036, 0)
        #z1 = z2 - PP(2.34391, ta + -9)
        c1 = z1 + PP(1.913, -89)
        #c2 = z1 + PP(0.459309, 90)
        #z2 = z1 + PP(2.34391, -154)
        #c3 = z2 + PP(0.385628, 35)

        return pyx.metapost.path.path([
            beginknot(*z0),
            controlcurve(c0, c1),
            knot(*z1),
            #controlcurve(c2, c3),
            tensioncurve(1.5),
            endknot(*z2, angle=ta + 180)
        ])
Ejemplo n.º 12
0
    def path_UWL_up(cls, ta=24, da=0, **kwargs):
        #M47.3414 58.6772C44.5656 59.7427 42.1255 61.8061 42.1255 64.6774C42.1255 67.5206 45.5236 69.1216 48.5106 67.7917

        #z0 = P(0, -0)
        #c0 = P(-0.975582, -0.37448)
        #c1 = P(-1.83318, -1.09968)
        #z1 = P(-1.83318, -2.10883)
        #c2 = P(-1.83318, -3.1081)
        #c3 = P(-0.638884, -3.67079)
        #z2 = P(0.410927, -3.20338)

        #z0 = P(0, -0)
        #c0 = z0 + P(-0.975582, -0.37448)
        #z1 = z0 + P(-1.83318, -2.10883)
        #c1 = z1 + P(0, 1.00915)
        #c2 = z1 + P(0, -0.999271)
        #z2 = z1 + P(2.24411, -1.09455)
        #c3 = z2 + P(-1.04981, -0.467406)

        z0 = P(0, -0)
        c0 = z0 + PP(1.04499, -159)
        z1 = z0 + PP(2.79423, -131)
        #z1 = z2 - PP(2.49681, ta + 309)
        c1 = z1 + PP(1.00915, 90)
        #c2 = z1 + PP(0.999271, -90)
        z2 = z1 + PP(2.49681, -26) + P(0.5, 0)
        #c3 = z2 + PP(1.14916, -155)

        return pyx.metapost.path.path([
            beginknot(*z0),
            controlcurve(c0, c1),
            knot(*z1),
            #controlcurve(c2, c3),
            tensioncurve(1.2),
            endknot(*z2, angle=ta + 90 + da)
        ])
Ejemplo n.º 13
0
from pyx import *
from pyx.metapost.path import beginknot, endknot, smoothknot, tensioncurve

p1, p2, p3, p4, p5 = (0, 0), (2, 1.33), (1.3, 3), (0.33, 2.33), (1, 1.67)
openpath = metapost.path.path([
    beginknot(*p1),
    tensioncurve(),
    smoothknot(*p2),
    tensioncurve(),
    smoothknot(*p3),
    tensioncurve(),
    smoothknot(*p4),
    tensioncurve(),
    endknot(*p5)
])
closedpath = metapost.path.path([
    smoothknot(*p1),
    tensioncurve(),
    smoothknot(*p2),
    tensioncurve(),
    smoothknot(*p3),
    tensioncurve(),
    smoothknot(*p4),
    tensioncurve(),
    smoothknot(*p5),
    tensioncurve()
])
c = canvas.canvas()
for p in [p1, p2, p3, p4, p5]:
    c.fill(path.circle(p[0], p[1], 0.05), [color.rgb.red])
    c.fill(path.circle(p[0], p[1], 0.05),
Ejemplo n.º 14
0
 def path_template(cls, ta=80, tn=1.7):
     return path([
         beginknot(0, 0, angle=-18),
         tensioncurve(tn),
         endknot(8, 0, angle=ta)
     ])
Ejemplo n.º 15
0
 def path_SEL(cls, ha=-90, tn=0.8, ta=0, d=-55, sellen=7.3, dz=P(0, 0)):
     return mpath([
         beginknot(0, 0, angle=ha),
         tensioncurve(tn),
         endknot(*(PP(sellen, d) + dz), angle=ta)
     ])
Ejemplo n.º 16
0
 def path_SELnel(cls, ha=-90, tn=1.5, ta=0):
     return mpath([
         beginknot(0, 0, angle=ha),
         tensioncurve(tn),
         endknot(*P(4.5, -math.sqrt(7.6**2 - 4.5**2)), angle=ta)
     ])
Ejemplo n.º 17
0
 def path_ER_cr1(cls, ta=-90):
     return mpath([
         beginknot(0, 0, angle=28),
         tensioncurve(1.75, 1.1),
         endknot(*PP(4, 4), angle=ta)
     ])
Ejemplo n.º 18
0
 def path_ER(cls, ta=-90):
     return mpath([
         beginknot(0, 0, angle=30),
         tensioncurve(1.2),
         endknot(4, 0, angle=ta)
     ])
Ejemplo n.º 19
0
 def path_template(cls, ta=-90, tn=1.5):
     return mpath([
         beginknot(0, 0, angle=23),
         tensioncurve(tn),
         endknot(8, 0, angle=ta)
     ])
Ejemplo n.º 20
0
                  path.lineto(62,108),path.lineto(62,0),
                 path.closepath())

pret2 = path.path(path.moveto(186,0),path.lineto(186,108),
                  path.lineto(214,108),path.lineto(214,0),
                  path.closepath())

kulka = path.circle(123,-240,35)

kabel = path.path(path.moveto(102,-240),path.lineto(102,-360),
                  path.lineto(144,-360),path.lineto(144,-240),
                  path.closepath())

wycinek = path.path(path.arc(123, -130, 85, 0, 270))

tylda = metapost.path.path([
    beginknot(*(90,-135)), tensioncurve(), smoothknot(*(125,-115)), tensioncurve(),
   smoothknot(*(160,-140)), tensioncurve(), endknot(*(190,-120))])

c.stroke(pret1, black)
c.stroke(pret2, black)
c.stroke(kulka, black)
c.stroke(kabel, black)
c.stroke(body, black)

c.stroke(wycinek, wycinek_blue)

c.stroke(tylda, tylda_orange)

c.writePDFfile('wtyczka.pdf')
Ejemplo n.º 21
0
from pyx import *
from pyx.metapost.path import beginknot, endknot, smoothknot, tensioncurve

p1, p2, p3, p4, p5 = (0, 0), (2, 1.33), (1.3, 3), (0.33, 2.33), (1, 1.67)
openpath = metapost.path.path([
    beginknot(*p1), tensioncurve(), smoothknot(*p2), tensioncurve(),
    smoothknot(*p3), tensioncurve(), smoothknot(*p4), tensioncurve(),
    endknot(*p5)])
closedpath = metapost.path.path([
    smoothknot(*p1), tensioncurve(), smoothknot(*p2), tensioncurve(),
    smoothknot(*p3), tensioncurve(), smoothknot(*p4), tensioncurve(),
    smoothknot(*p5), tensioncurve()])
c = canvas.canvas()
for p in [p1, p2, p3, p4, p5]:
    c.fill(path.circle(p[0], p[1], 0.05), [color.rgb.red])
    c.fill(path.circle(p[0], p[1], 0.05), [color.rgb.red, trafo.translate(2, 0)])
c.stroke(openpath)
c.stroke(closedpath, [trafo.translate(2, 0)])

c.writeEPSfile("metapost")
c.writePDFfile("metapost")
c.writeSVGfile("metapost")
Ejemplo n.º 22
0
from pyx import *
from pyx.metapost.path import beginknot, endknot, smoothknot, tensioncurve
c = canvas.canvas()
tylda1 = metapost.path.path([
    beginknot(*(90, -120)),
    tensioncurve(),
    smoothknot(*(125, -115)),
    tensioncurve(),
    smoothknot(*(160, -130)),
    tensioncurve(),
    smoothknot(*(190, -115)),
    tensioncurve(1.5),
    endknot(*(90, -120))
])
tylda2 = metapost.path.path([
    beginknot(*(90, -120)),
    tensioncurve(),
    smoothknot(*(125, -115)),
    tensioncurve(),
    smoothknot(*(160, -130)),
    tensioncurve(),
    smoothknot(*(190, -115)),
    tensioncurve(1.5),
    endknot(*(90, -120))
])
c.fill(tylda1, [
    style.linewidth(0.1), color.cmyk.Orange,
    trafo.scale(sx=0.1, sy=0.1), color.rgb.blue,
    trafo.mirror(180),
    trafo.mirror(90)
])
Ejemplo n.º 23
0
 def path_ER_cr1(cls, ha=23, ta=-90):
     return mpath([
         beginknot(0, 0, angle=ta),
         tensioncurve(2.05),
         endknot(*PP(16, 4), angle=ta)
     ])
Ejemplo n.º 24
0
 def path_ER(cls, ha=20, ta=-80, tn=1.6):
     return pyx.metapost.path.path([
         beginknot(0, 0, angle=ha),
         tensioncurve(tn),
         endknot(16, 0, angle=ta)
     ])
Ejemplo n.º 25
0
 def path_SELnel(cls, ha=-90, tn=1.5, ta=0):
     return path([
         beginknot(0, 0, angle=ha),
         tensioncurve(tn),
         endknot(*PP(16, -60), angle=ta)
     ])
Ejemplo n.º 26
0
 def path_template(cls, ta=90, tn=2.5):
     return path([
         beginknot(0, 0, angle=-13),
         tensioncurve(tn),
         endknot(16, 0, angle=ta)
     ])
Ejemplo n.º 27
0
from pyx.metapost.path import beginknot,roughknot,endknot,smoothknot,tensioncurve

styll = [style.linewidth(0.4), style.linecap.round, color.cmyk.Green]
drawpath = path.line(-1,-1.3, 7,-1.3)
drawpath2 = path.line(-1,-1.9, 6,-1.9)
drawpath3 = path.line(-1,-2.3, 6,-2.3)
drawpath4 = path.line(-1,-2.8, 6,-2.8)
drawpath5 = path.line(0,-3.5, 6,-3.5)
drawpath6 = path.line(0,-4.1, 6,-4.1)
purple = "#9370D8"
c=canvas.canvas()
p1,p2,p3,p4,p5,p6,p7,p8,p9,p10 = (1,-1),(2,-1.2),(3.5,-1),(4,-1.5),(3.2,-2),(4,-3.5),(3,-4.1),(2,-4),(1,-4),(0,-3)
o1,o2,o3,o4= (3,0),(2.66,-0.66),(2,-1),(2.33,-0.4),
ogon = metapost.path.path([
    beginknot(*o1),tensioncurve(),smoothknot(*o2),tensioncurve(),
    roughknot(*o3),tensioncurve(), smoothknot(*o4),tensioncurve(),
    endknot(*o1)])
apple = metapost.path.path([
    beginknot(*p6),tensioncurve(),smoothknot(*p7),tensioncurve(),smoothknot(*p8),tensioncurve(),smoothknot(*p9),tensioncurve(),
    smoothknot(*p10),tensioncurve(),smoothknot(*p1),tensioncurve(),smoothknot(*p2),tensioncurve(),smoothknot(*p3),tensioncurve(),
    roughknot(*p4),tensioncurve(), smoothknot(*p5),tensioncurve(),
    endknot(*p6)])
c1=canvas.canvas([canvas.clip(apple)])
c1.stroke(drawpath, [color.rgbfromhexstring("#60bb44"), style.linewidth(1.0)])
c1.stroke(drawpath2, [color.rgbfromhexstring("#fcb827"),style.linewidth(1.0)])
c1.stroke(drawpath3, [color.rgbfromhexstring("#f6821f"),style.linewidth(1.0)])
c1.stroke(drawpath4, [color.rgbfromhexstring("#e03a3c"),style.linewidth(1.0)])
c1.stroke(drawpath5, [color.rgbfromhexstring("#953d94"),style.linewidth(1.0)])
c1.stroke(drawpath6, [color.rgbfromhexstring("#009edd"),style.linewidth(1.0)])
 
Ejemplo n.º 28
0
    (3.5, -0.2),
    (4.8, 0.),
    (5.0, 0.2),
    (5.2, 0.),
    (3.5, -0.4),
    (2.3, 0.),
    (1.5, 0.2),
    (1.2, 0.),
    (1., -0.2),
]

items = []
for i, p in enumerate(points):
    px, py = p
    items.append(smoothknot(px*dx, py*dy))
    items.append(tensioncurve())

c.stroke(metapost.path.path(items),
    [trafo.translate(tx0, ty0), green, style.linewidth.Thick,
        style.linestyle.dashed])

y -= 6*dr
c.text(x, y,
r"""
In tree notation:
""",
[text.parbox(dw-2*m),])


y -= 2*dr
tdx = 0.8
Ejemplo n.º 29
0
 def path_EL(cls, ta=80):
     return path([
         beginknot(0, 0, angle=-28),
         tensioncurve(1.2),
         endknot(4, 0, angle=ta)
     ])