Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- lib by levshx
- local graph = {}
- local component = require("component")
- local computer=require("computer")
- local serial = require("serialization")
- local unicode = require("unicode")
- local gpu = component.gpu
- function sign(x)
- if x<0 then
- return -1
- elseif x>0 then
- return 1
- else
- return 0
- end
- end
- function graph.setColorMinecraft(index) --Список цветов
- if (index ~= "r") then back = gpu.getForeground() end
- if (index == "0") then gpu.setForeground(0x333333) end
- if (index == "1") then gpu.setForeground(0x0000ff) end
- if (index == "2") then gpu.setForeground(0x00ff00) end
- if (index == "3") then gpu.setForeground(0x24b3a7) end
- if (index == "4") then gpu.setForeground(0xff0000) end
- if (index == "5") then gpu.setForeground(0x8b00ff) end
- if (index == "6") then gpu.setForeground(0xffa500) end
- if (index == "7") then gpu.setForeground(0xbbbbbb) end
- if (index == "8") then gpu.setForeground(0x808080) end
- if (index == "9") then gpu.setForeground(0x0000ff) end
- if (index == "a") then gpu.setForeground(0x66ff66) end
- if (index == "b") then gpu.setForeground(0x00ffff) end
- if (index == "c") then gpu.setForeground(0xff6347) end
- if (index == "d") then gpu.setForeground(0xff00ff) end
- if (index == "e") then gpu.setForeground(0xffff00) end
- if (index == "f") then gpu.setForeground(0xffffff) end
- if (index == "g") then gpu.setForeground(0x00ff00) end
- if (index == "r") then gpu.setForeground(back) end
- end
- function graph.text(x,y,text)
- y = y + 1
- for i = 1, unicode.len(text) do
- gpu.set(x+i,y, unicode.sub(text, i,i))
- end
- end
- function graph.colorText(x,y,text)
- -- Example:
- -- graph.colorText(0,0,"&4 RED &2 GREEN &3 BLUE &6 ORANGE")
- y = y + 1
- local n = 1
- for i = 1, unicode.len(text) do
- if unicode.sub(text, i,i) == "&" then
- graph.setColorMinecraft(unicode.sub(text, i + 1, i + 1))
- elseif unicode.sub(text, i - 1, i - 1) ~= "&" then
- gpu.set(x+n,y, unicode.sub(text, i,i))
- n = n + 1
- end
- end
- end
- function graph.box(x, y, width, height, symbol)
- if not symbol then
- symbol = unicode.char(0x2588) -- FULL BLOCK SYMBOL
- end
- gpu.fill(x, y, 1, height, symbol)
- gpu.fill(x, y, width, 1, symbol)
- gpu.fill(x+width-1, y, 1, height, symbol)
- gpu.fill(x, y+height-1, width, 1, symbol)
- end
- function graph.circle(X1, Y1, R, symbol)
- X1 = math.ceil( X1 / 2 )
- if not symbol then
- symbol = unicode.char(0x2588)..unicode.char(0x2588) -- FULL BLOCK SYMBOL
- end
- -- R - радиус, X, Y - координаты центра
- local x = 0
- local y = R
- local delta = 1 - (2 * R)
- local errror = 0
- while (y >= x) do
- gpu.set((X1 + x)*2, Y1 + y, symbol)
- gpu.set((X1 + x)*2, Y1 - y, symbol)
- gpu.set((X1 - x)*2, Y1 + y, symbol)
- gpu.set((X1 - x)*2, Y1 - y, symbol)
- gpu.set((X1 + y)*2, Y1 + x, symbol)
- gpu.set((X1 + y)*2, Y1 - x, symbol)
- gpu.set((X1 - y)*2, Y1 + x, symbol)
- gpu.set((X1 - y)*2, Y1 - x, symbol)
- error = 2 * (delta + y) - 1
- if ((delta < 0) and (errror <= 0)) then
- delta = delta +( 2 * (x+1) + 1)
- x = x + 1
- goto continue
- end
- if ((delta > 0) and (errror > 0)) then
- delta =delta-(2 * (y-1) + 1)
- y = y - 1
- goto continue
- end
- delta = delta + (2 * ((x+1)) - (y-1))
- x = x +1
- y = y-1
- ::continue::
- end
- end
- function graph.point(x, y, symbol)
- x = x + 1
- y = y + 1
- if not symbol then
- symbol = unicode.char(0x2588) -- FULL BLOCK SYMBOL
- end
- gpu.set(x, y, symbol)
- end
- function graph.line(x1, y1, x2, y2, symbol)
- if (y1>y2) then
- local xx = x1
- local yy = y1
- x1 = x2
- y1 = y2
- x2 = xx
- y2 = yy
- end
- if (x1>x2) then
- local xx = x1
- local yy = y1
- x1 = x2
- y1 = y2
- x2 = xx
- y2 = yy
- end
- local dx, dy = math.abs(x1-x2), math.abs(y1-y2)
- local symbol = value or unicode.char(0x2588)
- if dx > 0 or dy > 0 then
- if dx > dy then
- local y = y1
- for x = x1, x2, sign(x2-x1) do
- graph.point( x, math.floor(y+ 0.5), symbol)
- y = y + (dy / dx) * sign(y2-y1)
- end
- else
- local x = x1
- for y = y1, y2, sign(y2-y1) do
- graph.point(math.floor(x + 0.5), y, symbol)
- x = x + (dx / dy) * sign(x2-x1)
- end
- end
- end
- end
- return graph
Add Comment
Please, Sign In to add comment