(p5.Vector.obj).set

def setup 
  @v0 = createVector(0, 0)
  @v1 = createVector(50, 50)
end

def draw 
  background(240)
  drawArrow(@v0, @v1, 'black')
  @v1.set(@v1.x + random(-1, 1), @v1.y + random(-1, 1))
  noStroke
  text("x: #{round(@v1.x)}  y: #{round(@v1.y)}", 10, 90)
end

def drawArrow(base, vec, myColor) 
  push do
    stroke(myColor)
    strokeWeight(3)
    fill(myColor)
    translate(base.x, base.y)
    line(0, 0, vec.x, vec.y)
    rotate(vec.heading)
    arrowSize = 7
    translate(vec.mag - arrowSize, 0)
    triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0)
  end
end

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

[p5.js] (p5.Vector.obj).set

概要

ベクトルの各成分の値を設定します。

書式

set([x] [, y] [, z])
set(value)

引数

引数名内容備考オプションデフォルト値
xx成分の値未詳
yy成分の値未詳
zz成分の値未詳
valueベクトルの値p5.Vectorオブジェクトまたは
数値配列

戻値

なし

備考

関連