Ejemplo n.º 1
0
def read(size, color):
    size = size * 0.25
    cread = canvas.canvas()
    cread.fill(path.circle(0, 0, 0.35), [color, trafo.scale(size)])
    p = path.path(path.moveto(0.8, 0),
                  path.curveto(0.2, 0.5, -0.2, 0.5, -0.8, 0),
                  path.curveto(-0.2, -0.5, 0.2, -0.5, 0.8, 0),
                  path.closepath())
    cread.stroke(p, [color, style.linewidth.thick, trafo.scale(size)])
    return cread
Ejemplo n.º 2
0
class Promoter(Brick):
    _default_color = cmyk.ForestGreen
    _offset = (0, -0.5)
    _path = path(moveto(0, 0), lineto(1, 0), lineto(1, 0.75), lineto(3, 0.75),
                 lineto(3, 0.25), lineto(3 + sqrt(3) * 0.75, 1.125),
                 lineto(3, 2.0), lineto(3, 1.5), lineto(1, 1.5),
                 curveto(0.5, 1.5, 0.125, 1.5, 0, 1), lineto(0, 0),
                 closepath())
Ejemplo n.º 3
0
def client(clientcolor=color.rgb(0.8, 0.5, 0.5)):
    c = canvas.canvas()
    r = 0.3
    c.fill(path.circle(0, 0, r), [clientcolor])
    r = 0.5
    p = path.path(path.moveto(-r, 0), path.curveto(-r, r, r, r, r, 0),
                  path.closepath())
    c.fill(p, [clientcolor, trafo.translate(0, -1.3 * r)])
    return c
Ejemplo n.º 4
0
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])

c1 = canvas.canvas([canvas.clip(p)])
c1.fill(p, [color.grey(0.9)])

r = 1
brown1 = color.rgb(148 / 255, 77 / 255, 48 / 255)
brown2 = color.rgb(193 / 255, 91 / 255, 49 / 255)
red1 = color.rgb(200 / 255, 0, 0)
red2 = color.rgb(220 / 255, 0.5, 0.5)
flame = color.rgb(248 / 255, 212 / 255, 27 / 255)
c2 = canvas.canvas()
c2.insert(ellipse(r, 0.5, brown1))
c2.fill(path.rect(-r, 0, 2 * r, 0.5 * r), [brown1])
c2.insert(ellipse(r, 0.5, brown2), [trafo.translate(0, 0.5 * r)])
c2.insert(ellipse(0.2 * r, 0.5, red1), [trafo.translate(0, 0.5 * r)])
c2.fill(path.rect(-0.2 * r, 0.5 * r, 0.4 * r, r), [red1])
c2.insert(ellipse(0.2 * r, 0.5, red2), [trafo.translate(0, 1.5 * r)])
c2.stroke(path.line(0, 1.5 * r, 0, 1.5 * r + 0.2), [style.linewidth.Thick])
c2a = canvas.canvas()
c2a.fill(
    path.path(path.moveto(0, 0), path.curveto(-0.1, -0.2, -0.3, -0.6, 0, -0.6),
              path.curveto(0.3, -0.6, 0, -0.3, 0, 0), path.closepath()),
    [flame])
c2.insert(c2a, [trafo.translate(0, 1.65 * r + 0.6)])

c.insert(c1)
c.insert(c2, [trafo.translate(1.75, 1.3)])
c.insert(c2, [trafo.translate(4.7, 1.3)])
c.writeGSfile(device="png16m", resolution=300)
Ejemplo n.º 5
0
qi = 1.2
qf = 3.2
t = 3.5

text.set(engine=text.LatexEngine)
text.preamble(r'''\usepackage[sfdefault,scaled=.85]{FiraSans}
                  \usepackage{newtxsf}''')
unit.set(vscale=1.2, wscale=1.3, xscale=1.3)
c = canvas.canvas()
c.fill(path.rect(0, 0, -0.3, height-0.3), [color.grey(0.5)])
c.stroke(path.line(-0.5*width, 0, 0.5*width, 0), [deco.earrow])
c.text(0.5*width+0.1, 0, '$q$', [text.valign.middle])
c.stroke(path.line(0, 0, 0, height), [deco.earrow])
c.text(0.2, height, '$t$', [text.valign.top])
c.stroke(path.path(path.moveto(qi, 0),
                   path.curveto(qi, 0.5, qi+0.2, 1.3, qi+0.8, 1.6),
                   path.curveto(qi+1.4, 1.9, qf+0.7, 3, qf, t)),
         [style.linewidth.thick, linecolor1])
c.stroke(path.path(path.moveto(qi, 0),
                   path.curveto(0.5*qi, 0.5, -2.5, 1.3, 0, 1.6)),
         [style.linewidth.thick, linecolor2])
p = path.path(path.moveto(0, 1.6),
              path.curveto(2.5, 1.9, 3, 3, qf, t))
c.stroke(p, [style.linewidth.thick, linecolor2])
c.stroke(p, [style.linewidth.thick, style.linestyle.dashed,
             linecolor2, trafo.mirror(90)])
ypos = 0
for q, label in ((qi, r'$q_\text{i}$'),
                 (qf, r'$q_\text{f}$'),
                 (-qf, r'$-q_\text{f}$')):
    c.stroke(path.line(q, 0.1, q, -0.1))
Ejemplo n.º 6
0
height = 4
linecolor1 = color.rgb(0.2, 0.5, 0)
linecolor2 = color.rgb(0.2, 0, 0.8)

text.set(engine=text.LatexEngine)
text.preamble(r'''\usepackage[sfdefault,scaled=.85]{FiraSans}
                  \usepackage{newtxsf}''')
unit.set(vscale=1.2, wscale=1.3, xscale=1.3)
c = canvas.canvas()
c.stroke(path.line(0, 0, width, 0), [deco.earrow])
c.text(width+0.1, 0, '$t$', [text.valign.middle])
c.stroke(path.line(0, -0.45*height, 0, 0.55*height), [deco.earrow])
c.text(0.2, 0.55*height, '$q$', [text.valign.top])
c.stroke(path.path(path.moveto(0, 0),
                   path.curveto(0.1*width, 0.2*height,
                                0.3*width, -0.4*height,
                                0.4*width, -0.4*height),
                   path.curveto(0.5*width, -0.4*height,
                                0.7*width, 0.7*height,
                                0.9*width, 0.3*height)),
         [linecolor1, style.linewidth.thick, style.linestyle.dashed])
for x, y, label in ((0.9*width, 0.3*height, r'$q_\text{f}$'),
                    (0.9*width, -0.4*height, r'$q_\text{f}-2\pi$'),
                    (0, 0, r'$q_\text{i}$')):
    if x == 0:
        c.text(x-0.15, y, label, [text.halign.right, text.valign.middle])
    else:
        if y > 0:
            linecolor = linecolor1
        else:
            linecolor = linecolor2
Ejemplo n.º 7
0
c.insert(repo('origin', color.hsb(0.13, 1, 0.6), color.hsb(0.13, 0.1, 1)),
         [trafo.translate(4.6, 0.8)])

c.insert(read(1, maintainercolor), [trafo.translate(6.1, 1.05)])
c.insert(read(1, usercolor), [trafo.translate(6.1, 0.75)])
c.insert(write(1, usercolor), [trafo.translate(6.45, 0.75)])

opcolor = color.hsb(0.3, 1, 0.4)
c.stroke(path.line(2.1, 2.5, 4.4, 1.2),
         [deco.earrow, style.linestyle.dashed, opcolor])
c.text(2.3, 1.6, r'\textsf{fork}', [opcolor])

c.text(2.3, 1.3, r'\scriptsize\textsf{(only once)}', [opcolor])

p = path.path(path.moveto(5, 1.3), path.curveto(5, 1.7, 4.6, 2.9, 2.4, 2.9))
c.stroke(p, [deco.earrow, opcolor])
c.text(4.1, 2.7, r'\textsf{merge request}', [opcolor])

p = path.path(path.moveto(0.5, 2.5), path.curveto(0.5, 0, 1.0, -1.5, 2.65,
                                                  -1.5))
c.stroke(p, [deco.earrow, opcolor])
c.text(0.1, -1.3, r'\textsf{pull \scriptsize or}', [opcolor])
c.text(0.1, -1.75, r'\textsf{fetch/merge}', [opcolor])

p = path.path(path.moveto(4.0, -1.1), path.curveto(4.8, -0.5, 5, 0., 5, 0.5))
c.stroke(p, [deco.earrow, opcolor])
c.text(4.7, -0.8, r'\textsf{push}', [opcolor])

p = path.path(path.moveto(4.8, 0.5), path.curveto(4.0, 0, 3.8, -0.5, 3.8,
                                                  -1.1))
Ejemplo n.º 8
0
c.insert(read(1, maintainercolor), [trafo.translate(6.1, 1.05)])
c.insert(read(1, usercolor), [trafo.translate(6.1, 0.75)])
c.insert(write(1, usercolor), [trafo.translate(6.45, 0.75)])

opcolor = color.hsb(0.3, 1, 0.4)
c.stroke(path.line(2.1, 2.5, 4.4, 1.2),
         [deco.earrow, style.linestyle.dashed, opcolor])
c.text(2.3, 1.6, r'\textsf{fork}', [opcolor])

c.writePDFfile('{}_2.pdf'.format(basename))

c.text(2.3, 1.3, r'\scriptsize\textsf{(only once)}', [opcolor])

p = path.path(path.moveto(5, 1.3),
              path.curveto(5, 1.7, 4.6, 2.9, 2.4, 2.9))
c.stroke(p, [deco.earrow, opcolor])
c.text(4.1, 2.7, r'\textsf{pull request}', [opcolor])

p = path.path(path.moveto(0.5, 2.5),
              path.curveto(0.5, 0, 1.0, -1.5, 2.65, -1.5))
c.stroke(p, [deco.earrow, opcolor])
c.text(0.1, -1.3, r'\textsf{pull \scriptsize or}', [opcolor])
c.text(0.1, -1.75, r'\textsf{fetch/merge}', [opcolor])

p = path.path(path.moveto(4.0, -1.1),
              path.curveto(4.8, -0.5, 5, 0., 5, 0.5))
c.stroke(p, [deco.earrow, opcolor])
c.text(4.7, -0.8, r'\textsf{push}', [opcolor])

p = path.path(path.moveto(4.8, 0.5),
Ejemplo n.º 9
0
    def draw(self, vec=None, name=None, c=None, trafo=[]):
        nodes = self.nodes
        edges = self.edges

        R = 1.5
        r = 0.2

        if c is None:
            c = pyx.canvas.canvas()

        # fudge the layout
        layout = dict(self.layout)
        for i in nodes:
            dx, dy = self.fudge[i]
            x, y = layout[i]
            layout[i] = x + dx, y + dy

        for edge in edges:
            src, tgt = edge

            x0, y0 = layout[src]
            x1, y1 = layout[tgt]

            color = black

            delta = self.fudge.get(edge)
            if delta is None:
                c.stroke(path.line(R * x0, R * y0, R * x1, R * y1),
                         [color] + trafo)
            else:
                dx, dy = delta
                #x2, y2 = (x0+x1)/2. + dx, (y0+y1)/2. + dy
                x2, y2 = (2 * x0 + x1) / 3. + dx, (2 * y0 + y1) / 3. + dy
                x3, y3 = (x0 + 2 * x1) / 3. + dx, (y0 + 2 * y1) / 3. + dy
                ps = [
                    path.moveto(R * x0, R * y0),
                    path.curveto(R * x2, R * y2, R * x3, R * y3, R * x1,
                                 R * y1)
                ]
                c.stroke(path.path(*ps), [color] + trafo)
            # path.curveto(x1, y1, x2, y2, x3, y3)
            # path.rcurveto(dx1, dy1, dx2, dy2, dx3, dy3)

        for node in nodes:
            x, y = layout[node]

            p = path.circle(R * x, R * y, 0.2)
            c.fill(p, [white] + trafo)

            p = path.circle(R * x, R * y, 0.10)
            c.fill(p, [black] + trafo)

            if argv.show_nodes:
                c.text(R * x + 0.1, R * y + 0.1, node, trafo)

            val = 0
            if vec is not None:
                val = vec[node]
                assert int(val) == val

            if val > 0:
                color = dgreen
            elif val < 0:
                color = red
                val = -val
            else:
                continue

            for i in range(val):
                p = path.circle(R * x, R * y, (i + 2) * 0.10)
                c.stroke(p, [color, style.linewidth.THick] + trafo)

        if name is not None:
            print("Graph.draw: writePDFfile %s" % name)
            c.writePDFfile(name)
            c.writeSVGfile(name)
        return c