跳转至主要内容

taichi.ui.canvas#

class taichi.ui.canvas.Canvas(canvas)#

The Canvas class.

This is the context manager for managing drawing commands on a window. You should not instantiate this class directly via __init__, instead please call the get_canvas() method of Window.

circles(self, centers, radius, color=(0.5, 0.5, 0.5), per_vertex_color=None)#

Draw a set of 2D circles on this canvas.

Parameters:
  • centers – a taichi 2D Vector field, where each element indicate the 3D location of a vertex.

  • radius (Number) – radius of the circles in pixels.

  • color – a global color for the triangles as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.

  • per_vertex_color (Tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of a circle.

lines(self, vertices, width, indices=None, color=(0.5, 0.5, 0.5), per_vertex_color=None)#

Draw a set of 2D lines on this canvas.

Parameters:
  • vertices – a taichi 2D Vector field, where each element indicate the 3D location of a vertex.

  • width (float) – width of the lines, relative to the height of the screen.

  • indices – a taichi int field of shape (2 * #lines), which indicate the vertex indices of the lines. If this is None, then it is assumed that the vertices are already arranged in lines order.

  • color – a global color for the triangles as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.

  • per_vertex_color (tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of a vertex.

scene(self, scene)#

Draw a 3D scene on the canvas

Parameters:

scene (Scene) – an instance of Scene.

set_background_color(self, color)#

Set the background color of this canvas.

Parameters:

color (tuple(float)) – RGB triple in the range [0, 1].

set_image(self, img)#

Set the content of this canvas to an img.

Parameters:

img (numpy.ndarray, MatrixField, Field, Texture) – the image to be shown.

triangles(self, vertices, color=(0.5, 0.5, 0.5), indices=None, per_vertex_color=None)#

Draw a set of 2D triangles on this canvas.

Parameters:
  • vertices – a taichi 2D Vector field, where each element indicate the 3D location of a vertex.

  • indices – a taichi int field of shape (3 * #triangles), which indicate the vertex indices of the triangles. If this is None, then it is assumed that the vertices are already arranged in triangles order.

  • color – a global color for the triangles as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.

  • per_vertex_color (Tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of a vertex.