floor

def draw
  background(200);
  # map, mouseX between 0 and 5.
  ax = map(mouseX, 0, 100, 0, 5)
  ay = 66

  # Get the floor of the mapped number.
  bx = floor(map(mouseX, 0, 100, 0, 5))
  by = 33

  # Multiply the mapped numbers by 20 to more easily
  # see the changes.
  stroke(0)
  fill(0)
  line(0, ay, ax * 20, ay)
  line(0, by, bx * 20, by)

  # Reformat the float returned by map and draw it.
  noStroke
  text(format("%.2f", ax), ax, ay - 5)
  text(format("%.1f", bx), bx, by - 5)
end

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

[p5.js] floor

概要

小数点以下を切り捨てた値を計算します。

書式

floor(n)

引数

引数名内容備考オプションデフォルト値
n数値

戻値

切り捨てられた値

備考

関連