texture#
- k3d.factory.texture(binary=None, file_format=None, color_map=None, color_range=[], attribute=[], puv=[], opacity_function=[], interpolation=True, name=None, group=None, custom_data=None, compression_level=0, **kwargs)[source]#
Create a Texture drawable for displaying 2D raster images in common formats.
By default, the texture image is mapped into the square: -0.5 < x, y < 0.5, z = 1.
If the size (scale, aspect ratio) or position should be different then the texture should be transformed using kwargs
texture(..., xmin=0, xmax=640, ymin=0, ymax=480)
texture(..., bounds=[0, 10, 0, 20])
texture(..., scaling=[1.0, 0.75, 0])
- Parameters
binary (bytes, optional) – Image data in a specific format, by default None
file_format (str, optional) –
Format of the data, by default None.
It should be the second part of MIME format of type ‘image/’,e.g. ‘jpeg’, ‘png’, ‘gif’, ‘tiff’.
color_map (list, optional) – List of float quadruplets (attribute value, R, G, B) sorted by attribute value, by default None. The first quadruplet should have value 0.0, the last 1.0; R, G, B are RGB color components in the range 0.0 to 1.0.
color_range (list, optional) – [min_value, max_value] pair determining the levels of color attribute mapped to 0 and 1 in the colormap, by default [].
attribute (list, optional) – List of values used to apply color_map, by default [].
puv (list, optional) – List of float triplets (x,y,z), by default []. The first triplet mean a position of left-bottom corner of texture. Second and third triplets means a base of coordinate system for texture.
opacity_function (list, optional) – float tuples (attribute value, opacity) sorted by attribute value, by default []. The first tuples should have value 0.0, the last 1.0; opacity is in the range 0.0 to 1.0.
interpolation (bool, optional) – Interpolate the data, by default True
name (str, optional) – Object name, by default None.
group (str, optional) – Name of a group, by default None.
custom_data (dict) – A object with custom data attached to object.
compression_level (int, optional) – Level of data compression [-1, 9], by default 0.
**kwargs – For other keyword-only arguments, see process_transform_arguments.
- Returns
Texture Drawable.
- Return type
Texture
Examples#
Basic#
# Texture from https://opengameart.org/content/arcade-carpet-textures-arcadecarpet512png
import k3d
with open('arcade_carpet_512.png', 'rb') as texture:
data = texture.read()
plt_texture = k3d.texture(data,
file_format='png')
plot = k3d.plot()
plot += plt_texture
plot.display()
Colormap#
Attention
color_map must be used along with attribute and color_range in order to work correctly.
import k3d
import numpy as np
from k3d.colormaps import matplotlib_color_maps
t = np.linspace(0, 1, 100)
plt_texture = k3d.texture(color_map=matplotlib_color_maps.Jet,
attribute=t,
color_range=[0.15, 0.85])
plot = k3d.plot()
plot += plt_texture
plot.display()