#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# TextAlign() not working

in Bugs Posts: 16

I am trying to make my text aligned to the left, but it stays aligned to the center. Can I have some help??

• Posts: 2,348
@DJMoffinz - could you post a little code to see what you are trying to do.
• edited November 2020 Posts: 16
``````-- Area Calculator

-- Use this function to perform your initial setup
function setup()
Pi = math.pi
CenterX = WIDTH/2
CenterY = HEIGHT/2
CirclePos = WIDTH/4 +100
parameter.number("Diameter",10,600,200)
end

-- This function gets called once every frame
function draw()
textAlign(LEFT)
TextPos = CirclePos + (Diameter/2) + 100
LineThickness = 2.5+2.5*Diameter/600
-- This sets a dark background color
background(25)

strokeWidth(LineThickness)

fontSize(14.5+(2.5+2.5*Diameter/600))

-- Do your drawing here
fill(255)

if Diameter <= 181 then
text("Diameter: "..string.format("%.2f",Diameter).."px",TextPos,CenterY)

elseif Diameter >= 181 then
text("Diameter: "..string.format("%.2f",Diameter).."px",CirclePos,(CenterY+12.5)+LineThickness)
pushStyle()
textAlign(CENTER)
fontSize(17)
end
text("Radius: "..string.format("%.2f",Diameter/2) .."px",TextPos,CenterY -20)
text("Area: "..string.format("%.2f",Pi*((Diameter/2)^2)).."px",TextPos,CenterY -40)
text("Circumference: "..string.format("%.2f",Diameter*Pi).."px",TextPos,CenterY -60)
pushStyle()
noFill()
ellipse(CirclePos,CenterY,Diameter)

line(CirclePos - (Diameter/2 -4),CenterY,CirclePos + (Diameter/2 -4),CenterY)
end
``````
• Mod
Posts: 9,415

@DJMoffinz If you want to use string.format to align text, here’s an example. You have to use a fixed width font, in this case Courier. Then you use values to define the sizes of the values you display. A minus sign before a value aligns left.

``````viewer.mode=FULLSCREEN

function setup()
font("Courier-Bold")
fill(255)
t1="Diameter"
v1=123.4567
t2="Size"
v2=23.65