P5Vector.fromAngle

概要

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

[p5.js] fromAngle

サンプル

def draw
  background(200)

  # Create a variable, proportional to the mouseX,
  # varying from 0-360, to represent an angle in degrees.
  myDegrees = map(mouseX, 0, width, 0, 360)

  # Display that variable in an onscreen text.
  # (Note the nfc() function to truncate additional decimal places,
  # and the "\xB0" character for the degree symbol.)
  readout = format("angle = %.1f\xB0", myDegrees);
  noStroke
  fill(0)
  text(readout, 5, 15)

  # Create a p5.Vector using the fromAngle function,
  # and extract its x and y components.
  v = P5Vector.fromAngle(radians(myDegrees), 30)
  vx = v.x
  vy = v.y

  push do
    translate(width / 2, height / 2)
    noFill
    stroke(150)
    line(0, 0, 30, 0)
    stroke(0)
    line(0, 0, vx, vy)
  end
end

構文

戻値