コード例 #1
0
ファイル: modular.py プロジェクト: punkdit/fibonacci
def surface(x, y, r, fill=shade, mark=False, orient=None):
    p = path.circle(x, y, r)
    if fill is not None:
        c.fill(p, [fill])
    c.stroke(p)
    if orient == True:
        c.stroke(p, [deco.earrow()])
    elif orient == False:
        c.stroke(p, [deco.earrow(), trafo.scale(x=x, y=y, sx=1, sy=-1)])
    if mark:
        p = path.circle(x, y-r, 0.06)
        c.fill(p)
コード例 #2
0
def build_canvas():
    cnv = canvas.canvas()
    cnv.stroke(make_line(w), [deco.earrow()])
    text_at(cnv, w / 2. - (.5, 0), r'$\vec{w}$')
    cnv.stroke(make_line(v), [deco.earrow()])
    text_at(cnv, v / 2. - (0, .5), r'$\vec{v}$')
    cnv.stroke(make_line(w, c * v), [deco.earrow(), rgb.red])
    text_at(cnv, w - (w - c * v) / 2 + (.1, .1), r'$\vec{w} - c \vec{v}$')
    cnv.stroke(make_line(c * v), [deco.earrow(), ls.dashed, rgb.blue])
    text_at(cnv, c * v / 1.5 - (0, .5), r'$c \vec{v}$')
    cnv.stroke(make_line(v * -1.5, v * 3), [ls.dotted])
    return cnv
コード例 #3
0
ファイル: graph.py プロジェクト: silverfield/pythonsessions
    def draw(self, r=5):
        c = canvas.canvas()

        x_centre = r + 1
        y_centre = r + 1

        angle_diff = 2*math.pi/self.n

        def get_pos(index):
            x_pos = x_centre + math.sin(index*angle_diff)*r
            y_pos = y_centre + math.cos(index*angle_diff)*r
            return x_pos, y_pos

        # nodes
        for i in range(self.n):
            x, y = get_pos(i)
            c.stroke(path.circle(x, y, 1))
            c.text(x, y, i)

        # edges
        for i in range(self.n):
            for j in range(self.n):
                if math.isnan(self.adj_mat[i, j]):
                    continue
                x1, y1 = get_pos(i)
                x2, y2 = get_pos(j)
                x_offset = (x2 - x1)/math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
                y_offset = (y2 - y1)/math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
                arc = path.line(x1 + x_offset, y1 + y_offset, x2 - x_offset, y2 - y_offset)
                c.stroke(arc, [deco.earrow()])
                c.text((x1 + x2)/2 + x_offset, (y1 + y2)/2 + y_offset, self.adj_mat[i, j])  # moved towards the end pt

        c.writePDFfile("graph")
コード例 #4
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
def hole(x, y, radius, msg=None, extra=[], arrow=None):
    p = path.circle(x, y, radius)
    c.fill(p, [white]+extra)
    c.stroke(p, extra)
    if arrow is not None:
        c.stroke(p, extra+[deco.earrow(size=arrow)])
    if msg:
        c.text(x, y, msg, [text.halign.boxcenter, text.valign.middle])
コード例 #5
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
def ellipse(x, y, radius, sx=1., sy=1., color=None, extra=[], arrow=None):
    p = path.circle(x, y, radius)
    t = trafo.scale(sx=sx, sy=sy)
    if color:
        c.fill(p, [t, shade]+extra)
    c.stroke(p, [t]+extra)
    if arrow is not None:
        c.stroke(p, [t]+extra+[deco.earrow(size=arrow)])
コード例 #6
0
ファイル: braid.py プロジェクト: punkdit/thesis2015
def loop(x0, y0, r1, theta0, theta1, tpy):
    t = Turtle(x0, y0, theta0)
    #theta = 0.55*pi
    theta = theta1
    r2 = 2*r1*sin(theta - 0.5*pi)
    t.penup().fwd(0.1*r1).pendown()
    t.fwd(0.9*r1).right(theta).fwd(r2).right(theta).fwd(0.9*r1) 
    t.stroke([deco.earrow(), 
        deformer.smoothed(4.0), style.linewidth.Thick,
        color.transparency(tpy), tr])
コード例 #7
0
ファイル: Kmu_plots.py プロジェクト: AntipovDen/Master
def make_picture_for_two_vertices():
    c = canvas.canvas()
    c.stroke(path.rect(0, 0, 12, 1))
    c.stroke(path.rect(1, 0, 1, 1), [style.linewidth.THICK])
    c.stroke(path.rect(5, 0, 1, 1), [style.linewidth.THICK])
    c.stroke(path.rect(7, 0, 1, 1), [style.linewidth.THICK])
    c.stroke(path.rect(10, 0, 1, 1), [style.linewidth.THICK])
    c.stroke(path.line(-0.5, 0.5, -0.5, 6), [deco.earrow(size=0.2)])
    c.stroke(path.line(1.5, 0.5, 1.5, 5), [deco.earrow(size=0.2)])
    c.stroke(path.line(5.5, 0.5, 5.5, 4), [deco.earrow(size=0.2)])
    c.stroke(path.line(7.5, 0.5, 7.5, 3), [deco.earrow(size=0.2)])
    c.stroke(path.line(10.5, 0.5, 10.5, 2), [deco.earrow(size=0.2)])
    c.stroke(path.line(12.5, 0.5, 12.5, 1), [deco.earrow(size=0.2)])
    c.stroke(path.line(5.5, 4, 8, 4), [style.linewidth.THIN])
    c.stroke(path.line(7, 3, 8, 3), [style.linewidth.THIN])
    c.text(7.5, 3.5, r"$\delta_i = l_i - l_{i + 1}$", [text.halign.boxcenter, text.valign.middle])
    c.stroke(path.line(6, 0, 6, -1), [style.linewidth.THIN])
    c.stroke(path.line(7, 0, 7, -1), [style.linewidth.THIN])
    c.text(6.5, -0.4, r"$d_i$", [text.halign.boxcenter, text.valign.middle])
    c.text(-0.5, 3, r"$l_0 = 1.0$", [text.halign.boxleft])
    c.text(5.5, 2.5, r"$l_i$", [text.halign.boxright])
    c.text(7.5, 2, r"$l_{i+1}$", [text.halign.boxleft])
    c.text(12.5, 1.1, r"$l_{E+1} = 0.0$", [text.halign.boxcenter])

    c.writePDFfile("test_picture.pdf")
コード例 #8
0
ファイル: decode.py プロジェクト: punkdit/fibonacci
def draw(dx=0., dy=0., use_arrows=True):

    r = 4.*m
    syndrome1 = syndrome.copy()
    lines = []
    for tree in trees:
      for p0 in tree.sites:
        x0, y0 = coord(*p0)
        c.fill(path.circle(x0+dx, y0+dy, r), [grey])
        p1 = tree.parent[p0]
        #print p0, p1
        if p1 is None:
            continue # root
        lines.append((p0, p1))

        x1, y1 = coord(*p1)
        #syndrome1[p0] = 0
        #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
        #    [style.linewidth.Thick, deco.earrow(size=0.3)])

        if x0==x1:
            c.fill(path.rect(x0-r+dx, y0+dy, 2*r, y1-y0), [grey])
        else:
            c.fill(path.rect(x0+dx, y0-r+dy, x1-x0, 2*r), [grey])
        c.fill(path.circle(x0+dx, y0+dy, r), [grey])
        c.fill(path.circle(x1+dx, y1+dy, r), [grey])
        #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
        #    [style.linewidth.THICK, style.linecap.round, grey])

    if use_arrows:
      t = 0.1
      s = 1.-t
      for (p0, p1) in lines:
        x0, y0 = coord(*p0)
        x1, y1 = coord(*p1)
        #x0, x1 = s*x0+t*x1, s*x1+t*x0
        #y0, y1 = s*y0+t*y1, s*y1+t*y0
        if syndrome[p1]:
            x1 = s*x1+t*x0
            y1 = s*y1+t*y0
        syndrome1[p0] = 0
        c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
            [style.linewidth.Thick, style.linecap.round, deco.earrow(size=0.2)])

    for i, j in sites:
        c.stroke(path.rect(j*w+dx, i*h+dy, w-2*m, h-2*m))
        if syndrome[i,j]:
            x, y = coord(i, j)
            anyon(x+dx, y+dy, 0.1*w)

    syndrome[:] = syndrome1
コード例 #9
0
ファイル: hexagon.py プロジェクト: punkdit/fibonacci
def tetra(x, y, count=None, subcount=None, rev=1, back=True, front=True, reflect=False):

    if back:
        circle(x, y, r, shade)

    rr = 1.0*r
    if subcount is not None:
        ps = []
        for i in range(3):
            theta1 = rev*2*(i+subcount)*pi/3
            if i==0:
                # start of curve
                x1, y1 = x+rr*sin(theta1), y+rr*cos(theta1)
                ps.append((x1, y1))
            if i==1:
                x1, y1 = x+0.7*r*sin(theta1), y+0.7*r*cos(theta1)
                ps.append((x1, y1))
            else:
                x1, y1 = x+0.4*r*sin(theta1), y+0.4*r*cos(theta1)
                ps.append((x1, y1))
            if i==2:
                # end of curve
                x1, y1 = x+1.0*rr*sin(theta1), y+1.0*rr*cos(theta1)
                ps.append((x1, y1))
        c.stroke(path.path(
            path.moveto(*ps[0]),
            path.lineto(*ps[1]),
            path.lineto(*ps[2]), 
            path.lineto(*ps[3]), 
            path.lineto(*ps[4])), 
            st_curve+[deformer.smoothed(0.6)])

    if front:
        for theta1 in [0., 2*pi/3, 4*pi/3]:
            x1, y1 = x+0.5*r*sin(theta1), y+0.5*r*cos(theta1)
            circle(x1, y1, r0, white)

    if count is not None:

        assert 0<=count<=2
        s = 0.86*r
        r1 = 2.4*r0
        extra = []
        #c.text(x, y, count)
        if reflect:
            #count = [0, 1, 2][count]
            extra.append(trafo.scale(x=x, y=y, sx=-1, sy=1))
        extra += [trafo.rotate(-count*120, x=x, y=y)]
        t = Turtle(x1, y1-r1, -pi/2).right(pi, r1).fwd(s).right(pi, r1).fwd(s)
        t.stroke(extra)
        t.stroke(extra+[deco.earrow()])
コード例 #10
0
ファイル: draw.py プロジェクト: nespinoza/pyx-utils
def arrow(g,
          x_coord_init,
          y_coord_init,
          x_coord_final,
          y_coord_final,
          size,
          line_color,
          stroke_color=None,
          fill_color=None):
    """
        Function that draws an arrow in a given plot

        INPUTS:

                g               (Object) A graph-type object to which you want to add the text

                x_coord_init    (Double) x-coordinate (in plot units) at which you want the arrow
                                to start.

                y_coord_init    (Double) y-coordinate (in plot units) at which you want the arrow
                                to start.

                x_coord_final   (Double) x-coordinate (in plot units) at which you want the arrow
                                to end.

                y_coord_final   (Double) y-coordinate (in plot units) at which you want the arrow
                                to end.

		size		(int) Size of the arrow.

		line_color	(instance) Instance color that defines the color of the line of the arrow.

		stroke_color	(instance, optional) Defines the stroke color (default is same as line_color).

		fill_color	(instance, optional) Defines the color fill of the arrow (default is same as 
				line_color).

        """

    if stroke_color is None:
        stroke_color = line_color
    if fill_color is None:
        fill_color = line_color

    x0, y0 = g.pos(x_coord_init, y_coord_init)
    xf, yf = g.pos(x_coord_final, y_coord_final)
    g.stroke(pyx_path.line(x0,y0,xf,yf),\
     [pyx_style.linewidth.normal, pyx_style.linestyle.solid, line_color,\
      pyx_deco.earrow([pyx_deco.stroked([stroke_color]),\
      pyx_deco.filled([fill_color])], size=0.1)])
コード例 #11
0
def earrowLine(canv,
               pta,
               ptb,
               linewidth=LINE_DEF_WIDTH,
               color=LINE_DEF_COLOR,
               marks=False):

    line = path.line(pta.x, pta.y, ptb.x, ptb.y)

    arrow_type = deco.earrow([deco.stroked([color])], size=10)

    canv.stroke(line, [style.linewidth(linewidth), color, arrow_type])
    if marks:
        pta.mark(canv)
コード例 #12
0
ファイル: refactoring.py プロジェクト: punkdit/fibonacci
def manifold(x, y, labels):

    global count
    if count in [0, 2]:
        c.stroke(path.line(x-r0, y, x+r1+r0, y), st_curve)
    else:
        extra = list(st_curve)
        if count==3:
            extra.append(trafo.scale(x=x, y=y, sx=1, sy=-1))
        Turtle(x-0.85*r0, y, pi/2).\
            fwd(0.3).\
            right(0.25*pi, 0.4).left(0.50*pi, 0.73).left(0.88*pi, 0.15).\
            fwd(0.55).\
            right(0.88*pi, 0.15).right(0.50*pi, 0.73).left(0.25*pi, 0.4).goto(x+r1+r0, y).\
            stroke(extra)

#    st_target = st_curve+st_dashed
    st_target = [red, style.linewidth.THick, deco.earrow(size=0.2)]
    if count == 0:
        Turtle(x, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*r1).stroke(st_target)
    elif count == 3:
        Turtle(x-0.05, y, 0.90*pi).left(0.30*pi, 0.8).left(0.3*pi, 2.8).stroke(st_target)
    else:
        Turtle(x+r0, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*(r1-r0)).stroke(st_target)

    for i in range(3):
        _x = [x, x+r0, x+r1][i]
        p = path.circle(_x, y, 0.08)
        c.fill(p, [white])
        c.stroke(p)
        ydelta = 0.25
        xdelta = 0.00
        if count==1  and labels[i]=="a":
            ydelta = -0.35
            xdelta = +0.1
        if count==3  and labels[i]=="a":
            ydelta = -0.35
            xdelta = -0.1
        c.text(_x+xdelta, y+ydelta, r"$\scriptstyle %s$"%labels[i], south)

    c.text(x+(r0+r1)/2., y-0.2, "...", north)

    c.stroke(path.circle(x+r0/2, y, r0), [trafo.scale(x=x+r0/2, y=y, sx=1.0, sy=0.8)])

    if count in [0, 3]:
        c.text(x+r0, y+0.3*h, "$\omega$", southwest)
    else:
        c.text(x+r0, y+0.3*h, "$f(\omega)$", southwest)

    count += 1
コード例 #13
0
ファイル: render.py プロジェクト: punkdit/fibonacci
def draw(dx=0., dy=0.):

    r = 4.*m
    data1 = data.copy()
    lines = []
    for tree in trees:
      for p0 in tree.sites:
        x0, y0 = coord(*p0)
        c.fill(path.circle(x0+dx, y0+dy, r), [grey])
        p1 = tree.parent[p0]
        #print p0, p1
        if p1 is None:
            continue # root
        lines.append((p0, p1))

        x1, y1 = coord(*p1)
        #data1[p0] = 0
        #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
        #    [style.linewidth.Thick, deco.earrow(size=0.3)])

        if x0==x1:
            c.fill(path.rect(x0-r+dx, y0+dy, 2*r, y1-y0), [grey])
        else:
            c.fill(path.rect(x0+dx, y0-r+dy, x1-x0, 2*r), [grey])
        c.fill(path.circle(x0+dx, y0+dy, r), [grey])
        c.fill(path.circle(x1+dx, y1+dy, r), [grey])
        #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
        #    [style.linewidth.THICK, style.linecap.round, grey])

    for (p0, p1) in lines:
        x0, y0 = coord(*p0)
        x1, y1 = coord(*p1)
        data1[p0] = 0
        c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
            [style.linewidth.Thick, deco.earrow(size=0.3)])

    for i, j in sites:
        c.stroke(path.rect(j*w+dx, i*h+dy, w-2*m, h-2*m))
        if data[i,j]:
            x, y = coord(i, j)
            anyon(x+dx, y+dy, 0.1*w)

    data[:] = data1
コード例 #14
0
    def render(self, cvs=None, name=None, size=1.0, double=False):
        if cvs is None:
            cvs = canvas.canvas()

        dx, dy = size, -size
        r = 0.05 * size
        mul = 1.5  # critical radius

        cx = self.cx
        critical = self.get_critical(0)
        cells = cx.get_cells(0)
        for cell in cells:
            i, j = cell.key
            x, y = dx * j, dy * i
            cell.pos = (x, y)
            if cell in critical:
                cvs.stroke(path.circle(x, y, mul * r), [blue] + st_thick)
            else:
                cvs.fill(path.circle(x, y, r))

        critical = self.get_critical(1)
        cells = cx.get_cells(1)
        for cell in cells:
            i, j, k = cell.key
            assert k in "hv"
            x0, y0 = dx * j, dy * i
            if k == "h":
                x1, y1 = dx * (j + 1), dy * i
            else:
                x1, y1 = dx * j, dy * (i + 1)

            x = 0.5 * (x0 + x1)
            y = 0.5 * (y0 + y1)
            if cell in critical:
                cvs.stroke(path.circle(x, y, mul * r), [red] + st_thick)
            else:
                cvs.fill(path.circle(x, y, 1 * r), [red] + st_thick)
            cvs.stroke(path.line(x0, y0, x1, y1))
            cell.pos = (x0, y0, x1, y1, x, y)

        critical = self.get_critical(2)
        cells = cx.get_cells(2)
        for cell in cells:
            i, j = cell.key
            x, y = dx * (j + 0.5), dy * (i + 0.5)
            cell.pos = (x, y)
            if cell in critical:
                cvs.stroke(path.circle(x, y, mul * r), [green] + st_thick)

        for src, tgt in self.pairs[0]:
            i0, j0 = src.key  # vert
            i1, j1, k = tgt.key  # edge
            if k == "h":
                assert i0 == i1  # same row
                if j0 == j1:
                    pass
                elif j0 - 1 == j1:
                    pass
                elif j0 < j1:
                    j0 = j1 + 1
            else:
                assert j0 == j1
                if i1 > i0:
                    i0 = i1 + 1

            x0, y0 = dx * j0, dy * i0
            if k == "h":
                x1, y1 = dx * (j1 + 0.5), dy * i1
            else:
                x1, y1 = dx * j1, dy * (i1 + 0.5)
            if double:
                dx1, dy1 = x1 - x0, y1 - y0
                x1 += dx1
                y1 += dy1
            cvs.stroke(path.line(x0, y0, x1, y1),
                       [deco.earrow(), green] + st_THick)

        for src, tgt in self.pairs[1]:
            i0, j0, k = src.key  # edge
            i1, j1 = tgt.key  # face

            if k == "h":
                assert j0 == j1  # same col
                if i0 == i1 or i0 - 1 == i1:
                    pass
                elif i0 < i1:
                    #i0 = i1+1
                    i1 = i0 - 1
            if k == "v":
                assert i0 == i1  # same row
                if j0 == j1 or j0 - 1 == j1:
                    pass
                elif j0 < j1:
                    #j0 = j1+1
                    j1 = j0 - 1

            x0, y0 = dx * j0, dy * i0
            if k == "h":
                x1, y1 = dx * (j0 + 1), dy * i0
            else:
                x1, y1 = dx * j0, dy * (i0 + 1)
            x0 = 0.5 * (x0 + x1)
            y0 = 0.5 * (y0 + y1)
            x1, y1 = dx * (j1 + 0.5), dy * (i1 + 0.5)

            if double:
                dx1, dy1 = x1 - x0, y1 - y0
                x0 -= dx1
                y0 -= dy1
            cvs.stroke(path.line(x0, y0, x1, y1),
                       [deco.earrow(), blue] + st_THick)

        if name:
            cvs.writePDFfile(name)
            cvs.writeSVGfile(name)
            print("saved", name)

        return cvs
コード例 #15
0
ファイル: braid.py プロジェクト: punkdit/thesis2015
    if label:
        c.text(W+0.2, 0., label, west+[trafo.translate(x, y)])



#############################################################################
#
#


c = canvas.canvas()

W = 5.
H = 3.

c.stroke(path.line(0.0, -0.2, 0., H), [deco.earrow()])
c.stroke(path.line(-0.2, 0., W, 0), [deco.earrow()])
my = 0.25
c.stroke(path.line(-0.2, -my*0.2, 0.9*W, my*W), [deco.earrow()])

x0, y0 = 0.3*W, 0.3*H
x1, y1 = x0+0.3*W, y0+my*0.3*W


#t = Turtle(x0, y0, pi/4)
#t.penup().fwd(0.2).pendown()
#theta, r = 0.25*pi, 2.0
#t.right(theta, r).right(0.8*pi, 0.2).right(theta, r)
#t.fwd(0.1).stroke([deco.earrow()])

tr = trafo.scale(x=0.5*W, y=0.3*H, sx=1.3, sy=1.5)
コード例 #16
0
ファイル: trellis.py プロジェクト: punkdit/surface2015
def arrow(x0, y0, x1, y1, a=0.1, b=0.9):
    x00, y00 = conv(a, (x0, y0), (x1, y1))
    x11, y11 = conv(b, (x0, y0), (x1, y1))
    c.stroke(path.line(x00, y00, x11, y11), [deco.earrow()])
コード例 #17
0
ファイル: skein.py プロジェクト: punkdit/fibonacci
def dopath(ps, extra=[], fill=[], closepath=False, smooth=0.3, stroke=True):
    ps = [path.moveto(*ps[0])]+[path.lineto(*p) for p in ps[1:]]
    if closepath:
        ps.append(path.closepath())
    p = path.path(*ps)
    if fill:
        c.fill(p, [deformer.smoothed(smooth)]+extra+fill)
    if stroke:
        c.stroke(p, [deformer.smoothed(smooth)]+extra)




st_curve = [green, style.linewidth.THick]
st_curve_arrow = st_curve + [deco.earrow(size=0.2)]


def circle(x, y, r, shade, deco=[], mark=False):
    p = path.circle(x, y, r)
    c.fill(p, [shade])
    c.stroke(p, deco)
    if mark:
        c.fill(path.circle(x, y-r, 0.05))



###############################################################################
#
#
コード例 #18
0
ファイル: process.py プロジェクト: punkdit/fibonacci
W = 3.4
H = 5.0

dy = 0.9

x, y = 0., 0.
r = 0.3

c.text(x, y, "Decoder", center)
c.text(x, y-0.2, "(classical)", north)

c.stroke(path.line(x, y+r, x, y+H)) #, [deco.earrow()])

y += dy
c.stroke(path.line(x+2*W-r, y, x+W+r, y), [deco.earrow()])
c.text(x+1.5*W, y+0.1, "noise", south)

y += 0.5*dy
c.stroke(path.line(x+r, y, x+W-r, y), [deco.earrow()])
c.text(x+0.5*W, y+0.1, "recovery", south)

y += dy
c.stroke(path.line(x+W-r, y, x+r, y), [deco.earrow()])
c.text(x+0.5*W, y+0.1, "syndrome", south)

y += 0.5*dy
c.stroke(path.line(x+0.5*W, y+0.2, x+0.5*W, y-0.2+dy), st_dotted)

y += dy
コード例 #19
0
ファイル: poster.py プロジェクト: punkdit/fibonacci
points.insert(idx, (1.5*dx, -1.4*dy)); idx+=3 # next pair
points.insert(idx, (3.7*dx, -1.4*dy)); idx+=1
points.insert(idx, (3.7*dx, -1.6*dy)); idx+=1
points.insert(idx, (1.7*dx, -1.6*dy)); idx+=3 # next pair
points.insert(idx, (1.7*dx, -3.3*dy)); # end

items = []
for i, p in enumerate(points):
    if i==0:
        items.append(path.moveto(*p))
    else:
        items.append(path.lineto(*p))

c.stroke(path.path(*items),
    [trafo.translate(tx0, ty0), lred, deformer.smoothed(2.0),
    style.linewidth.THICk, deco.earrow(size=0.3)])

for (s, t) in [(0, 1), (2, 3), (4, 5)]:
    pair(points0[s], points0[t])


y -= 4.*dy
c.text(x, y,
r"""When we yank the red line straight
we find out what braid moves to do:
""",
[text.parbox(dw-2*m),])

# Linear order:
ty0 -= 4.5*dy + 2*dr
dx = 0.9
コード例 #20
0
def slepc(Gx, Gz, Hx, Hz, Rx, Rz, Pxt, Qx, Pz, Tx, **kw):

    name = argv.get("name", "ex3.tmp.c")
    print("slepc: name=%s"%name)

    r = len(Rx)
    n = 2**r
    assert (r<40), "ugh"

    #code = Code("body.h")
    code = Code()

    code.append("#define DIMS (%d)"%n)

    code.append("static void matmult(PetscScalar *py, const PetscScalar *px, long nx)")
    code.begin()
    code.append("assert(DIMS == %d);"%n)
    code.append("assert(nx == %d);"%n)
    code.append("memset(py, 0, sizeof(PetscScalar)*nx);")

    offset = argv.get("offset", None)

    mz = len(Gz)
    t = None
    #excite = argv.excite
    #if excite is None:
    excite = kw.get("excite") or argv.excite

    if excite is not None:
        print("excite:", excite)
        if type(excite) is tuple:
            t = Tx[excite[0]]
            for i in range(1, len(excite)):
                t = (t + Tx[excite[i]])%2
        else:
            assert type(excite) in (int, int)
            t = Tx[excite]
        print("t:", shortstr(t))
        Gzt = dot2(Gz, t)
        print("Gzt:", shortstr(Gzt))

    weights = kw.get("weights")
    if weights is not None:
        assert len(weights)==len(Gx)

    RR = dot2(Gz, Rx.transpose())

    PxtQx = dot2(Pxt, Qx)
    gxs = [getnum(dot2(gx, PxtQx)) for gx in Gx]
    gxs.sort()
    uniq_gxs = list(set(gxs))
    uniq_gxs.sort()

    code.append("long v;")
    code.append("int k;")
    code.append("struct timeval t0, t1;")
    code.append("gettimeofday(&t0, NULL);")
    code.append("for(v=0; v<%d; v++)"%n)
    code.begin()
    code.append("double pxv = px[v];")
    if n >= 128:
        code.append(r'if((v+1) %% %d == 0)' % (n//128))
        code.begin()
        code.append("gettimeofday(&t1, NULL);")
        code.append("long delta = t1.tv_sec-t0.tv_sec;")
        code.append("if(delta>1)")
        code.append('{printf("[%lds]", delta);fflush(stdout);}')
        code.append('t0 = t1;')
        code.end()
    code.append("k = 0;")
    for i, row in enumerate(RR):
        if t is not None and Gzt[i]==1:
            code.append("k += (countbits_fast(v&%s)+1) %% 2;" % getnum(row))
        else:
            code.append("k += countbits_fast(v&%s) %% 2;" % getnum(row))
    cutoff = argv.cutoff
    if cutoff is not None:
        code.append("if(k>%d) continue; // <-------- continue" % cutoff)
    else:
        code.append("if(k>cutoff) continue; // <-------- continue")
    code.append("py[v] += pxv * (%d - 2*k);" % mz)

    if weights is None:
        for gx in uniq_gxs:
            s = '+'.join(['pxv']*gxs.count(gx))
            code.append("py[v^%s] += %s;" % (gx, s))
    else:
        gxs = [getnum(dot2(gx, PxtQx)) for gx in Gx]
        for i, gx in enumerate(gxs):
            code.append("py[v^%s] += %s*pxv;" % (gx, weights[i]))

    code.end()
    code.end()

    if name is None:
        return

    s = code.output()

    src = open("ex3.c").read()
    match = '\n#include "body.h"\n'
    assert match in src
    src = src.replace(match, s)
    assert name and name.endswith(".c")
    f = open(name, 'w')
    tag = hash(src)
    print(("hash(src):", tag))
    f.write(src)
    f.close()

    import socket
    host = socket.gethostname()
    if host == "bucket":
        cmd = "gcc MATCH.c -O3 -o MATCH -I/home/simon/local/petsc/arch-linux2-c-debug/include -I/home/simon/local/petsc/include/petsc/mpiuni -I/home/simon/local/petsc/include -I/home/simon/local/slepc-3.7.1/include -I/home/simon/local/slepc-3.7.1/arch-linux2-c-debug/include/ -L/home/simon/local/petsc/arch-linux2-c-debug/lib -L/home/simon/local/slepc-3.7.1/arch-linux2-c-debug/lib -lpetsc -lslepc"
    elif host == "hero":
        cmd = "gcc MATCH.c -O3 -o MATCH -I/usr/include/openmpi -I/usr/include/petsc -I/usr/include/slepc -lpetsc -lslepc -lmpi"
    else:
        cmd = "gcc -O3 MATCH.c -I/suphys/sburton/include/ -o MATCH -lpetsc -L$PETSC_DIR/$PETSC_ARCH/lib -L$SLEPC_DIR/$PETSC_ARCH/lib -lslepc"

    cmd = cmd.replace("MATCH.c", name)
    stem = name[:-2]
    cmd = cmd.replace("MATCH", stem)

    rval = os.system(cmd)
    assert rval == 0
    #print("exec:", hash(open(stem).read()))

    nev = argv.get("nev", 1)
    cmd = "./%s -eps_nev %d -eps_ncv %d -eps_largest_real" 

    if argv.plot:
        cmd += " -eps_view_vectors binary:evec.bin "

    cmd = cmd%(stem, nev, max(2*nev, 4))
    eps_tol = argv.get("eps_tol", 1e-4)
    if eps_tol is not None:
        cmd += " -eps_tol %s "%eps_tol

    #cmd += " -eps_type arnoldi -info -eps_monitor -eps_tol 1e-3"
    print(cmd)
    #rval = os.system(cmd)
    #assert rval == 0
    f = os.popen(cmd)
    s = f.read()
    #print(s)
    lines = s.split('\n')
    vals = []
    for line in lines:
        line = line.strip()
        flds = line.split()
        #print("parse", flds)
        try:
            a, b = flds
            a = float(a)
            b = float(b)
            vals.append(a)
        except:
            pass

    if not argv.plot:
        print(("vals:", vals))
        return vals

    assert argv.plot.endswith(".pdf")

    s = open("evec.bin").read()
    sz = 8*2**r

    if len(s)==sz+8:
        s = s[8:]
    elif len(s)==sz+16:
        s = s[16:]
    #elif len(s)==2*(sz+16): # got two vectors
    #    s = s[16:16+sz] # pick the first vector
    elif len(s)%(sz+16) == 0:
        count = len(s)/(sz+16)
#        s = s[16:16+sz] # pick the first vector
        ev_idx = argv.get("ev_idx", 0)
        s = s[16+ev_idx*(16+sz):(ev_idx+1)*(16+sz)]
    else:
        assert 0, "sz=%d but s=%s"%(sz, len(s))

    vec0 = numpy.fromstring(s, dtype=">d")
    assert len(vec0)==2**r

    assert excite is None

    print("graphing...")
    gz, n = Gz.shape
    xdata = []
    lookup = {}
    GzRxt = dot2(Gz, Rx.transpose())
    for i, v in enumerate(genidx((2,)*r)):
        v = array2(v)
        lookup[v.tobytes()] = i
        syndrome = dot2(GzRxt, v)
        value = gz - 2*syndrome.sum()
        xdata.append(value)

    pdata = {}
    ndata = {}
    my = 20. # mul y
    EPSILON = argv.get("EPSILON", 1e-6)

    def yfunc(y):
        y = log2(abs(y))
        y = int(round(my*y))
        return y

    for i in range(len(vec0)):
        x = xdata[i] # integer
        y = vec0[i]
        if abs(y) < EPSILON:
            continue
        if y > 0.:
            y = yfunc(y)
            pdata[x, y] = pdata.get((x, y), 0) + 1
        else:
            y = yfunc(y)
            ndata[x, y] = ndata.get((x, y), 0) + 1

    from pyx import graph, canvas, path, trafo, color, deco, text
    
    north = [text.halign.boxcenter, text.valign.top]
    northeast = [text.halign.boxright, text.valign.top]
    northwest = [text.halign.boxleft, text.valign.top]
    south = [text.halign.boxcenter, text.valign.bottom]
    southeast = [text.halign.boxright, text.valign.bottom]
    southwest = [text.halign.boxleft, text.valign.bottom]
    east = [text.halign.boxright, text.valign.middle]
    west = [text.halign.boxleft, text.valign.middle]
    center = [text.halign.boxcenter, text.valign.middle]
    
    c = canvas.canvas()
    sx = 0.4
    sy = 1.4
    tr = trafo.scale(sx, sy)

    green = color.rgb(0.2,0.6,0.2)
    brown = color.rgb(0.8,0.2,0.2)
    grey = color.rgb(0.4,0.4,0.4)
    lgrey = color.rgb(0.8,0.8,0.8)

    W = 2*gz
    H = log2(EPSILON)
    dy = 0.5 * 1.2/my

    X0 = -gz
    Y0 = 0.

    def showp(gx, radius):
        v = dot2(gx, PxtQx)
        syndrome = dot2(GzRxt, v)
        x = gz - 2*syndrome.sum()
        i = lookup[v.tobytes()]
        #print syndrome, syndrome.sum(), vec0[i]
        y = (1./my)*yfunc(vec0[i]) + 0.5*dy
        #y = 0.5*dy + log2(abs(vec0[i]))
        c.fill(path.circle(-x*sx, y*sy, radius), [lgrey])

    showp(zeros2(n), 0.8)
    for gx in Gx:
        showp(gx, 0.4)

    for gx0 in Gx:
      for gx1 in Gx:
        gx = (gx0+gx1)%2
        if gx.sum()==0:
            continue
        showp(gx, 0.2)

    for i in range(0, gz+1):
        x, y = X0+2*i, Y0
        c.stroke(path.line(x, y, x, y+H), [tr, grey])
        if i%2 == 0:
            c.text(x*sx, y*sy + 0.2, "%d"%i, south)

    c.stroke(path.line(X0, Y0, X0+1.0*W+3.5, Y0), [tr, deco.earrow(size=0.5)])
    c.stroke(path.line(X0, Y0, X0, Y0+1.0*H-0.5), [tr, deco.earrow(size=0.5)])

    y = 1.0
    i = 0
    while y > EPSILON:

        x = X0*sx
        y1 = sy*(1./my)*yfunc(y)
        c.stroke(path.line(x, y1, x-0.1, y1))

        c.text(x-0.3, y1, "%d"%i, east)

        y /= 2.
        i -= 1

    R = 0.15
    for key, value in list(pdata.items()):
        x, y = key
        y = y/my
        x = -x
        value = 1 + math.log(value)
        r = R*value
        #c.stroke(path.circle(x, y, r))
        #c.stroke(path.line(x, y, x+r, y), [brown, tr])
        c.fill(path.rect(x, y, r, dy), [brown, tr])

    for key, value in list(ndata.items()):
        x, y = key
        y = y/my
        x = -x
        value = 1 + math.log(value)
        r = R*value
        #c.stroke(path.circle(x, y, r))
        #c.stroke(path.line(x-r, y, x, y), [green, tr])
        c.fill(path.rect(x-r, y, r, dy), [green, tr])

    c.writePDFfile(argv.plot)


    if 0:
        print("graph..")
    
        g = graph.graphxy(
            width=16,
            x=graph.axis.linear(reverse=True),
            y=graph.axis.linear())
            #y=graph.axis.log(min=0.8*vec0.min(), max=1.2*vec0.max()))
    
        g.plot(graph.data.values(x=xdata, y=ydata))
        g.writePDFfile(argv.plot)
コード例 #21
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
def arrowcircle(x, y, r, ar=0.1):
    p = path.circle(x, y, r)
    c.stroke(p)
    c.stroke(p, [deco.earrow(size=ar)])
コード例 #22
0
ファイル: refactoring.py プロジェクト: punkdit/fibonacci
        self.x = x
        self.y = y
        return self

    def left(self, dtheta, r=0.):
        self.right(-dtheta, -r)
        return self

    def stroke(self, extra=[], fill=[], closepath=False):
        dopath(self.ps, extra, fill, closepath, smooth=0.)
        return self



st_curve = [green, style.linewidth.THick]
st_curve = st_curve + [deco.earrow(size=0.2)]


def circle(x, y, r, shade, deco=[], mark=False):
    p = path.circle(x, y, r)
    c.fill(p, [shade])
    c.stroke(p, deco)
    if mark:
        c.fill(path.circle(x, y-r, 0.05))




###############################################################################
#
#
コード例 #23
0
ファイル: hexagon.py プロジェクト: punkdit/fibonacci
        if penup:
            self.ps = [(x, y)] # HACK
        return self

    def left(self, dtheta, r=0., penup=False):
        self.right(-dtheta, -r, penup=penup)
        return self

    def stroke(self, extra=[], fill=[], closepath=False):
        dopath(self.ps, extra, fill, closepath, smooth=0.)
        return self



st_curve = [green, style.linewidth.THick]
st_curve = st_curve + [deco.earrow(size=0.2)]


def circle(x, y, r, shade, deco=[], mark=False):
    p = path.circle(x, y, r)
    c.fill(p, [shade])
    c.stroke(p, deco)
    if mark:
        c.fill(path.circle(x, y-r, 0.05))


w, h = 1.5, 1.5

r = 0.7*w
r0 = 0.06*w
コード例 #24
0
ファイル: render.py プロジェクト: punkdit/fibonacci
# --------------------------------------------------------------------

w, h = 1.0, 1.0
m = 0.1

#x0, y0 = 0.6, h + 10*m
x0, y0 = 0., 0.

push()
#c.text(x0-0.8, y0, "(a)")

c.stroke(path.rect(x0, y0, w, h), dashed)
c.stroke(path.rect(x0+w+m, y0, w, h), dotted)

grarrow = [green, style.linewidth.THick, deco.earrow(size=0.2)]

y = y0+0.3*h
c.stroke(path.line(x0+0.5*w, y, x0+1.5*w+m, y), grarrow)
anyon(x0+0.8*w, y)
anyon(x0+m+1.2*w, y)
    
y = y0+0.7*h
c.stroke(path.line(x0+1.5*w+m, y, x0+0.5*w, y), grarrow)
anyon(x0+0.8*w, y)
anyon(x0+m+1.2*w, y)

pop([trafo.rotate(-90), trafo.translate(0.7, 2.5*h)])
c.text(0., 0.5*h, "(a)")

# --------------------------------------------------------------------
コード例 #25
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
    u, v = warp(u, v)
    ps.append(path.lineto(u, v))
ps.append(path.lineto(x+w+m, y+0.5*h-r))
p = path.path(*ps)
c.stroke(p, g_curve+sm) #+[trafo.scale(1.4, 1.0, x=x+1.*w+m, y=y+0.5*h)])



c.writePDFfile("pic-cells-0.pdf")


#############################################################################
#
#

g_arrow = g_curve + [deco.earrow(size=0.3)]

def up_arrow(x, y):
    c.stroke(path.line(x, y-m0, x, y+m0), g_arrow)
def dn_arrow(x, y):
    c.stroke(path.line(x, y+m0, x, y-m0), g_arrow)
def le_arrow(x, y):
    c.stroke(path.line(x+m0, y, x-m0, y), g_arrow)
def ri_arrow(x, y):
    c.stroke(path.line(x-m0, y, x+m0, y), g_arrow)


w = 1.5
h = 1.5

c = canvas.canvas()
コード例 #26
0
ファイル: trellis.py プロジェクト: punkdit/surface2015
        for j0 in range(n):
            y0 = j0 * h - h * (n - 1) / 2.0

            c.fill(path.circle(x0, y0, 0.1))

            if i == len(ns) - 1:
                continue

            n1 = ns[i + 1]
            for j1 in range(n1):
                y1 = j1 * h - h * (n1 - 1) / 2.0

                alpha = 0.95
                x11 = (1 - alpha) * x0 + alpha * x1
                y11 = (1 - alpha) * y0 + alpha * y1
                c.stroke(path.line(x0, y0, x11, y11), [deco.earrow()])

                alpha = 0.25
                x = (1 - alpha) * x0 + alpha * x1
                y = (1 - alpha) * y0 + alpha * y1
                # weight = randint(0, 4)
                # weights[i, j0, j1] = weight

                R = 0.17
                c.fill(path.circle(x, y, R), [white])
                c.stroke(path.circle(x, y, R))
                c.text(x, y, "$%d$" % weights[i, j0, j1], center)

    for i in range(len(ns)):

        n = ns[i]
コード例 #27
0
ファイル: render.py プロジェクト: punkdit/morse2019
def arrow(x0, y0, x1, y1, a=0.8, extra=[]):
    x2, y2 = conv(x0, y0, x1, y1, a)
    cvs.stroke(path.line(x0, y0, x2, y2), [deco.earrow()] + extra)
    if a < 1.0:
        cvs.stroke(path.line(x0, y0, x1, y1), extra)
コード例 #28
0
ファイル: trellis.py プロジェクト: punkdit/surface2015
def arrow(x0, y0, x1, y1):
    x00, y00 = conv(0.1, (x0, y0), (x1, y1))
    x11, y11 = conv(0.85, (x0, y0), (x1, y1))
    c.stroke(path.line(x00, y00, x11, y11), [deco.earrow()])
コード例 #29
0
ファイル: drawer.py プロジェクト: AntipovDen/XdivK
def draw_plot():
    c = canvas.canvas()
    #axis
    c.stroke(path.line(0, 0, 12, 0), [deco.earrow(size=0.5)])
    c.stroke(path.line(0, 0, 0, 6), [deco.earrow(size=0.5)])
    #dashed lines
    c.stroke(path.line(0, 5, 10, 5),
             [style.linestyle.dashed, style.linewidth.thin])
    c.stroke(path.line(10, 0, 10, 5),
             [style.linestyle.dashed, style.linewidth.thin])
    # c.stroke(path.line(0, 0, 20, 10), [style.linestyle.dashed])

    c.stroke(path.line(0, 3.75, 7.5, 3.75),
             [style.linestyle.dashed, style.linewidth.thin])
    c.stroke(path.line(7.5, 0, 7.5, 3.75),
             [style.linestyle.dashed, style.linewidth.thin])

    #plot
    c.stroke(path.line(0, 0, 7.5, 3.75), [style.linewidth.THICK])
    c.stroke(path.line(7.5, 3.75, 10, 3.75), [style.linewidth.THICK])
    c.stroke(path.circle(10, 5, 0.18))
    c.fill(path.circle(10, 5, 0.18), [color.rgb.black])
    c.stroke(path.circle(10, 3.75, 0.18))
    c.fill(path.circle(10, 3.75, 0.18), [color.rgb.white])

    #text
    c.text(-0.2, 6, r"Plateau$(x)$",
           [text.halign.boxright, text.valign.top, text.size.Huge])
    c.text(13, -0.2, r"OneMax$(x)$",
           [text.halign.boxcenter, text.valign.top, text.size.Huge])

    c.text(0, 5, r"$n$",
           [text.halign.boxright, text.valign.top, text.size.Huge])
    c.text(0, 3.75, r"$n - k$",
           [text.halign.boxright, text.valign.middle, text.size.Huge])

    c.text(0, 0, r"$0$",
           [text.halign.boxright, text.valign.top, text.size.Huge])

    c.text(7.5, -0.2, r"$n - k$",
           [text.halign.boxcenter, text.valign.top, text.size.Huge])
    c.text(10, -0.2, r"$n$",
           [text.halign.boxcenter, text.valign.top, text.size.Huge])

    c.writePDFfile("plateau.pdf")

    c = canvas.canvas()

    c.stroke(path.circle(0, 0, 0.18))
    c.fill(path.circle(0, 0, 0.18), [color.rgb.black])
    c.text(0.18, 0, r"Opt",
           [text.halign.boxleft, text.valign.middle, text.size.Huge])

    n_level = 20
    for i in range(n_level):
        if i not in range(8, 13):
            c.stroke(
                path.circle(2 * sin(i * pi * 2 / n_level),
                            2 * cos(i * pi * 2 / n_level), 0.18))
    c.text(0, -2, r"Level $(k - 1)$",
           [text.halign.boxcenter, text.valign.bottom, text.size.LARGE])

    n_level = 40
    for i in range(n_level):
        if i not in range(18, 23):
            c.stroke(
                path.circle(4 * sin(i * pi * 2 / n_level),
                            4 * cos(i * pi * 2 / n_level), 0.18))
    c.text(0, -4, r"Level $(k - 2)$",
           [text.halign.boxcenter, text.valign.bottom, text.size.LARGE])

    c.stroke(path.circle(0, 0, 5),
             [style.linestyle.dotted, style.linewidth.thick])

    n_level = 60
    for i in range(n_level):
        if i not in range(29, 32):
            c.stroke(
                path.circle(6 * sin(i * pi * 2 / n_level),
                            6 * cos(i * pi * 2 / n_level), 0.18))
    c.text(0, -6, r"Level $0$",
           [text.halign.boxcenter, text.valign.bottom, text.size.LARGE])
    c.writePDFfile("individuals_chain.pdf")
コード例 #30
0
ファイル: modular.py プロジェクト: punkdit/fibonacci
brown = rgbfromhexstring("#AA6C39"),

light_shade = rgb(0.85, 0.65, 0.1)

#shade = brown
#shade = orange
shade = grey



st_curve = g_curve = [green, style.linewidth.THick]

st_tau = [style.linewidth.Thick, red, style.linecap.round]
#st_vac = [style.linewidth.thick, red]+st_dotted

st_arrow = [deco.earrow()]



def anyon(x, y, r=0.07):
    c.fill(path.circle(x, y, r), [white])
    c.stroke(path.circle(x, y, r), [red, style.linewidth.thick])


N = 20

def dopath(ps, extra=[], fill=[], closepath=True, smooth=0.3):
    ps = [path.moveto(*ps[0])]+[path.lineto(*p) for p in ps[1:]]
    if closepath:
        ps.append(path.closepath())
    p = path.path(*ps)
コード例 #31
0
ファイル: tmp.py プロジェクト: AntipovDen/Matan
text.set(text.LatexRunner)
c = canvas.canvas()

c.stroke(path.circle(0, 0, 1))
c.stroke(path.circle(5, 0, 1))
c.stroke(path.circle(15, 0, 1))
c.stroke(path.circle(20, 5, 1))

c.stroke(path.circle(9, 0, 0.1), [style.linewidth.THICK])
c.stroke(path.circle(10, 0, 0.1), [style.linewidth.THICK])
c.stroke(path.circle(11, 0, 0.1), [style.linewidth.THICK])

c.text(0, 0, r'\Huge{1}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(5, 0, r'\Huge{2}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(15, 0, r'\Huge{K}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(20, 5, r'\Huge{0}', [text.parbox(0), text.valign.middle, text.halign.center])

c.stroke(path.curve(1 / sqrt(2), 1 / sqrt(2), 2, 2, 3, 2,  5 - 1 / sqrt(2), 1 / sqrt(2)), [deco.earrow(size=1)])
c.stroke(path.curve(5 - 1 / sqrt(2), -1 / sqrt(2), 3, -2, 2, -2,  1 / sqrt(2), -1 / sqrt(2)), [deco.earrow(size=1)])
c.stroke(path.curve(1 / sqrt(2), 1 / sqrt(2), 1, 5, 10, 5,  19, 5), [deco.earrow(size=1)])
c.stroke(path.curve(5 + 1 / sqrt(2), 1 / sqrt(2), 7, 5, 12, 5,  19, 5), [deco.earrow(size=1)])
c.stroke(path.line(15 + 1 / sqrt(2), 1 / sqrt(2), 20 - 1 / sqrt(2), 5 - 1 / sqrt(2)), [deco.earrow(size=1)])


c.text(2.5, 2.5, r'\huge{$p_1^2$}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(2.5, -1, r'\huge{$p_2^1$}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(2.5, 4, r'\huge{$p_1^0$}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(8, 3, r'\huge{$p_2^0$}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(18, 2, r'\huge{$p_K^0$}', [text.parbox(0), text.valign.middle, text.halign.center])
c.writePDFfile("states.pdf")
コード例 #32
0
ファイル: drawer.py プロジェクト: AntipovDen/XdivK
def draw_level_chain():
    c = canvas.canvas()

    # levels circles
    # for r in 3, 8, 11:
    #     circle = path.circle(11, 0, r)
    #     intersect = (circle.intersect(path.line(0, 2.6, 11, 2.6))[0][0], circle.intersect(path.line(0, -2.2, 11, -2.1))[0][0])
    #     arc = circle.split(intersect)[1]
    #     c.stroke(arc, [style.linestyle.dashed, style.linewidth.thin])

    #states
    c.stroke(path.circle(0, 0, 0.4))
    c.stroke(path.circle(3, 0, 0.4))
    c.stroke(path.circle(8, 0, 0.4))
    c.stroke(path.circle(11, 0, 0.4))
    c.fill(path.circle(0, 0, 0.4), [color.rgb.white])
    c.fill(path.circle(3, 0, 0.4), [color.rgb.white])
    c.fill(path.circle(8, 0, 0.4), [color.rgb.white])
    c.fill(path.circle(11, 0, 0.4), [color.rgb.black])
    c.text(0, 0, r"0",
           [text.halign.boxcenter, text.valign.middle, text.size.huge])
    c.text(3, 0, r"1",
           [text.halign.boxcenter, text.valign.middle, text.size.huge])
    c.text(8, 0, r"$k - 1$",
           [text.size.small, text.halign.boxcenter, text.valign.middle])

    #dots
    c.fill(path.circle(6, 0, 0.1), [color.rgb.black])
    c.fill(path.circle(5, 0, 0.1), [color.rgb.black])
    c.fill(path.circle(5.5, 0, 0.1), [color.rgb.black])

    #transitions
    c.stroke(path.line(sqrt(0.15), 0.1, 3 - sqrt(0.15), 0.1), [deco.earrow()])
    c.text(1.5, 0.1, r"$p_0^1$", [text.halign.boxcenter, text.valign.bottom])
    c.stroke(path.line(3 - sqrt(0.15), -0.1, sqrt(0.15), -0.1),
             [deco.earrow()])
    c.text(1.5, -0.1, r"$p_1^0$", [text.halign.boxcenter, text.valign.top])
    c.stroke(
        path.curve(3 + sqrt(0.15), 0.1, 5, 0.4, 6, 0.4, 8 - sqrt(0.15), 0.1),
        [deco.arrow()])
    c.text(5.5, 0.4, r"$p_1^{k - 1}$",
           [text.halign.boxcenter, text.valign.bottom])
    c.stroke(
        path.curve(8 - sqrt(0.15), -0.1, 6, -0.4, 5, -0.4, 3 + sqrt(0.15),
                   -0.1), [deco.arrow()])
    c.text(5.5, -0.4, r"$p_{k - 1}^1$",
           [text.halign.boxcenter, text.valign.top])
    c.stroke(path.line(8.4, 0, 10.6, 0), [deco.earrow()])
    c.text(9.5, 0, r"$p_{k - 1}^k$",
           [text.halign.boxcenter, text.valign.bottom])
    c.stroke(path.curve(0, 0.4, 3, 2.7, 8, 2.7, 11, 0.4), [deco.arrow()])
    c.text(5.5, 2.2, r"$p_0^k$", [text.halign.boxcenter, text.valign.bottom])
    c.stroke(path.curve(sqrt(0.07), 0.3, 3, 2, 5, 2, 8 - sqrt(0.07), 0.3),
             [deco.arrow()])
    c.text(4.5, 1.6, r"$p_0^{k - 1}$",
           [text.halign.boxcenter, text.valign.bottom])
    c.stroke(path.curve(8 - sqrt(0.12), 0.2, 5, 1.9, 3, 1.9, sqrt(0.12), 0.2),
             [deco.arrow()])
    c.text(4.5, 1.4, r"$p_{k - 1}^0$",
           [text.halign.boxcenter, text.valign.top])
    c.stroke(
        path.curve(3 + sqrt(0.07), -0.3, 6, -2, 9, -2, 11 - sqrt(0.07), -0.3),
        [deco.arrow()])
    c.text(7, -1.7, r"$p_1^k$", [text.halign.boxcenter, text.valign.top])
    c.stroke(
        path.curve(-sqrt(0.07), -0.3, -0.3, -1, 0.3, -1, sqrt(0.07), -0.3),
        [deco.earrow])
    c.text(0, -1, r"$p_0^0$", [text.halign.boxcenter, text.valign.top])
    c.stroke(
        path.curve(3 - sqrt(0.07), -0.3, 3 - 0.3, -1, 3.3, -1, 3 + sqrt(0.07),
                   -0.3), [deco.earrow])
    c.text(3, -1, r"$p_1^1$", [text.halign.boxcenter, text.valign.top])
    c.stroke(
        path.curve(8 - sqrt(0.07), -0.3, 8 - 0.3, -1, 8.3, -1, 8 + sqrt(0.07),
                   -0.3), [deco.earrow])
    c.text(8, -1, r"$p_{k - 1}^{k - 1}$",
           [text.halign.boxcenter, text.valign.top])

    c.writePDFfile("levels_chain.pdf")
コード例 #33
0
ファイル: poster.py プロジェクト: punkdit/fibonacci
def arrow(x0, y0, x1, y1, extra=[]):
    c.stroke(path.line(x0, y0, x1, y1),
        extra+[deco.earrow(size=0.2)])
コード例 #34
0
ファイル: pentagon.py プロジェクト: punkdit/fibonacci
brown = rgbfromhexstring("#AA6C39"),

light_shade = rgb(0.85, 0.65, 0.1)

#shade = brown
#shade = orange
shade = grey



st_curve = g_curve = [green, style.linewidth.THick]

st_tau = [style.linewidth.Thick, red, style.linecap.round]
#st_vac = [style.linewidth.thick, red]+st_dotted

st_arrow = [deco.earrow()]



def anyon(x, y, r=0.07):
    c.fill(path.circle(x, y, r), [white])
    c.stroke(path.circle(x, y, r), [red, style.linewidth.thick])


c = canvas.canvas()


R = 2.4
r = 1.0
r1 = 0.10
r2 = 0.4