コード例 #1
0
ファイル: refactoring.py プロジェクト: punkdit/fibonacci
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)
    if fill:
        c.fill(p, [deformer.smoothed(smooth)]+extra+fill)
    c.stroke(p, [deformer.smoothed(smooth)]+extra)
コード例 #2
0
ファイル: decode.py プロジェクト: punkdit/fibonacci
def dopath(ps, extra=[], fill=False, closepath=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(0.3)]+extra+[color.rgb.white])
    c.stroke(p, [deformer.smoothed(0.3)]+extra)
コード例 #3
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
def braid(n, i, t, inverse=False):

    if not isinstance(t, list):
        t = [t]

    t = t + [style.linewidth.Thick, red, style.linecap.round]

    N = 10

    if i is None:
        items = range(n)
    else:
        assert 0<=i<i+1<n
        items = range(i)+range(i+2, n)
    
    for k in items:
        c.stroke(path.line(0.5*k, 0., 0.5*k, 1.), t)

    if i is None:
        return

    pts0 = []
    for j in range(N):
        theta = pi*j/(N-1)
        x = 0.5 * 0.5 * (cos(theta)-1.) + 0.5*(i+1)
        y = 1.*j/(N-1)
        pts0.append((x, y))

    pts1 = []
    for j in range(N):
        theta = pi*j/(N-1)
        x = 0.5 * 0.5 * (1.-cos(theta)) + 0.5*i
        y = 1.*j/(N-1)
        pts1.append((x, y))

    if inverse:
        pts0, pts1 = pts1, pts0

    pts = [path.moveto(*pts0[0])] + [path.lineto(*p) for p in pts0[1:]]
    wiggle = path.path(*pts)
    c.stroke(wiggle, [deformer.smoothed(2.0)]+t)

    c.fill(path.circle(0.5*(i+0.5), 0.5, 0.15), t+[white])

    pts = [path.moveto(*pts1[0])] + [path.lineto(*p) for p in pts1[1:]]
    wiggle = path.path(*pts)
    c.stroke(wiggle, [deformer.smoothed(2.0)]+t)
コード例 #4
0
def repo(label, colorfg, colorbg):
    crepo = canvas.canvas()
    labeltext = text.text(0, 0, r'\textsf{{{}}}'.format(label),
                          [colorfg])
    extrawd = 0.15
    labelbox = labeltext.bbox().enlarged(extrawd)
    crepo.fill(labelbox.path(), [colorbg, deformer.smoothed(0.05),
                                  deco.stroked([colorfg])])
    crepo.insert(labeltext)
    return crepo
コード例 #5
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])
コード例 #6
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()])
コード例 #7
0
ファイル: braid.py プロジェクト: punkdit/surface2015
def dopath(ps, extra=[], fill=[], closepath=False, smooth=0.0):
    if not ps:
        print "dopath: empty"
        return
    ps = [path.moveto(*ps[0])]+[path.lineto(*p) for p in ps[1:]]
    if closepath:
        ps.append(path.closepath())
    p = path.path(*ps)
    extra = list(extra)
    if smooth:
        extra.append(deformer.smoothed(smooth))
    if fill:
        c.fill(p, extra+fill)
    c.stroke(p, extra)
コード例 #8
0
def file(c, size=1, xoff=0, yoff=0, attrs=[], title=''):
    w = 3
    h = 2.1
    fold = 0.6
    outline = path.path(path.moveto(0, 0), path.lineto(w, 0),
                        path.lineto(w, h - fold), path.lineto(w - fold, h),
                        path.lineto(0, h), path.closepath())
    foldpath = path.path(path.moveto(w - fold, h),
                         path.lineto(w - fold, h - fold),
                         path.lineto(w, h - fold))
    c1 = canvas.canvas()
    c1.stroke(outline, attrs)
    d = deformer.smoothed(0.2)
    c1.stroke(d.deform(foldpath), attrs)
    c1.stroke(path.rect(0.1 * w, 0.3 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.45 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.6 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.75 * h, 0.6 * w, 0.1 * h))
    c1.text(0.1, 0.1, r'\sffamily ' + title, [trafo.scale(0.7)])
    myattrs = [trafo.translate(xoff, yoff), trafo.scale(size)]
    myattrs.extend(attrs)
    c.insert(c1, myattrs)
コード例 #9
0
ファイル: trajectory_utils.py プロジェクト: cebeery/robo2
    def makePath(self):
        ''' makes pyx path object from pygame points '''
        # so we can use pop() w/o modifying self.positions
        positions = copy.copy(self.points)
        positions.reverse()

        p = None

        # BEZIER CURVES
        while len(positions) > 4: # need at least 4 points to make bezier curve
            # make a bezier curve
            points = []
            for _ in range(3):
                points += positions.pop()
            points += positions[-1] # so next curve will start at this point

            if p:
                p += path.curve(*points)
            else:
                p = path.curve(*points)


        # LINES
        while len(positions) > 1: # use up rest of points with lines
            points = []
            points += positions.pop()
            points += positions[-1]

            if p:
                p += path.line(*points)
            else:
                p = path.line(*points)


        # store curve in object
        p = deformer.smoothed(2.0).deform(p) # smooth curve
        self.path = p
        self.arclen = p.arclen_pt()*metersPerPoint
        self.duration = self.arclen/self.velocity
コード例 #10
0
    def makePath(self):
        ''' makes pyx path object from pygame points '''
        # so we can use pop() w/o modifying self.positions
        positions = copy.copy(self.points)
        positions.reverse()

        p = None

        # BEZIER CURVES
        while len(
                positions) > 4:  # need at least 4 points to make bezier curve
            # make a bezier curve
            points = []
            for _ in range(3):
                points += positions.pop()
            points += positions[-1]  # so next curve will start at this point

            if p:
                p += path.curve(*points)
            else:
                p = path.curve(*points)

        # LINES
        while len(positions) > 1:  # use up rest of points with lines
            points = []
            points += positions.pop()
            points += positions[-1]

            if p:
                p += path.line(*points)
            else:
                p = path.line(*points)

        # store curve in object
        p = deformer.smoothed(2.0).deform(p)  # smooth curve
        self.path = p
        self.arclen = p.arclen_pt() * metersPerPoint
        self.duration = self.arclen / self.velocity
コード例 #11
0
ファイル: render.py プロジェクト: punkdit/fibonacci
#c.text(x0-0.8, y0, "(b)")
push()

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


p = path.path(
    path.moveto(x0+0.5*w, y0-0.3*h), 
    path.lineto(x0+0.5*w, y0+0.3*h), 
    path.lineto(x0+1.5*w+m, y0+0.3*h),
    path.lineto(x0+1.5*w+m, y0+0.7*h), 
    path.lineto(x0+0.5*w, y0+0.7*h),
    path.lineto(x0+0.5*w, y0+1.3*h),
)
c.stroke(p, [deformer.smoothed(0.3)]+grarrow)

y = y0+0.3*h
anyon(x0+0.8*w, y)
anyon(x0+m+1.2*w, y)
    
y = y0+0.7*h
anyon(x0+0.8*w, y)
anyon(x0+m+1.2*w, y)

pop([trafo.rotate(-90), trafo.translate(2.*w+0.7, 2.5*h)])
c.text(2.*w, 0.5*h, "(b)")


# --------------------------------------------------------------------
コード例 #12
0
ht = 5
htlabel = 1
wd = 3.5
vdist = 0.05
hdist = 1
size = 1.2

for nr, (label, boxcolor, symbolcolor, status) in enumerate(
    (('working directory', color.hsb(0.87, 1, 0.6), color.rgb(0.6, 0,
                                                              0), 'modified'),
     ('staging area', color.hsb(0.2, 1, 0.6), color.rgb(0, 0.5, 0), 'staged'),
     ('repository (.git)', color.hsb(0.53, 1,
                                     0.6), color.grey(0.3), 'committed'))):
    xmid = nr * (wd + hdist) + 0.5 * wd
    c.stroke(path.rect(nr * (wd + hdist), 0, wd, ht),
             [deformer.smoothed(0.3), boxcolor, style.linewidth.Thick])
    c.fill(path.rect(nr * (wd + hdist), ht + vdist, wd, htlabel),
           [deformer.smoothed(0.3), boxcolor])
    c.text(xmid, ht + vdist + 0.5 * htlabel, label,
           [text.halign.center, text.valign.middle,
            color.grey(1)])
    c.insert(filesymbol(size, symbolcolor), [trafo.translate(xmid, 0.5 * ht)])
    c.text(xmid, 0.2 * ht, status, [text.halign.center, symbolcolor])
for nr, operation in enumerate(('git add', 'git commit')):
    xmid = nr * (wd + hdist) + 0.5 * wd
    c.stroke(
        path.line(xmid + 0.5 * size + 0.1, 0.5 * ht,
                  xmid + wd + hdist - 0.5 * size - 0.1, 0.5 * ht),
        [deco.earrow.large, style.linewidth.Thick])
    cop = canvas.canvas()
    optext = text.text(0, 0, operation,
コード例 #13
0
    cf.text(0, -nr*dy, name, [color.hsb(hue, 1, 0.5), text.valign.middle])
    for nver, (v1, v2) in enumerate(zip(versions[:-1], versions[1:])):
        y = -(nr+0.4)*dy
        lv = len(versions)-1
        xll = v1*dx+versionoff+0.1
        yll = y
        width = (v2-v1)*dx-0.2
        height = 0.8*dy
        cf.fill(path.rect(xll, yll, width, height),
                [color.hsb(hue, 1-(lv-1-nver)/(lv-1)*0.7, 0.6)])
        cf.text(xll+0.5*width, yll+0.5*height, gethashstring(),
                [text.size(-4), text.halign.center, text.valign.middle, color.grey(1)])
for n in range(nr_revisions):
    xcenter = (n+0.5)*dx+versionoff
    y = 0.5
    cf.text(xcenter, y, gethashstring(), [text.size(-4), text.halign.center])
    if n:
        yshift = 0.1
        cf.stroke(path.line(xcenter-0.33*dx, y+yshift, xcenter-0.67*dx, y+yshift),
                  [deco.earrow])
cf.stroke(path.rect(3*dx+versionoff, -2.6*dy, dx, 2.6*dy+1.0),
              [style.linewidth.THIck, deformer.smoothed(0.3)])
    
c.insert(cf, [trafo.translate(4.5, 1)])

c.writePDFfile()




コード例 #14
0
            trafo.scale(size).rotated(-30).translated(0, -0.4 * size)])
    return cwrite


text.set(text.LatexRunner)
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
c = canvas.canvas()

wd = 6.9
ht = 3.5
gitlabfgcolor = color.grey(0.4)
gitlabbgcolor = color.grey(0.97)
maintainercolor = color.hsb(0.7, 1, 0.5)
usercolor = color.hsb(0.05, 1, 0.5)
c.stroke(path.rect(0, 0, wd, ht), [
    deformer.smoothed(0.1), gitlabfgcolor, style.linewidth.Thick,
    deco.filled([gitlabbgcolor])
])

clabel = canvas.canvas()
labeltext = text.text(0, 0, r'\textsf{\bfseries Gitlab}', [color.grey(1)])
extrawd = 0.15
labelbox = labeltext.bbox().enlarged(extrawd)
clabel.fill(labelbox.path(), [gitlabfgcolor, deformer.smoothed(0.1)])
clabel.insert(labeltext)
c.insert(clabel, [trafo.translate(extrawd, ht + extrawd)])

c.text(wd + 0.4, ht - 0.5, r'\footnotesize\textsf{read/write permissions}')
c.insert(read(1, usercolor), [trafo.translate(wd + 0.7, ht - 0.9)])
c.insert(write(1, usercolor), [trafo.translate(wd + 1.05, ht - 0.9)])
c.text(wd + 1.5, ht - 1.0, r'\footnotesize\textsf{user}', [usercolor])
コード例 #15
0
    cwrite.stroke(p, [color, trafo.scale(size).rotated(-30).translated(0,-0.4*size)])
    return cwrite

basename = os.path.splitext(sys.argv[0])[0]

text.set(text.LatexRunner)
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
c = canvas.canvas()

wd = 6.9
ht = 3.5
githubfgcolor = color.grey(0.4)
githubbgcolor = color.grey(0.97)
maintainercolor = color.hsb(0.7, 1, 0.5)
usercolor = color.hsb(0.05, 1, 0.5)
c.stroke(path.rect(0, 0, wd, ht), [deformer.smoothed(0.1),
                                   githubfgcolor,
                                   style.linewidth.Thick,
                                   deco.filled([githubbgcolor])])

clabel = canvas.canvas()
labeltext = text.text(0, 0, r'\textsf{\bfseries Github}', [color.grey(1)])
extrawd = 0.15
labelbox = labeltext.bbox().enlarged(extrawd)
clabel.fill(labelbox.path(), [githubfgcolor, deformer.smoothed(0.1)])
clabel.insert(labeltext)
c.insert(clabel, [trafo.translate(extrawd, ht+extrawd)])

c.text(wd+0.4, ht-0.5, r'\footnotesize\textsf{read/write permissions}')
c.insert(read(1, usercolor), [trafo.translate(wd+0.7, ht-0.9)])
c.insert(write(1, usercolor), [trafo.translate(wd+1.05, ht-0.9)])
コード例 #16
0
from pyx import canvas, color, deco, deformer, graph, path, style, trafo


def ellipse(r, scaley, fillcolor):
    ce = canvas.canvas()
    ce.fill(path.circle(0, 0, r), [trafo.scale(1, scaley), fillcolor])
    return ce


c = canvas.canvas()
dx = 0.3
h = 4
w = 6.5
p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx)
p = deformer.smoothed(0.5).deform(p)
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)])
コード例 #17
0
ファイル: braid.py プロジェクト: punkdit/thesis2015
def dorect(x, y, W=2, H=0.6):
    dopath([(x-1.1, y-H), (x-0.1, y+H), (x+W+.2, y+H), (x+W-0.8, y-H)],
        fill=[shade, color.transparency(0.3)],
        closepath=True)


x, y = 0., 0.
radius = 0.06 

dorect(x, y)

c.fill(path.circle(x, y, radius), [style.linewidth.thick])
c.fill(path.circle(x+1, y, radius), [style.linewidth.thick])
c.stroke(mkpath(x, y, 3),
    [deformer.smoothed(2.0),
    style.linewidth.Thick, deco.earrow(size=0.2)])

x += 3 

c.text(x-0.1, y-0.1, r"$\ne$")

x += 2 

dorect(x, y)

c.fill(path.circle(x, y, radius), [style.linewidth.thick])
c.fill(path.circle(x+1, y, radius), [style.linewidth.thick])
c.stroke(mkpath(x, y, 1.4),
    [deformer.smoothed(2.0),
    style.linewidth.Thick, deco.earrow(size=0.2)])
コード例 #18
0
ファイル: poster.py プロジェクト: punkdit/fibonacci
points.insert(idx, (1.5*dx, -2.*dy)); idx+=1
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
コード例 #19
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
        u += 0.1 * 2**(-5*r)
    u, v = w*u+x, h*v+y
    return u, v

def warp(u, v):
    u = (u-x)/w
    v = (v-y)/h
    assert 0<=u<=1., u
    assert 0<=v<=1., v
    u, v = twist(u, v, 1.2*pi, 0.0, 0.48, x0=0.5, y0=0.5)
    u, v = w*u+x, h*v+y
    return u, v



sm = [deformer.smoothed(2.0)]

c.fill(path.rect(x-m0, y-m0, 2*m0+w, 2*m0+h), [shade])
c.stroke(path.rect(x, y, w, h))
r = 0.3*w

ps = [ path.moveto(x+r, y-m), path.lineto(x+r, y)]
#path.arc(x, y, r, 0, 90),
for i in range(N):
    theta = 0.5*pi*i/(N-1)
    u = x+r*cos(theta)
    v = y+1.3*r*sin(theta)
    u, v = warp(u, v)
    ps.append(path.lineto(u, v))
ps.append(path.lineto(x-m, y+1.3*r))
p = path.path(*ps)