Skip to content

textAscent()

Returns the ascent of the text.

The textAscent() function calculates the distance from the baseline to the highest point of the current font. This value represents the ascent, which is essential for determining the overall height of the text along with textDescent().

Examples

textAscent example 1

require("L5")

function setup()
  size(150, 100)
  windowTitle("textAscent()/textDescent() example")

  background(240)
  fill(0)
  textAlign(LEFT, BASELINE)

  local baselineY = 60
  local msg = "Hello"
  text(msg, 20, baselineY)

  stroke(255, 0, 0)
  local topY = baselineY - textAscent()
  line(20, topY, 20 + textWidth(msg), topY)

  stroke(0, 0, 255)
  local bottomY = baselineY + textDescent()
  line(20, bottomY, 20 + textWidth(msg), bottomY)

  describe("The text Hello with a red line above and a blue line below.")
end

Syntax

textAscent()

Returns

Number: The ascent value in pixels.


This reference page contains content adapted from p5.js and Processing by p5.js Contributors and Processing Foundation, licensed under CC BY-NC-SA 4.0.