Skip to content

texture()

Sets a texture to be applied to vertex points.

To properly wrap custom shapes you will need to specify uv coordinates in each vertex(). A uv cordinate indicates the placement of the mesh texture onto the shape. These can be specified normalized or as pixels with textureMode().

Note: Works similar to Processing's implementation rather than p5.js.

Examples

texture example 1

require("L5")

function setup()
  size(400, 400)
  windowTitle("texture() example")
  noStroke()
  textureMode(NORMAL)

  flower = loadImage("assets/flower.jpg")

  beginShape()
  texture(flower)
  vertex(40, 80, 0, 0)
  vertex(320, 20, 1, 0)
  vertex(380, 360, 1, 1)
  vertex(160, 380, 0, 1)
  endShape()

  describe("Wrapping a mesh texture around a custom shape with coordinates specified with u,v")
end

Syntax

texture(image)

This reference page contains content adapted from p5.js and Processing by p5.js Contributors and Processing Foundation, licensed under CC BY-NC-SA 4.0.