SHOW:
|
|
- or go back to the newest paste.
| 1 | _G["basic"] = {}
| |
| 2 | ||
| 3 | function basic.drawPixel(x,y,spec) | |
| 4 | if not math.floor(x) then | |
| 5 | error("Got "..type(x)..". Number is expected")
| |
| 6 | elseif not math.floor(y) then | |
| 7 | - | error("Got"..typer(y)..". Number is expected")
|
| 7 | + | error("Got"..type(y)..". Number is expected")
|
| 8 | end | |
| 9 | local x = math.floor(x) | |
| 10 | local y = math.floor(y) | |
| 11 | if not spec then | |
| 12 | term.setCursorPos(x,y) | |
| 13 | write("#")
| |
| 14 | return true | |
| 15 | elseif spec == true then | |
| 16 | paintutils.drawPixel(x,y,colors.white) | |
| 17 | return true | |
| 18 | end | |
| 19 | return false | |
| 20 | end | |
| 21 | function basic.drawLine(x1,y1,x2,y2,spec) | |
| 22 | if spec then | |
| 23 | paintutils.drawLine(x1,y1,x2,y2,colors.white) | |
| 24 | return true | |
| 25 | end | |
| 26 | local x1 = math.floor(x1) | |
| 27 | local x2 = math.floor(x2) | |
| 28 | local y1 = math.floor(y1) | |
| 29 | local y2 = math.floor(y2) | |
| 30 | local minX = math.min(x1,x2) | |
| 31 | local maxX = math.max(x1,x2) | |
| 32 | local minY = math.min(y1,y2) | |
| 33 | local maxY = math.max(y1,y2) | |
| 34 | local difX = maxX - minX | |
| 35 | local difY = maxY - minY | |
| 36 | if x1 == x2 then | |
| 37 | if y1 == y2 then | |
| 38 | basic.drawPixel(x1,y1) | |
| 39 | else | |
| 40 | for ypos = minY,maxY do | |
| 41 | basic.drawPixel(x1,ypos) | |
| 42 | end | |
| 43 | end | |
| 44 | return true | |
| 45 | end | |
| 46 | for xpos = minX,maxX do | |
| 47 | local ypos = minY + difY * (xpos - minX) / difX | |
| 48 | basic.drawPixel(xpos,ypos) | |
| 49 | end | |
| 50 | return true | |
| 51 | end | |
| 52 | ||
| 53 | function basic.drawBox(x1,y1,x2,y2,spec) | |
| 54 | if spec then | |
| 55 | paintutils.drawBox(x1,y1,x2,y2,colors.white) | |
| 56 | return true | |
| 57 | end | |
| 58 | basic.drawLine(x1,y1,x2,y1) | |
| 59 | basic.drawLine(x1,y1,x1,y2) | |
| 60 | basic.drawLine(x2,y2,x1,y2) | |
| 61 | basic.drawLine(x2,y2,x2,y1) | |
| 62 | return true | |
| 63 | end | |
| 64 | ||
| 65 | function basic.drawFilledBox(x1,y1,x2,y2,spec) | |
| 66 | if spec then | |
| 67 | paintutils.drawFilledBox(x1,y1,x2,y1,colors.white) | |
| 68 | return true | |
| 69 | end | |
| 70 | local maxY = math.max(y1,y2) | |
| 71 | local minY = math.min(y1,y2) | |
| 72 | for i =minY,maxY do | |
| 73 | basic.drawLine(x1,i,x2,i) | |
| 74 | end | |
| 75 | return true | |
| 76 | end |