Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Gets a specified capacitor bank from an id
- function cb(num)
- return peripheral.wrap("capacitor_bank_" .. num)
- end
- --Gets a specified monitor and id
- function mon(num)
- return peripheral.wrap("monitor_" .. num)
- end
- --Gets a specific terminal bridge from an ID
- function tbr(num)
- return peripheral.wrap("openperipherals_bridge_" .. num);
- end
- --Gets a specified pnematiccraft compressor
- function fcmpr(num)
- return peripheral.wrap("fluxCompressor_" .. num)
- end
- --Gets a specified computer
- function comp(num)
- return peripheral.wrap("computer_" .. num)
- end
- --Maps a value of range to a new range
- function map(val, min, max, nmin, nmax)
- return ((val - min) / (max - min)) * (nmax - nmin) + nmin
- end
- --Clamps a value to a range
- function clamp(val, min, max)
- if val < min then return min end
- if val > max then return max end
- return val
- end
- --Clamps a value to a range (0, max)
- function clampMax(val, max)
- if val < 0 then return 0 end
- if val > max then return max end
- return val
- end
- --Clamps a value to a range, in this case 0 to 1
- function clamp01(val)
- if val < 0 then return 0 end
- if val > 1 then return 1 end
- return val
- end
- --Similar to blit, writes to monitor and colors the text
- function monWrt(mon, text, color)
- if color ~= nil then mon.setTextColor(color) end
- mon.write(text)
- end
- --Monitor newline
- function monNL(mon)
- local x, y = mon.getCursorPos()
- y = y + 1
- mon.setCursorPos(x, y)
- end
- --Monitor carriage return
- function monCR(mon)
- local x, y = mon.getCursorPos()
- mon.setCursorPos(1, y)
- end
- -- Monitor newline and carriage return
- function monNLCR(mon)
- local x, y = mon.getCursorPos()
- y = y + 1
- mon.setCursorPos(1, y)
- end
- --Reset monitor to defaults
- function rstMon(mon)
- mon.clear()
- mon.setCursorPos(1, 1)
- mon.setCursorBlink(false)
- mon.setTextScale(1)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- end
- --Monitor write fixed length
- function monWrtFxdLen(mon, len, text, color)
- local suff = ""
- local msgLen = string.len(text)
- local diff = len - msgLen
- local x, y = mon.getCursorPos()
- if msgLen > len then
- monWrt(mon, string.sub(text, 0, len), color)
- else
- monWrt(mon, text, color)
- mon.setCursorPos(x + len, y)
- end
- end
- --Prints to the monitor centered, also adds a lne
- function printCentLn(mon, text)
- local x, y = mon.getCursorPos()
- local w2 = (mon.getSize()) / 2
- local tl2 = string.len(text) / 2
- mon.setCursorPos(w2 - tl2, y)
- mon.write(text)
- mon.setCursorPos(x, y + 1)
- end
- --Rounds a number to n places
- function round(num, detail)
- local m = 10 ^ (detail or 0)
- return math.floor(num * m + 0.5) / m
- end
- --Formats a rf power string into a nice, clean format
- function getPwrStr(pwr, perT, digits)
- local d = math.floor(math.log10(pwr))
- local suff = "RF"
- if d >= 9 then
- pwr = pwr / 1000000000
- suff = "GRF"
- elseif d >= 6 then
- pwr = pwr / 1000000
- suff = "MRF"
- elseif d >= 3 then
- pwr = pwr / 1000
- suff = "KRF"
- elseif d < 0 then d = 1 end
- if perT then suff = suff .. "/t" end
- local pwrStr = round(pwr, digits)
- return pwrStr .. suff
- end
- --Checks if position is in bounds
- function chkBds(x, y, x1, y1, x2, y2)
- if((x >= x1 and x <= x2) and (y >= y1 and y <= y2)) then
- return true
- else
- return false
- end
- end
- --Converts kelvin to celcius
- function kelvinToCelcius(kelvin)
- return kelvin - 273.15
- end
- --Converts kelvin to celcius
- function celciusToKelvin(celcius)
- return celcius + 273.15
- end
- --Converts farenheit to celcius
- function farenheitToCelcius(faren)
- return (faren - 32.0) * (5.0 / 9.0)
- end
- --Converts celcius to farenheit
- function celciusToFarenheit(celcius)
- return (celcius * (9.0 / 5.0)) + 32.0
- end
- --Converts kelvin to farenheit
- function kelvinToFarenheit(kelvin)
- return celciusToFarenheit(kelvinToCelcius(kelvin))
- end
- --Converts farenheit to kelvin
- function farenheitToKelvin(faren)
- return celciusToKelvin(farenheitToCelcius(faren))
- end
Add Comment
Please, Sign In to add comment