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))
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
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)])
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)
(2.6, 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
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),
from pyx.metapost.path import beginknot, roughknot, endknot, smoothknot, tensioncurve styll = [style.linewidth(0.4), style.linecap.round, color.cmyk.Green] drawpath = path.line(0, -2, 6, -2) drawpath2 = path.line(0, -1, 6, -1) drawpath3 = path.line(0, -3, 6, -3) drawpath4 = path.line(0, -4, 6, -4) c = canvas.canvas() p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 = (1, -1), (2, -1.5), (3, -1), ( 4, -1.7), (3.2, -2.6), (4, -3.5), (3, -4.5), (2, -4), (1, -4.5), (0, -3) o1, o2, o3, o4 = (3, 0), (2.66, -0.66), (2, -1), (2.33, -0.33) tail = 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),
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)])
from pyx import * from pyx.metapost.path import beginknot, roughknot, endknot, smoothknot, tensioncurve c = canvas.canvas() p = [(1, -1), (2, -1.5), (3, -1), (4, -1.8), (3.1, -2.5), (4, -3.5), (3, -4.5), (2, -4), (1, -4.5), (0, -3)] apple = metapost.path.path([ beginknot(*p[5]), tensioncurve(), smoothknot(*p[6]), tensioncurve(), smoothknot(*p[7]), tensioncurve(), smoothknot(*p[8]), tensioncurve(), smoothknot(*p[9]), tensioncurve(), smoothknot(*p[0]), tensioncurve(), smoothknot(*p[1]), tensioncurve(), smoothknot(*p[2]), tensioncurve(), smoothknot(*p[3]), tensioncurve(), smoothknot(*p[4]), tensioncurve(), endknot(*p[5]) ]) o = [(3, 0), (2.66, -0.66), (2, -1), (2.33, -0.33)]
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) ])
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')
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")
path.closepath()) lewy_czerwony = path.path(path.moveto(102, -8), path.lineto(8, -8), path.lineto(8, -192), path.lineto(102, -192), path.closepath()) prawy_niebieski = path.path(path.moveto(180, -8), path.lineto(275, -8), path.lineto(275, -192), path.lineto(180, -192), path.closepath()) pusty_srodek = path.circle(141, -100, 98) lezka_gora = metapost.path.path([ beginknot(64, -56), tensioncurve(), smoothknot(100, -21), tensioncurve(), smoothknot(141, -10), tensioncurve(), smoothknot(185, -21), tensioncurve(), endknot(225, -70), beginknot(225, -70), tensioncurve(), smoothknot(180, -56), tensioncurve(), smoothknot(142, -60), tensioncurve(), smoothknot(100, -66), tensioncurve(), endknot(64, -56)