我想在GGUI上写一行命令,绘制100个不同位置、不同大小的圆球。
在GGUI中,我想画大约100个圆球在画布上,canvas.circles(vertices, radius, color, per_vertex_color)
这个函数可以实现。不过,我的100个圆圈位置跟半径都不一样。
100个位置信息我用一个100 x 2的vector,但是半径用一个100x1的ti.vector
好像不行,这里color好像只支持标量,也就是只支持统一半径吗。不过颜色可以用100*1的ti.vector
去支持多彩绘制,per_vertex_color
这个设置应该就是这个意思。
我觉得是不是radius也要有per_vertex_radius就好了。要不然我写做一个循环100次,去循环绘制100个圆球。例如:canvas.circles(vertices, radius, color,per_vertex_radius, per_vertex_color)
?
是否有现成的实现方式呢?我查看了文档 Doc里没有说。另外,Drawing on the canvas有画矩形的函数吗,我现在画矩形是画四条线拼起来的,代码看上去就很多,不知道有没有canvas.rectangle函数,我看了一下也没有。我的绘制程序如下:
window = ti.ui.Window('Test', (1000, 1000),vsync=True)
canvas = window.get_canvas()
ball_radius = 0.01
#下面十几行是绘制一个矩形
CornerPos = ti.Vector.field(2, dtype=ti.f32, shape=4)
CornerPos[0] = ti.Vector([Bilix, Bilix])
CornerPos[1] = ti.Vector([Bilix, 1-Bilix])
CornerPos[2] = ti.Vector([Biliy, 1-Bilix])
CornerPos[3] = ti.Vector([Biliy, Bilix])
indices = ti.field(dtype=ti.i32,shape=8)
indices[0] = 0
indices[1] = 1
indices[2] = 1
indices[3] = 2
indices[4] = 2
indices[5] = 3
indices[6] = 3
indices[7] = 0
#
while window.running:
canvas.lines(CornerPos, indices=indices, color=(), width=0.01)
canvas.circles(这里支持100行向量,color=(), radius = 这里不支持100行向量)
有没有更简洁的方式呢?