Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- w,h = term.getSize()
- local x,y = term.getCursorPos()
- local str = ""
- local posX,posY --= nil,nil
- local elements = {}
- --"x,y" = {"string",colors.text,colors.back}
- function draw(words,x,y,col,back)
- words = tostring(words) or ""
- col = col or colors.white
- back = back or colors.black
- if x and y then
- term.setCursorPos(x,y)
- posX,posY = x,y
- for i=1,#words do
- posX,posY = tostring(posX),tostring(posY)
- local coord = posX..","..posY
- elements[coord] = {words:sub(i,i),col,back}
- posX = tonumber(posX) + 1
- end
- end
- term.setTextColor(col)
- term.setBackgroundColor(back)
- write(words)
- posX,posY = nil,nil
- end
- draw("string",7,5,colors.green,colors.white)
- draw("here's more",14,5,colors.purple,colors.grey)
- --[[term.setCursorPos(1,7)
- for i,v in pairs(elements) do
- write(i.." : ")
- for k=1,#v do
- write(tostring(v[k]).." ")
- end
- end
- for i,v in pairs(elements) do
- local half = i:find(",")
- draw(v[1],i:sub(1,half-1),i:sub(half+1)+1,v[2],v[3])
- end]]
- function clearMove(k,l)
- for i,v in pairs(elements) do
- local half = i:find(",")
- local px = tonumber(i:sub(1,half-1))
- local py = tonumber(i:sub(half+1))
- if k == px and l == py then
- draw(v[1],x,y,v[2],v[3])
- else
- draw(" ",x,y)
- end
- end
- end
- while true do
- e = {os.pullEvent()}
- if (e[1] == "mouse_drag" or e[1] == "mouse_click") and e[2] == 2 then
- clearMove(x,y)
- x,y = e[3],e[4]
- for i,v in pairs(elements) do
- i = tostring(i)
- local half = i:find(",")
- if tostring(x) == i:sub(1,half-1) then
- --if tostring(y) == i:sub(half+1) then
- str = "I"
- --end
- else
- str = "^"
- end
- end
- elseif e[1] == "mouse_click" and e[2] == 1 then
- clearMove(x,y)
- x,y = e[3],e[4]
- str = "*"
- end
- draw(str,x,y)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement