vertex

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

[p5.js] vertex

def setup
  background(220)
  strokeWeight(3)
  beginShape(POINTS)
  vertex(30, 20)
  vertex(85, 20)
  vertex(85, 75)
  vertex(30, 75)
  endShape
end
def setup
  createCanvas(100, 100, WEBGL)
  background(240, 240, 240)
  fill(237, 34, 93)
  noStroke
  beginShape
  vertex(0, 35)
  vertex(35, 0)
  vertex(0, -35)
  vertex(-35, 0)
  endShape()
end
def setup
  createCanvas(100, 100, WEBGL)
  background(240, 240, 240)
  fill(237, 34, 93)
  noStroke
  beginShape
  vertex(-10, 10)
  vertex(0, 35)
  vertex(10, 10)
  vertex(35, 0)
  vertex(10, -8)
  vertex(0, -35)
  vertex(-10, -8)
  vertex(-35, 0)
  endShape
end
def setup
  strokeWeight(3)
  stroke(237, 34, 93)
  beginShape(LINES)
  vertex(10, 35)
  vertex(90, 35)
  vertex(10, 65)
  vertex(90, 65)
  vertex(35, 10)
  vertex(35, 90)
  vertex(65, 10)
  vertex(65, 90)
  endShape
end
def setup 
  createCanvas(100, 100, WEBGL)
  @sides = 3
  fill(237, 34, 93)
  strokeWeight(3)
end

def draw 
  background(200)
  rotateX(frameCount * 0.01)
  rotateZ(frameCount * 0.01)
  ngon(@sides, 0, 0, 80)
end

def mouseClicked 
  if (@sides > 6) 
    @sides = 3
  else 
    @sides += 1
  end
end

def ngon(n, x, y, d) 
  beginShape(TESS)
  (0..n).each do |i|
    angle = TWO_PI / n * i
    px = x + sin(angle) * d / 2
    py = y - cos(angle) * d / 2
    vertex(px, py, 0)
  end
  (0..n).each do |i|
    angle = TWO_PI / n * i
    px = x + sin(angle) * d / 4
    py = y - cos(angle) * d / 4
    vertex(px, py, 0)
  end
  endShape
end

概要

多角形などの頂点座標を指定します。

書式

vertex(x, y)
vertex(x, y [, z])
vertex(x, y [, z] [, u] [, v])

引数

引数名内容備考オプションデフォルト値
x頂点の x座標
y頂点の y座標
z頂点の z座標0
u頂点のテクスチャの u座標
v頂点のテクスチャの v座標

戻値

なし

備考

・「beginShape ~ endShape」構文または「shape do ~ end」構文の中でのみ有効です。

関連

beginShape
endShape
shape