def setup
background(220)
v0 = createVector(1, 2, 3)
v1 = createVector(2, 3, 4)
result = P5Vector.mult(v0, v1)
text(result.toString, 10, 30, 70)
end
def setup
background(220)
v1 = createVector(1, 2, 3)
v2 = P5Vector.mult(v1, 2)
text(v2.toString, 10, 30, 60)
end
def draw
background(240)
v0 = createVector(50, 50)
v1 = createVector(25, -25)
num = map(mouseX, 0, width, -2, 2, true)
v2 = P5Vector.mult(v1, num)
drawArrow(v0, v1, 'red')
drawArrow(v0, v2, 'blue')
noStroke
text(format("multiplied by %.2f", num), 0, 90)
end
# draw an arrow for a vector at a given base position
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
あるベクトルに数値または他のベクトルを乗算してベクトルを生成します。
| 引数名 | 内容 | 備考 | オプション | デフォルト値 |
|---|---|---|---|---|
| v1 | ベクトル1 | p5.Vectorオブジェクト | ||
| v2 | ベクトル2 | p5.Vectorオブジェクト | ||
| n | 数値 | p5.Vectorオブジェクト | ||
| arr | 数値の配列 | p5.Vectorオブジェクト | ||
| target | 乗算結果収録用ベクトル | p5.Vectorオブジェクト | ○ |
乗算されたベクトル
(p5.Vectorオブジェクト)