texture

def setup
  createCanvas(100, 100, WEBGL)
  @img = loadImage("panda.png")
end

def draw
  background(0)
  rotateZ(frameCount * 0.02)
  rotateX(frameCount * 0.02)
  rotateY(frameCount * 0.02)
  # pass image as texture
  texture(@img)
  box(width / 2)
end
def setup
  createCanvas(100, 100, WEBGL)
  @pg = createGraphics(200, 200)
  @pg.textSize(75)
end

def draw
  background(0)
  orbitControl
  @pg.background(255)
  @pg.text('hello!', 0, 100)
  # pass image as texture
  texture(@pg)
  rotateX(0.5)
  noStroke
  plane(50)
end
def setup
  createCanvas(100, 100, WEBGL)
  @img = loadImage("panda.png")
end

def draw
  background(0)
  orbitControl
  texture(@img)
  textureMode(NORMAL)
  shape do
    vertex(-40, -40, 0, 0)
    vertex(40, -40, 1, 0)
    vertex(40, 40, 1, 1)
    vertex(-40, 40, 0, 1)
  end
end

p5.jsリファレンス(参考情報)

[p5.js] texture

概要

3Dモデルにテクスチャを設定します。

書式

texture(tex)

引数

引数名内容備考オプションデフォルト値
texp5.Imageオブジェクト
p5.Graphicsオブジェクト

戻値

なし

備考

・WEBGLモードのキャンバスでのみ有効です。
・beginShapeメソッドや shapeメソッドで作成された形体にテクスチャを適用するには
 vertexメソッドで uv座標を指定する必要があります。

関連

textureMode
textureWrap