Skip to content

origami_simulator

pleat.origami_simulator

Open a crease pattern in Origami Simulator (https://origamisimulator.org/).

Origami Simulator imports a crease pattern via a postMessage handshake: it announces {from:'OrigamiSimulator', status:'ready'} to its parent frame (when embedded) or opener (when popped out), then accepts {op:'importFold', fold:<FOLD object>}. We embed the pattern as FOLD JSON in a self-contained page and reply to whichever OS window reports ready.

Two entry points:

  • :func:origami_simulator -- show OS folding a pattern: inline in the cell under Jupyter (Notebook / Lab / VS Code), or in the system browser from a script.
  • :func:origami_simulator_button -- a button that embeds OS inline when clicked (lazy; good for the static docs, where auto-loading many at once would be heavy).

origami_simulator

origami_simulator(
    G, *, height: int = 600, new_tab: bool = False
) -> None

Show Origami Simulator folding the crease pattern G.

In a Jupyter environment (Notebook, Lab, VS Code) this embeds OS inline in the cell output (resizable via height); it can be called off any line and several times in one cell. From a plain script it opens OS in the system browser.

Pass new_tab=True to force the browser even from a notebook - useful in VS Code, where the inline Fullscreen button is blocked by the webview.

Source code in pleat/origami_simulator.py
def origami_simulator(G, *, height: int = 600, new_tab: bool = False) -> None:
    """Show Origami Simulator folding the crease pattern *G*.

    In a Jupyter environment (Notebook, Lab, VS Code) this embeds OS inline in the
    cell output (resizable via *height*); it can be called off any line and several
    times in one cell. From a plain script it opens OS in the system browser.

    Pass ``new_tab=True`` to force the browser even from a notebook - useful in VS
    Code, where the inline Fullscreen button is blocked by the webview.
    """
    if new_tab or not in_notebook():
        _open_in_browser(G)
    else:
        _display_html(_iframe_html(G, height=height))

origami_simulator_button

origami_simulator_button(
    G,
    *,
    height: int = 600,
    title: str = "Load Origami Simulator"
) -> None

Display a button that embeds Origami Simulator inline when clicked.

Like :func:origami_simulator but lazy -- nothing loads until the reader clicks, so a page with many patterns does not spin up a WebGL instance for each on load. title sets the button label.

Source code in pleat/origami_simulator.py
def origami_simulator_button(G, *, height: int = 600, title: str = "Load Origami Simulator") -> None:
    """Display a button that embeds Origami Simulator inline when clicked.

    Like :func:`origami_simulator` but lazy -- nothing loads until the reader
    clicks, so a page with many patterns does not spin up a WebGL instance for each
    on load. *title* sets the button label.
    """
    _display_html(_button_html(G, height=height, title=title))