Reference getTexture()

getTexture()

This API is experimental

Its behavior may change in a future version of p5.js.

Retrieves the current color of a given texture at given coordinates.

The given coordinates should be between [0, 0] representing the top-left of the texture, and [1, 1] representing the bottom-right of the texture.

The given texture could be, for example:

The retrieved color that is returned will behave like a vec4, with components for red, green, blue, and alpha, each between 0.0 and 1.0.

Linear interpolation is used by default. For Framebuffer sources, you can prevent this by creating the buffer with:

createFramebuffer({
    textureFiltering: NEAREST
 })

This can be useful if you are using your texture to store data other than color. See createFramebuffer.

Note: The getTexture function is only available when using p5.strands.

Examples

Syntax

getTexture(texture, coords)

Parameters

texture
The texture to sample from. (e.g. a p5.Image, p5.Graphics, or p5.Framebuffer).
coords
The 2D coordinates to sample from. This should be between [0,0] (the top-left) and [1,1] (the bottom-right) of the texture. It should be compatible with a vec2.

Returns

The color of the given texture at the given coordinates. This will behave as a vec4 holding components r, g, b, and a (alpha), with each component being in the range 0.0 to 1.0.
Notice any errors or typos? Please let us know. Please feel free to edit src/strands/p5.strands.js and open a pull request!

Related References