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, per_vertex_radius=None)#
Draw a set of 2D circles on this canvas.
- Parameters:
centers – a taichi 2D Vector field, where each element indicate the 2D location of the center of a vertex.
radius – 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 – a taichi 3D vector field, where each element indicates the RGB color of a circle.
per_vertex_radius – a taichi float field, where each element indicates the radius of a circle.
- contour(self, scalar_field, cmap_name='plasma', normalize=False)#
Plot a contour view of a scalar field.
The input scalar_field will be converted to a Numpy array first, and then plotted using Matplotlib’s colormap. Users can specify the color map through the cmap_name argument.
- Parameters:
scalar_field (ti.field) – The scalar field being plotted. Must be 2D.
cmap_name (str, Optional) – The name of the color map in Matplotlib.
normalize (bool, Optional) – Display the normalized scalar field if set to True.
False. (Default is) –
- 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.
- 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.
- vector_field(self, vector_field, arrow_spacing=5, scale=0.1, width=0.002, color=(0, 0, 0))#
Draw a vector field on this canvas.
- Parameters:
vector_field – The vector field to be plotted on the canvas.
arrow_spacing (int) – Spacing used when sample on the vector field.
scale (float) – Maximum vector length proportional to the canvas.
width (float) – Line width when drawing the arrow.
color (tuple[float]) – The RGB color of arrows.