←  APIs and Utilities

ComputerCraft | Programmable Computers for Minecraft

»

Position API - Place it anywhere!

thecrimulo's Photo thecrimulo 04 Jul 2016

Position

API for managing coordinates


What is Position?
Position is an API for working with coordinates and other APIs that require them, like ChartsAPI.

Using Position
position.zero()
Returns zero
zero = position.zero()

position.incrFiveX(x, times)
Gets x, and increments by five $times times
x = position.incrFiveX(x, 5)

position.incrTenX(x, times)
Gets x, and increments by ten $times times
x = position.incrTenX(x, 5)

position.decrFiveX(x, times)
Gets x, and decrements by five $times times
x = position.decrFiveX(x, 5)
position.decrTenX(x, times)
Gets x, and decrements by ten $times times
x = position,decrTenX(x, 5)
position.middleX()
Returns the middle of the X axis, 26
term.setCursorPos(position.middleX(), 5)
position.rightX()
Returns 51, the full X axis size
term.setCursorPos(position.rightX(), 5)
position.leftX()
Returns 0, aligned left
term.setCursorPos(position.leftX(), 0)
position.marginRightX(margin)
Returns 51 minus the margin you want
marginRX = position.marginRightX(5)
position.marginLeftX(margin)
Returns 0 plus the margin you want
marginLX = position.marginLeftX(5)
position.incrFiveY(y, times)
Gets y, and increments by five $times times
x = position.incrFiveY(x, 5)

position.incrTenY(y, times)
Gets y, and increments by ten $times times
x = position.incrFiveX(x, 5)

position.decrFiveY(y, times)
Gets y, and decrements by five $times times
x = position.incrFiveX(x, 5)

position.decrTenY(y, times)
Gets y, and decrements by five $times times
x = position.incrFiveX(x, 5)

position.middleY()
Returns the middle of the Y axis, 7
mY = position.middleY()
position.topY()
Returns 0, aligned top
term.setCursorPos(5, position.topY())
position.bottomY()
Returns 19, the full Y axis size
bY = position.bottomY()
position.marginTopY()
Returns 0 plus the margin you want
term.setCursorPos(5, position.marginTopY())
position.marginBottomY()
Returns 19 minus the margin you want
term.setCursorPos(5, position.marginBottomY())
position.topLeftCorner()
Returns 0,0
x, y = position.topLeftCorner()
position.topRightCorner()
Returns 51,0
x, y = position.topRightCorner()
position.bottomLeftCorner()
Returns 0,19
x, y = position.bottomLeftCorner()
position.bottomRightCorner()
Returns 51,19
x, y = position.bottomRightCorner()
position.marginTopLeftCorner(margin)
Returns 0 + margin, 0 + margin
mx, my = position.marginTopLeftCorner()
position.marginTopRightCorner(margin)
Returns 51 - margin, 0 + margin
mx, my = position.marginTopRightCorner()
position.marginBottomLeftCorner(margin)
Returns 0 + margin, 19 - margin
mx, my = position.marginBottomLeftCorner()
position.marginBottomRightCorner(margin)
Returns 51 - margin, 19 - margin
mx, my = position.marginBottomRightCorner()
position.centerXY()
Returns 26,7. The center of the screen
cx, cy = position.centerXY()


Installing
pastebin get f5wzGRvN position

Edited by thecrimulo, 04 July 2016 - 06:15 PM.
Quote

moomoomoo3O9's Photo moomoomoo3O9 15 Aug 2016

If I can give a recommendation: use term.getSize(). Not all monitors or computers (pocket computers) are 51 characters long, especially if you change their size in the config!
Quote