P5 Python Docs
  • Getting Started
  • Simple mode
  • Reference
    • Shapes
      • 2D
        • point()
        • line()
        • rect()
        • square()
        • triangle()
        • circle()
        • ellipse()
        • arc()
        • quad()
        • beginShape()
      • 3D
        • plane()
        • box()
        • sphere()
        • cone()
        • cylinder()
        • ellipsoid()
        • torus()
    • Controlling the environment
      • coordinateMode()
      • rectMode()
      • ellipseMode()
      • frameRate()
      • setup()
      • draw()
    • Built-in Variables
      • Environment
      • Keyboard
      • Mouse
    • Built-in Functions
      • keyIsDown()
      • millis()
      • second()
      • minute()
      • hour()
      • translate()
      • rotate()
      • createSlider()
      • createGraphics()
      • createVector()
    • Events
      • Keyboard
        • keyPressed()
        • keyReleased()
      • Mouse
        • mouseMoved()
        • mouseDragged()
        • mousePressed()
        • doubleClicked()
        • mouseWheel()
    • Text
      • text()
      • textSize()
      • textAlign()
    • Math
      • drawTickAxes()
      • random()
      • randomGaussian()
      • dist()
      • linmap()
      • bounce()
      • wave()
    • Colour and Outline
      • colorMode()
      • fill()
      • stroke()
      • strokeWeight()
      • background()
    • Images & Audio
      • loadImage() and image()
      • loadSound()
    • 3D Controls
      • orbitControl()
      • translate()
      • rotateZ()
      • rotateX()
      • rotateY()
      • scale()
Powered by GitBook
On this page
  1. Reference
  2. Text

textAlign()

Set how text is aligned

PrevioustextSize()NextMath

Last updated 2 years ago

This function controls the alignment of the text you create with the function. It basically tell the computer how to understand the x, y coordinates the text function takes as parameter, since the text is not a point anyway. When you say textAlign(RIGHT) then call text("Hello", x, y) the right edge of the word "Hello" becomes the x value you give in the text function. Same thing with the vertical alignment, If you use textAlign(RIGHT, TOP), the top right corner becomes the x, y coordinates you give in the text function. You need to use on the predefined constants specified below.

textAlign(horizAlign, [vertAlign])
Input
Description

horizAlign

Specifies the horizontal alignment, takes values CENTER, RIGHT, LEFT

vertAlign

Specifies the vertical alignment, takes values CENTER, TOP, BOTTOM, BASELINE

Examples

    textAlign(LEFT)
    text("ABCD", 50, 25)

    textAlign(RIGHT)
    text("ABCD", 50, 50)

    textAlign(CENTER)
    text("ABCD", 50, 75)

    stroke("red")
    strokeWeight(5)
    point(50, 25)
    point(50, 50)
    point(50, 75)
    textAlign(CENTER, TOP)
    text("ABCD", 50, 15)

    textAlign(CENTER, CENTER)
    text("ABCD", 50, 40)

    textAlign(CENTER, BOTTOM)
    text("ABCD", 50, 65)

    textAlign(CENTER, BASELINE)
    text("ABCD", 50, 90)

    stroke("red")
    strokeWeight(5)
    point(50, 15)
    point(50, 40)
    point(50, 65)
    point(50, 90)

Find these documents helpful? Let the people who made them help your child learn to code at !

We'd love to hear your Feedback/Comments .

text()
Strivemath
here