Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getColor ( mctag )
- if mctag == "&0" then
- return 32768
- elseif mctag == "&f" then
- return 1
- elseif mctag == "&e" then
- return 16
- elseif mctag == "&a" then
- return colors.lime
- elseif mctag == "&b" then
- return colors.lightBlue
- elseif mctag == "&c" then
- return colors.red
- elseif mctag == "&d" then
- return colors.pink
- elseif mctag == "&1" then
- return colors.blue
- elseif mctag == "&2" then
- return colors.green
- elseif mctag == "&3" then
- return colors.cyan
- elseif mctag == "&4" then
- return colors.red
- elseif mctag == "&5" then
- return colors.purple
- elseif mctag == "&6" then
- return colors.orange
- elseif mctag == "&7" then
- return colors.lightGray
- elseif mctag == "&8" then
- return colors.gray
- elseif mctag == "&9" then
- return colors.cyan
- else
- return 1
- end
- end
- function setColor ( mctag )
- term.setTextColor(getColor(mctag))
- end
- function pColor ( text, color, bcolor )
- if bcolor == nil then
- term.setTextColor(getColor(color))
- print(text)
- term.setTextColor(getColor("&f"))
- else
- term.setBackgroundColor(getColor(color))
- term.setTextColor(getColor(color))
- print(text)
- term.setBackgroundColor(getColor("&f"))
- term.setTextColor(getColor("&0"))
- end
- end
- function setBColor ( mctag )
- term.setBackgroundColor(getColor(mctag))
- end
- nitro_api = {}
- function nitro_api.split(str, pat)
- local t = { }
- local fpat = "(.-)"..pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function pBack ( text, color )
- term.setBackgroundColor(getColor(color))
- if color == "&f" then
- term.setTextColor(getColor("&0"))
- print(text)
- term.setTextColor(getColor("&f"))
- term.setBackgroundColor(getColor("&0"))
- else
- print(text)
- term.setBackgroundColor(getColor("&0"))
- end
- end
- function resetScr ()
- term.setBackgroundColor(getColor("&0"))
- term.setTextColor(getColor("&f"))
- end
- function setPixel ( pix, piy, mcTag )
- oldx, oldy = term.getCursorPos()
- term.setCursorPos(pix,piy)
- term.setBackgroundColor(getColor(mcTag))
- write(" ")
- term.setBackgroundColor(getColor("&0"))
- term.setCursorPos(oldx,oldy)
- end
- function get_png_raw ( sfile )
- if not fs.exists(sfile) then
- return nil
- elseif fs.isDir(sfile) then
- return nil
- else
- local kb_0001 = io.open(sfile, "r")
- local slines = {}
- for line in kb_0001:lines() do
- slines[#slines+1] = line
- end
- kb_0001:close()
- local img_data = {}
- for n,m in ipairs(slines) do
- img_data[n] = nitro_api.split(m, " ")
- end
- return img_data
- end
- end
- function draw_png ( sfile )
- if not fs.exists(sfile) then
- return nil
- elseif fs.isDir(sfile) then
- return nil
- else
- oldX, oldY = term.getCursorPos()
- image_data = get_png_raw(sfile)
- for n, m in ipairs(image_data) do
- for zz, zy in ipairs(m) do
- setPixel(oldX+zz-1, oldY+n, zy)
- end
- end
- return true
- end
- end
- function export_png ( sfile, image_data )
- finalString = ""
- for n,m in ipairs(image_data) do
- for x,y in ipairs(m) do
- finalString = finalString..y.." "
- end
- finalString = string.sub(finalString,1,string.len(finalString)-1)
- finalString = finalString.."\n"
- end
- local ame = io.open(sfile, "w")
- ame:write(finalString)
- ame:close()
- end
- function drawLine(x1, y1, x2, y2, tag)
- local xdif = x1-x2
- local ydif = y1-y2
- local grad = ydif/xdif
- local curpos = 0
- for i=1,ydif,1 do
- if grad <= 1 then
- setPixel(x1+curpos, i)
- else
- for j=1,tonumber(grad),1 do
- setPixel(x1+curpos+j, i)
- end
- end
- curpos = curpos + grad
- end
- end
- function drawLine(pos1, pos2, tag)
- drawLine(pos1[0], pos1[1], pos2[0], pos2[1], tag)
- end
- function drawSquare(corner1, corner2, corner3, corner4, tag)
- drawLine(corner1, corner2, tag)
- drawLine(corner2, corner3, tag)
- drawLine(corner3, corner4, tag)
- drawline(corner4, corner1, tag)
- end
- function drawCircle(center, radius, tag, fill) -- (x-a)^2 + (y-B)^2 = r^2 (formula, where r is radius, x and y are coordinates and a and b is center)
- local rads = radius^2
- local topright = {center[0]-radius, center[1]+radius}
- local bottomleft = {center[0]+radius, center[1]-radius}
- for cx=topright[0],bottomleft[0],1 do
- for cy=topright[1],bottomleft[1],1 do
- local xb = (cx-center[0])^2
- local yb = (cy-center[1])^2
- if (xb+yb) == rads then
- setPixel(cx, cy, tag)
- elseif fill and (xb+yb) <= rads then
- setPixel(cx, cy, tag)
- end
- end
- end
- end
- function drawPolygon(points, tag)
- for i,v in ipairs(points) do
- local precorner = nil
- if i == 1 then
- precorner = points[#points]
- else
- precorner = points[i-1]
- end
- drawLine(v, precorner, tag)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment