Fork me on GitHub
-- title:   Print align
-- author:  JoaoPauloVF, congusbongus
-- desc:    Print text with alignment options
-- license: MIT License
-- script:  lua
-- tags:    text print align

function printAlign(text, x, y, alignX, alignY, color, fixed, scale, smallFont)
    local x = x or 0
    local y = y or 0
    local alignX = alignX or "right"
    local alignY = alignY or "bottom"
    local color = color or 15
    local fixed = fixed or false
    local scale = scale or 1
    local smallFont = smallFont or false
    
    local font_h = 6 * scale
    local font_w = print(text, 0, -font_h*scale, color, fixed, scale, smallFont)
    
    x = alignX=="right" and x or alignX=="center" and x - font_w//2 or alignX=="left" and x - font_w + 1*scale or x --if alignX is not any of the accepted values, x gets the default value from "right".
    y = alignY=="bottom" and y or alignY=="middle" and y - font_h//2 or alignY=="top" and y - font_h + 1*scale or y --The same for alignY that y gets the value from "bottom".
    
    print(text, x, y, color, fixed, scale, smallFont)
end

function cross(x,y)
    local d=5
    local c=7
    line(x-d,y,x+d,y,c)
    line(x,y-d,x,y+d,c)
end

function TIC()
	cls(0)

    local y=40
    local x=70
    cross(x,y)
    printAlign("top-left",x,y,"left","top",6)

    x=120
    cross(x,y)
    printAlign("top-center",x,y,"center","top",8)

    x=170
    cross(x,y)
    printAlign("top-right",x,y,"right","top",9)

    y=70
    x=70
    cross(x,y)
    printAlign("middle-left",x,y,"left","middle",10)

    x=120
    cross(x,y)
    printAlign("middle-center",x,y,"center","middle",11)

    x=170
    cross(x,y)
    printAlign("middle-right",x,y,"right","middle",12)

    y=100
    x=70
    cross(x,y)
    printAlign("bottom-left",x,y,"left","bottom",13)

    x=120
    cross(x,y)
    printAlign("bottom-center",x,y,"center","bottom",14)

    x=170
    cross(x,y)
    printAlign("bottom-right",x,y,"right","bottom",15)
end

-- <SCREEN>
-- 035:000000000000000000000000000660000000000000000000660000000000066600660070000000000000000000008800000000000000000000000000700000000000880000000000000000000000000000000000007990000000000000000000000000990000000990000099000000000000000000000000
-- 036:000000000000000000000000006666600666006666000000660000666000660006666670000000000000000000088888008880088880000000888800888008888008888800888008888000000000000000000000009999900999009999000000999900000099900999900999990000000000000000000000
-- 037:000000000000000000000000000660006600606600606660660006606606666600660070000000000000000000008800088008088008088808880008808808800800880008808808800800000000000000000000007990009900909900909990990090990900990990090099000000000000000000000000
-- 038:000000000000000000000000000660006600606600600000660006660000660000660070000000000000000000008800088008088008000008880008880008800800880008880008800000000000000000000000007990009900909900900000990000990999990990090099000000000000000000000000
-- 039:000000000000000000000000000066600666006666000000066600666000660000066670000000000000000000000888008880088880000000888800888008800800088800888008800000000000000000000000007099900999009999000000990000990000990990090009990000000000000000000000
-- 040:000000000000000000000000000000000000006600000000000000000000000007777777777700000000000000000000000000088000000000077777777777000000000000000000000000000000000000000777777777770000009900000000000000000099900000000000000000000000000000000000
-- 041:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 042:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 043:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 044:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 045:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 065:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 066:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 067:000000000000000000aa0000aa0000aa0aa0000000000000aa00000000000aaa00aa0070000000000000000000bb0000bb0000bb0bb00000000000007000000000000000000bb00000000000000000000000000000700000cc0000cc0000cc0cc0000000000000000000cc0000000cc00000cc0000000000
-- 068:000000000000aa0a000000aaaa00aaaa0aa0000aaa000000aa0000aaa000aa000aaaaa70000000000000bb0b000000bbbb00bbbb0bb0000bbb0000007bbbb00bbb00bbbb00bbbbb00bbb00bbbb0000000000000000cc0c000000cccc00cccc0cc0000ccc000000cccc000000ccc00cccc00ccccc00000000
-- 069:000000000000aaaaa0aa0a00aa0a00aa0aa000aa0aa0aaa0aa000aa0aa0aaaaa00aa0070000000000000bbbbb0bb0b00bb0b00bb0bb000bb0bb0bbb0bbb000bb0bb0bb00b00bb000bb0bb0bb00b000000000000000ccccc0cc0c00cc0c00cc0cc000cc0cc0ccc0cc00c0cc0c00cc0cc00c00cc0000000000
-- 070:000000000000a0a0a0aa0a00aa0a00aa0aa000aaa0000000aa000aaa0000aa0007aa7777777700000000b0b0b0bb0b00bb0b00bb0bb000bbb0077777bbb777bbb000bb00b00bb000bbb000bb000000000000077777c7c7c7cc0c00cc0c00cc0cc000ccc0000000cc0000cc0ccccc0cc00c00cc0000000000
-- 071:000000000000a0a0a0aa00aaaa00aaaa00aaa00aaa0000000aaa00aaa000aa00000aaa70000000000000b0b0b0bb00bbbb00bbbb00bbb00bbb0000007bbbb00bbb00bb00b000bbb00bbb00bb000000000000000000c0c0c0cc00cccc00cccc00ccc00ccc000000cc0000cc0000cc0cc00c000ccc00000000
-- 072:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000ccc000000000000000000000
-- 073:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 074:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 075:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 095:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 096:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 097:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 098:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 099:000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000
-- 100:00000000dd00000000000dd0000dd0000000000000000000dd00000000000ddd07dd77777777000000ee00000000000ee0000ee00000000000077777777777000000000000000ee000000000000000000000077777ff77770000000ff0000ff0000000000000000000000000ff0000000ff00000ff000000
-- 101:00000000dddd000ddd00ddddd0ddddd00ddd00dd0d000000dd0000ddd000dd000ddddd700000000000eeee000eee00eeeee0eeeee00eee00ee0e0000700eeee00eee00eeee00eeeee00eee00eeee00000000000000ffff000fff00fffff0fffff00fff00ff0f000000ffff000000fff00ffff00fffff0000
-- 102:00000000dd00d0dd00d00dd0000dd000dd00d0ddddd0ddd0dd000dd0dd0ddddd00dd00700000000000ee00e0ee00e00ee0000ee000ee00e0eeeee0eee0eee000ee0ee0ee00e00ee000ee0ee0ee00e0000000000000ff00f0ff00f00ff0000ff000ff00f0fffff0fff0ff00f0ff0f00ff0ff00f00ff000000
-- 103:00000000dd00d0dd00d00dd0000dd000dd00d0d0d0d00000dd000ddd0000dd0000dd00700000000000ee00e0ee00e00ee0000ee000ee00e0e0e0e00070eee000eee000ee00e00ee000eee000ee0000000000000000ff00f0ff00f00ff0000ff000ff00f0f0f0f00000ff0000ff0fffff0ff00f00ff000000
-- 104:00000000dddd000ddd0000ddd000ddd00ddd00d0d0d000000ddd00ddd000dd00000ddd700000000000eeee000eee0000eee000eee00eee00e0e0e000700eeee00eee00ee00e000eee00eee00ee0000000000000000ffff000fff0000fff000fff00fff00f0f0f00000ff0000ff0000ff0ff00f000fff0000
-- 105:0000000000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000fff00000000000000000
-- </SCREEN>

-- <PALETTE>
-- 000:140c1c44243430346d4e4a4e854c30346524d04648757161597dced27d2c8595a16daa2cd2aa996dc2cadad45edeeed6
-- </PALETTE>