atan2

def draw
  background(204)
  translate(width / 2, height / 2)
  a = atan2(mouseY - height / 2, mouseX - width / 2)
  rotate(a)
  rect(-30, -5, 60, 10)
end

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

[p5.js] atan2

概要

正のx軸を基準として、指定した点と原点とを結ぶ直線の角度を計算します。

書式

atan2(y, x)

引数

引数名内容備考オプションデフォルト値
y点のy座標
x点のx座標

戻値

角度

備考

・戻値の単位および値は、angleModeの設定に依存します。
  RADIANSの場合 : -PI~+PI
  DEGREESの場合 : -180~+180

関連

angleMode