Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _G["basic"] = {}
- function basic.drawPixel(x,y,spec)
- if not math.floor(x) then
- error("Got "..type(x)..". Number is expected")
- elseif not math.floor(y) then
- error("Got"..typer(y)..". Number is expected")
- end
- local x = math.floor(x)
- local y = math.floor(y)
- if not spec then
- term.setCursorPos(x,y)
- write("#")
- return true
- elseif spec == true then
- paintutils.drawPixel(x,y,colors.white)
- return true
- end
- return false
- end
- function basic.drawLine(x1,y1,x2,y2,spec)
- if spec then
- paintutils.drawLine(x1,y1,x2,y2,colors.white)
- return true
- end
- local x1 = math.floor(x1)
- local x2 = math.floor(x2)
- local y1 = math.floor(y1)
- local y2 = math.floor(y2)
- local minX = math.min(x1,x2)
- local maxX = math.max(x1,x2)
- local minY = math.min(y1,y2)
- local maxY = math.max(y1,y2)
- local difX = maxX - minX
- local difY = maxY - minY
- if x1 == x2 then
- if y1 == y2 then
- basic.drawPixel(x1,y1)
- else
- for ypos = minY,maxY do
- basic.drawPixel(x1,ypos)
- end
- end
- return true
- end
- for xpos = minX,maxX do
- local ypos = minY + difY * (xpos - minX) / difX
- basic.drawPixel(xpos,ypos)
- end
- return true
- end
- function basic.drawBox(x1,y1,x2,y2,spec)
- if spec then
- paintutils.drawBox(x1,y1,x2,y2,colors.white)
- return true
- end
- basic.drawLine(x1,y1,x2,y1)
- basic.drawLine(x1,y1,x1,y2)
- basic.drawLine(x2,y2,x1,y2)
- basic.drawLine(x2,y2,x2,y1)
- return true
- end
- function basic.drawFilledBox(x1,y1,x2,y2,spec)
- if spec then
- paintutils.drawFilledBox(x1,y1,x2,y1,colors.white)
- return true
- end
- local maxY = math.max(y1,y2)
- local minY = math.min(y1,y2)
- for i =minY,maxY do
- basic.drawLine(x1,i,x2,i)
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment