GGUI的lines方法画不出任何东西?

用GGUI的二维绘图功能,除了背景显示外没有任何东西被画出来:

import taichi as ti
import taichi.math as tm
ti.init(ti.gpu)

width, height = 512, 512
# field = ti.Vector.field(n=2, dtype=ti.f32, shape=(640,))
field = ti.Vector.field(n=2, dtype=ti.f64, shape=width)
indices = ti.Vector.field(n=2, dtype=ti.i32, shape=width)
field2 = ti.Vector.field(n=2, dtype=float, shape=3)
tmp = ti.Vector.field(n=2, dtype=ti.f64, shape=2)
field2[0] = [0, 0]
field2[1] = [1, 1]
field2[2] = [0, 0.5]

window = ti.ui.Window(name='Window Title', res = (width, height), fps_limit=200, pos = (150, 150))
canvas = window.get_canvas()
canvas.set_background_color((0x1f / 0xff, 0x1e / 0xff, 0x33 / 0xff))

@ti.kernel
def render_sin(phi: float):
    k = -50
    for i in field:
        k += 1
        field[i] = [k / width, (tm.sin(k + phi) * 10 + height / 2) / height]
        indices[i] = i

while window.running:
    render_sin(0)
    # canvas.circles(field, 0.01)
    canvas.lines(field, 0.01, indices)
    canvas.set_image(window.get_image_buffer_as_numpy())
    window.show()

但是circles方法可以正常画圆:

import taichi as ti
import taichi.math as tm
ti.init(ti.gpu)

width, height = 512, 512
# field = ti.Vector.field(n=2, dtype=ti.f32, shape=(640,))
field = ti.Vector.field(n=2, dtype=ti.f64, shape=width)
indices = ti.Vector.field(n=2, dtype=ti.i32, shape=width)
field2 = ti.Vector.field(n=2, dtype=float, shape=3)
tmp = ti.Vector.field(n=2, dtype=ti.f64, shape=2)
field2[0] = [0, 0]
field2[1] = [1, 1]
field2[2] = [0, 0.5]

window = ti.ui.Window(name='Window Title', res = (width, height), fps_limit=200, pos = (150, 150))
canvas = window.get_canvas()
canvas.set_background_color((0x1f / 0xff, 0x1e / 0xff, 0x33 / 0xff))

@ti.kernel
def render_sin(phi: float):
    k = -50
    for i in field:
        k += 1
        field[i] = [k / width, (tm.sin(k + phi) * 10 + height / 2) / height]
        indices[i] = i

while window.running:
    render_sin(0)
    canvas.circles(field, 0.01)
    # canvas.lines(field, 0.01, indices)
    canvas.set_image(window.get_image_buffer_as_numpy())
    window.show()

经测试,canvas.lines方法选取了一维的field中前两个点并画出了一条直线:

import taichi as ti
import taichi.math as tm
ti.init(ti.gpu)

width, height = 512, 512
# field = ti.Vector.field(n=2, dtype=ti.f32, shape=(640,))
field = ti.Vector.field(n=2, dtype=ti.f64, shape=width)
indices = ti.Vector.field(n=2, dtype=ti.i32, shape=width)
field2 = ti.Vector.field(n=2, dtype=float, shape=3)
tmp = ti.Vector.field(n=2, dtype=ti.f64, shape=2)
field2[0] = [0, 0]
field2[1] = [1, 1]
field2[2] = [0, 0.5]

window = ti.ui.Window(name='Window Title', res = (width, height), fps_limit=200, pos = (150, 150))
canvas = window.get_canvas()
canvas.set_background_color((0x1f / 0xff, 0x1e / 0xff, 0x33 / 0xff))

@ti.kernel
def render_sin(phi: float):
    k = -50
    for i in field:
        k += 1
        field[i] = [k / width, (tm.sin(k + phi) * 10 + height / 2) / height]
        indices[i] = i

while window.running:
    # canvas.circles(field, 0.01)
    # canvas.lines(field, 0.01, indices)
    canvas.lines(field2, 0.01)
    canvas.set_image(window.get_image_buffer_as_numpy())
    window.show()

那么canvas.lines方法能一次性画多条直线吗?如果能,应该怎么调用?