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
ベクトルの各成分の値を設定します。
| 引数名 | 内容 | 備考 | オプション | デフォルト値 |
|---|---|---|---|---|
| x | x成分の値 | ○ | 未詳 | |
| y | y成分の値 | ○ | 未詳 | |
| z | z成分の値 | ○ | 未詳 | |
| value | ベクトルの値 | p5.Vectorオブジェクトまたは 数値配列 |
なし