Is it possible to show ti.gui in Jupiter notebook?

Hi there! Just as the title says, I’d love to write and demonstrate the simulation result of taichi in Jupiter notebook, which means showing the content of ti.gui in Jupiter notebook. Is there a way to achieve this? Thx!

For the traditional ti.GUI usage, it will show up a window on the server side instead of transmit it to client (not a problem if you’re playing Jupyter on localhost).
If you’d like to visualize the GUI from remote, consider use the wrapped animation class in taichi_glsl:

import os
os.environ['TI_GUI_BACKEND'] = 'ipython'  # set this environment variable when used in Jupyter
# or you may put it in the bottom of

import taichi as ti
import taichi_glsl as ts


class MyAnimation(ts.Animation):
    def on_init(self):
        self.img = ti.Vector.field(3, ti.f32, (512, 512))
        self.define_input()  # define iResolution and iTime

    def on_render(self):  # called for each frame
        for I in ti.grouped(self.img):
            uv = I / self.iResolution
            self.img[I] = ti.cos(uv.xyx + self.iTime + ts.vec(0, 2, 4)) * 0.5 + 0.5

if __name__ == '__main__':
    animation = MyAnimation()

It will smoothly switch between traditional ti.GUI window and IPython built-in display module by the value of environment variable TI_GUI_BACKEND.

1 Like

This is amazing! Thanks a lot!

Though the animation cannot be shown on github.