示例#1
0
def test_arrows(): # XXX move to doc

    from huygens import config
    config(text="pdftex")

    Box.DEBUG = False

    tbox = lambda t: MarginBox(TextBox(t), 0.05)
    rows = [
        [r"A", r"B", r"C"],
        [r"D", r"E", r"F"],
        [r"G", r"H", r"I"],
    ]
    boxs = [[tbox("$%s$"%c) for c in row] for row in rows]

    arrows = []
    for di in [-1, 0, 1]:
      for dj in [-1, 0, 1]:
        if di==0 and dj==0:
            continue
        label = r"$x$"
        a = ArrowBox(boxs[1][1], boxs[1+di][1+dj], label=label)
        arrows.append(a)

    r = 1.1
    table = TableBox(boxs, hspace=r, vspace=0.8*r)
    box = MasterBox(table, arrows)

    cvs = canvas.canvas()
    box.render(cvs)

    cvs.writePDFfile("output.pdf")
示例#2
0
def test_snake():

    # Composing diagrams and box's
    # -----------------------------
    #
    # The base class for a diagram is `Dia`. Diagrams are
    # also `Box`'s so we can stick them anywhere we can use a `Box`.

    from huygens import config, canvas
    from huygens.box import Box, HBox
    from huygens.diagram import HDia, VDia, VWire, Cap, Cup, SIZE
    Box.DEBUG = False

    config(text="pdftex")

    top = HDia([VWire(), Cap()])
    #mid = HDia([VWire(), VWire(), VWire()])
    bot = HDia([Cup(), VWire()])
    lsnake = VDia([top, bot])

    top = HDia([Cap(), VWire()])
    bot = HDia([VWire(), Cup()])
    rsnake = VDia([top, bot])

    boxs = [lsnake, "$=$", VWire(min_height=SIZE), "$=$", rsnake]
    dia = HBox(boxs, align="center")

    yield dia

    # If we do this again with DEBUG you can see how
    # the underlying `Box`s are put together.

    Box.DEBUG = True

    # Currently, the anchor inside each `Dia` is not constrained and
    # so is free to wander around inside the `Box`.
    # Maybe this will change in the future.

    yield dia

    # If we use a `StrictHBox` it will stretch the `VWire()`
    # but then we need to put the text in a `SlackBox`.

    from huygens.box import SlackBox, StrictHBox
    boxs = [lsnake, SlackBox("$=$"), VWire(), SlackBox("$=$"), rsnake]
    dia = StrictHBox(boxs, align="center")

    yield dia, "hbox-slack-dia"
示例#3
0
def test():
    from huygens import config
    config("pdftex")

    #Box.DEBUG=True

    st_dashed = [style.linestyle.dashed]
    st_arrow = [deco.marrow()]
    st_rarrow = [deco.marrow(reverse=True)]

    #box = Spider(1, 2)

    box = TBone(1, 2, connect=[0, 0], weight=0.5)
    box = box * (VWire() @ Spider(1, 2))
    box = box * (Spider(2, 1) @ VWire())

    cvs = canvas.canvas()
    box.render(cvs)
    cvs.writePDFfile("output.pdf")
示例#4
0
文件: disc.py 项目: punkdit/bruhat
    disc.show_tiles(G)

    p = path.circle(0, 0, 1)
    cvs.clip(p)
    cvs.stroke(p, [1.0 * thin])

    #save("hyperbolic-55")
    #save("fold-hyperbolic-55")
    save("brings-curve")

    print("OK")
    print()

    # -------------------------------------------------------------


if __name__ == "__main__":
    from huygens import config
    config(text="pdflatex",
           latex_header=r"""
    \usepackage{amsmath}
    \usepackage{amssymb}
    """)

    from bruhat.argv import argv
    name = argv.next() or "main"
    fn = eval(name)
    fn()

    print("OK\n")
示例#5
0
        conf = cls.stack[-1]
        vflow = conf.vflow if vflow is None else vflow
        return vflow

    @classmethod
    def restore(cls):
        assert cls.stack, "empty stack!"
        conf = cls.stack.pop()

    #def __del__(self):
    #    self.restore()


#config = Config.config
config = Config
config(hflow="right", vflow="down", size=1.0)
restore = Config.restore
get_size = Config.get_size
get_hflow = Config.get_hflow
get_vflow = Config.get_vflow


conv = lambda x0, x1, t=0.5: (1.-t)*x0 + t*x1


class Dia(Base): # Mixin
    def __init__(self, n_top=0, n_bot=0, n_left=0, n_right=0, 
        min_width=None, min_height=None):
        self.n_top = n_top
        self.n_bot = n_bot
        self.n_left = n_left
示例#6
0
文件: lie.py 项目: punkdit/bruhat
    2, (-2, 0): 3, (-4, -1): 2, (4, 3): 2, (-1, 2): 3, (-3,
    1): 2, (3, 4): 2, (-2, 3): 2, (2, 5): 2, (1, 6): 2, (0,
    7): 1, (4, 0): 3, (2, -1): 3, (0, -2): 3, (-2, -3): 3,
    (-6, -5): 2, (6, 1): 2, (7, 3): 1, (6, 4): 1, (5, 5):
    1, (4, 6): 1, (3, 7): 1, (2, 8): 1, (8, 2): 1, (-7, -4):
    1, (-6, -2): 1, (-5, 0): 1, (-4, 2): 1, (-3, 4): 1, (-2,
    6): 1, (-8, -6): 1}

    weights = dict((k, str(v)) for (k,v) in weights.items())
    diagram = WeightDiagram.make_A2(weights)
    diagram.plot("sl3_weights_62")


try:
    from huygens import config
    config(text="pdflatex")
    from huygens.front import Canvas, path, color, text, style
except ImportError:
    pass

class WeightDiagram(object):
    def __init__(self, basis, weights):
        self.basis = basis
        self.weights = dict(weights)
        pts = []
        for (i,j) in weights.keys():
            x, y = self.coord(i, j)
            pts.append((x, y))
        self.pts = pts
        if len(pts)>=3:
            self.hull = ConvexHull(pts)