Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require"component"
- local e = require"event"
- local term = require"term"
- local sbc = com.gpu.setBackground
- local stc = com.gpu.setForeground
- local scp = term.setCursor
- local write = term.write
- local ui = {}
- function ui.gwrite(t)
- local x,y = term.getCursor()
- com.gpu.set(x,y,t)
- end
- function ui.drawPixel(x,y)
- scp(x,y)
- ui.gwrite(" ") -- add ui. when you call your own functions!
- end
- function ui.drawLine( startX, startY, endX, endY, nColour )
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- sbc(nColour)
- if startX == endX and startY == endY then
- ui.drawPixel( startX, startY )
- return
- end
- local minX = math.min( startX, endX )
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- -- TODO: clip to screen rectangle?
- local xDiff = maxX - minX
- local yDiff = maxY - minY
- if xDiff > math.abs(yDiff) then
- local y = minY
- local dy = yDiff / xDiff
- for x=minX,maxX do
- ui.drawPixel( x, math.floor( y + 0.5 ) )
- y = y + dy
- end
- else
- local x = minX
- local dx = xDiff / yDiff
- if maxY >= minY then
- for y=minY,maxY do
- ui.drawPixel( math.floor( x + 0.5 ), y )
- x = x + dx
- end
- else
- for y=minY,maxY,-1 do
- ui.drawPixel( math.floor( x + 0.5 ), y )
- x = x - dx
- end
- end
- end
- sbc(0x000000)
- end
- function ui.drawBox(sx,sy,ex,ey,col)
- sbc(col)
- scp(sx,sy)
- ui.gwrite(string.rep(" ",(ex-sx)+1))
- for i = 0, ey-sy do
- scp(sx,sy+i)
- ui.gwrite(" ")
- scp(ex,sy+i)
- ui.gwrite(" ")
- end
- scp(sx,ey)
- ui.gwrite(string.rep(" ",ex-sx))
- --sbc(0x000000)
- end
- function ui.drawFilledBox(sx,sy,ex,ey,col)
- sbc(col)
- for i = 0, ey-sy do
- scp(sx,sy+i)
- ui.gwrite(string.rep(" ",(ex-sx)+1))
- end
- --sbc(0x000000)
- end
- return ui
- --drawBox(1,1,10,10,0x00FF00)
- --drawFilledBox(11,11,21,21,0x0000FF)
- --drawLine(10,10,40,20,0xFFFFFF)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement