Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[INSTRUCTIONS:
- pixels in upper-right corner represent color selection.
- left = text color.
- middle = background color (leftClick).
- right = alternate background color (rightClick).
- click on an upper-right pixel and use shift/control to cycle through its colors.
- press any keyboard character to select it.
- use mouseclick/drag to paint.
- press alt to exit.
- ]]
- local w,h = term.getSize()
- function switchColors()
- local alphabet = {"a","b","c","d","e","f"}
- for i,v in pairs(colors) do
- if tonumber(v) then
- res = math.log(v)/math.log(2)
- if res > 9 then
- res = alphabet[res-9]
- end
- colors[i] = tostring(res)
- end
- end
- end
- function draw(str,xPos,yPos,txtcol,bakcol)
- local str = tostring(str) or ""
- local txtcol = txtcol or txtsel
- local bakcol = bakcol or baksel
- if xPos and yPos then
- term.setCursorPos(xPos, yPos)
- end
- if term.blit then
- term.blit(str,string.rep(txtcol,#str),string.rep(bakcol,#str))
- else
- term.setBackgroundColor(bakcol)
- term.setTextColor(txtcol)
- term.write(str)
- end
- end
- if term.blit then
- switchColors()
- else
- os.loadAPI(shell.resolve("rom/apis/colors"))
- end
- term.clear()
- baksel = colors.yellow
- txtsel = colors.white
- altsel = colors.black
- local pallet = {}
- n = 0
- for i,v in pairs(colors) do
- if tonumber(v) then
- n = n + 1
- pallet[n] = v
- end
- end
- local sel = 'bak'
- local nCol = 1
- local tCol = 1
- local aCol = 1
- local key = " "
- while true do
- local events = {coroutine.yield()}
- if events[1] == "mouse_click" or events[1] == "mouse_drag" then
- if events[2] == 1 then
- if events[3] == w-1 and events[4] == 1 then
- sel = 'txt'
- elseif events[3] == w-2 and events[4] == 1 then
- sel = 'bak'
- elseif events[3] == w and events[4] == 1 then
- sel = 'alt'
- else
- draw(key,events[3],events[4])
- end
- elseif events[2] == 2 then
- draw(key,events[3],events[4],txtsel,altsel)
- end
- elseif events[1] == "char" then
- key = tostring(events[2])
- --[[elseif events[1] == "mouse_scroll" then
- if events[2] == 1 then
- if nCol < #pallet then
- nCol = nCol + 1
- baksel = pallet[nCol]
- end
- elseif events[2] == -1 then
- if nCol > 1 then
- nCol = nCol - 1
- baksel = pallet[nCol]
- end
- end]]
- elseif events[1] == "key" then
- if events[2] == 42 then
- if sel == 'txt' then
- if tCol < #pallet then
- tCol = tCol + 1
- txtsel = pallet[tCol]
- end
- elseif sel == 'bak' then
- if nCol < #pallet then
- nCol = nCol + 1
- baksel = pallet[nCol]
- end
- elseif sel == 'alt' then
- if aCol < #pallet then
- aCol = aCol + 1
- altsel = pallet[aCol]
- end
- end
- elseif events[2] == 29 then
- if sel == 'txt' then
- if tCol > 1 then
- tCol = tCol - 1
- txtsel = pallet[tCol]
- end
- elseif sel == 'bak' then
- if nCol > 1 then
- nCol = nCol - 1
- baksel = pallet[nCol]
- end
- elseif sel == 'alt' then
- if aCol > 1 then
- aCol = aCol - 1
- altsel = pallet[aCol]
- end
- end
- end
- elseif events[2] == 56 then
- break
- end
- draw(" ",w-1,1,_,txtsel)
- draw(" ",w-2,1)
- draw(" ",w,1,_,altsel)
- end
- for i,v in pairs(pallet) do
- print(i,": ",v)
- end
- print(#pallet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement