exp

概要

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

[p5.js] exp

サンプル

def draw
  background(200)

  # Compute the exp() function with a value between 0 and 2
  xValue = map(mouseX, 0, width, 0, 2)
  yValue = exp(xValue)

  y = map(yValue, 0, 8, height, 0)

  legend = format("exp (%.3f)\n= %.4f", xValue, yValue, 1, 4)
  stroke(150)
  line(mouseX, y, mouseX, height)
  fill(0)
  text(legend, 5, 15)
  noStroke
  ellipse(mouseX, y, 7, 7)

  # Draw the exp(x) curve,
  # over the domain of x from 0 to 2
  noFill
  stroke(0)
  shape do
    (0...width).each do |x|
      xValue = map(x, 0, width, 0, 2)
      yValue = exp(xValue)
      y = map(yValue, 0, 8, height, 0)
      vertex(x, y)
    end
  end
  line(0, 0, 0, height)
  line(0, height - 1, width, height - 1)
end

構文

戻値