Advertisement
superkh

Buffer

Apr 28th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.60 KB | None | 0 0
  1. local w,h = term.getSize()
  2. local Pos = {1,1} --postion of cursor
  3. local Bc = 32768    --background color
  4. local Tc = 1  --text Color
  5. local buffer = {}
  6. local moniters = {}
  7. local lodingBar = {}
  8. local main = term
  9. ---------------------------------
  10. --buffer is the screen code
  11. ------------------------------------
  12. --buffer = buffer[n][1][2]==X=1,Y=2
  13. --n=nomber you get when you create a buffer
  14. --buffer[n][1][2]([1]<-- 1 2 3)
  15. --1=bc background color
  16. --2=tc text colorq
  17. --3=words/chars stuff you write to the screen
  18. ---------------------------------
  19. --Clear Buffer-------------------
  20. function clearBuffer()
  21.     buffer = {}
  22. end
  23. --Setup Buffer-------------------
  24. local function setupBuffer(xo,yo)
  25.     local xo = xo or w
  26.     local yo = yo or h
  27.     table.insert(buffer,{})
  28.     local n = #buffer
  29.     for y=1, yo do
  30.         table.insert(buffer[n],{})
  31.         for x=1, xo do
  32.             local i = {1,32768," "}
  33.             table.insert(buffer[n][y],i)
  34.         end
  35.     end
  36.     buffer[n].screen = main
  37.     return n
  38. end
  39. local function setupBufferMoniter(wrapMon, xo,yo)
  40.     local wM,hM = wrapMon.getSize()
  41.     local xo = xo or wM
  42.     local yo = yo or hM
  43.     table.insert(buffer,{})
  44.     local n = #buffer
  45.     for y=1, yo do
  46.         table.insert(buffer[n],{})
  47.         for x=1, xo do
  48.             local i = {1,32768," "}
  49.             table.insert(buffer[n][y],i)
  50.         end
  51.     end
  52.     buffer[n].screen = wrapMon
  53.     return n
  54. end
  55. ---------------------------------
  56. --Draws Buffer On Screen----------
  57. function drawBuffer(n,x2,y2)   
  58.     local h = #buffer[n]
  59.     local w = #buffer[n][1]
  60.     local x = 1
  61.     local y = 1
  62.     local screen = buffer[n].screen
  63.     if x2 then
  64.         ox2 = x2
  65.     else
  66.         ox2 = 1
  67.     end
  68.     x2 = x2 or 1
  69.     y2 = y2 or 1
  70.     while true do
  71.         if y<=h then
  72.             if x<=w then
  73.                 screen.setBackgroundColor(buffer[n][y][x][1])
  74.                 screen.setTextColor(buffer[n][y][x][2])
  75.                 screen.setCursorPos(x2,y2)
  76.                 screen.write(buffer[n][y][x][3])
  77.                 x=x+1
  78.                 x2=x2+1
  79.             else
  80.                 x2 = ox2
  81.                 x=1
  82.                 y=y+1
  83.                 y2 = y2+1
  84.             end
  85.         else
  86.             screen.setCursorPos(2,4)
  87.             break
  88.         end
  89.     end
  90. end
  91. function getSizeBuff(n)
  92.     local r = {#buffer[n],#buffer[n][1]}
  93.     return r
  94. end
  95. function copyBufferNew(n1) --n1 = orriginal; newbuf is the reffrence to the new buffer
  96.     table.insert(buffer,{})
  97.     local newbuf = #buffer
  98.     buffer[newbuf] = buffer[n1]
  99.     return newbuf
  100. end
  101. function copyBuffer(n1,n2) --n1 = orriginal; n2 is the other
  102.     buffer[n2] = buffer[n1]
  103. end
  104. function resizeBuffer(n,w,h)
  105.     buffer[n] = {}
  106.     local xo = xo or w
  107.     local yo = yo or h
  108.     for y=1, yo do
  109.         table.insert(buffer[n],{})
  110.         for x=1, xo do
  111.             local i = {1,32768," "}
  112.             table.insert(buffer[n][y],i)
  113.         end
  114.     end
  115. end
  116. ---------------------------------
  117. --Loads One Pixel----------------
  118. local function ldrawPixel(n,x,y,cbc,ctc,s)
  119.     local ctc = ctc or Tc
  120.     local s = s or " "
  121.     local cbc = cbc or Bc
  122.     buffer[n][y][x][1]=cbc
  123.     buffer[n][y][x][2]=ctc
  124.     buffer[n][y][x][3]=s
  125. end
  126. ----------------------------------
  127. --User Commands-------------------
  128. --[[ More Detailed Information located by function
  129. pos(x,y) -sets the postion on the screen
  130. getPos() -returns curent posistion
  131. bc(colors) -sets the background color
  132. tc(colors) -sets the text color
  133. cls() -clears the screen
  134. clsB() -clears the buffer
  135. clsLx() -clears the X line/row
  136. clsLy() -clears the Y line/colaum
  137. bWrite("text") -writes text to the screen in string
  138. ]]
  139. -----------------------------------
  140. --[[ Example Program #1: Simple Header and Footer Program
  141.     local w,h = term.getSize()
  142.     buf1 = buffer.createBuffer() -- creates the buffer
  143.     buffer.bc(colors.blue) -- sets the background color
  144.     buffer.tc(colors.white) --sets the text color
  145.     buffer.pos(2,1) --sets the posistion
  146.     buffer.clsLx(buf1)  --clears the x row in this case line 1
  147.     buffer.bWriteL(buf1,"Welcome!") -- writes welcome! starting at x=1 y=2
  148.     buffer.pos(2,h) --sets the posistion to x=2, y=19 or h
  149.     buffer.clsLx(buf1) --clears that line
  150.     buffer.wCentered(buf1,"This is in the center") --prints the string in the senter  
  151.     buffer.drawBuffer(buf1) -- befor this nothing has been drawn
  152.     sleep(5)
  153. ]]
  154. --[[ Example Program #2: has borders around screen with a black dot that can move with keys w a s d
  155. function main()
  156.     local w,h = term.getSize()
  157.     buf1 = buffer.createBuffer() -- creates the buffer
  158.     buffer.clsB(buf1,colors.red) -- this makes all the pixels red
  159.     --makes a red border
  160.     buffer.wCentered(buf1,"Dot Example",1,colors.white,colors.red)
  161.     buffer.drawBuffer(buf1)
  162.     --beging code for Examples
  163.     buf2 = buffer.createBuffer(50,17)
  164.     buffer.clsB(buf2,colors.blue)
  165.     buffer.drawPixel(buf2,math.floor(w/2)-1,math.floor(h/2)-1,colors.white) -- first pixels
  166.     buffer.drawBuffer(buf2,2,2)
  167.     buffer.pos(math.floor(w/2)-1,math.floor(h/2)-1)
  168.     while true do
  169.         local lastpos = buffer.getPos()
  170.         local newpos = lastpos
  171.         local arg = { os.pullEvent("key") }
  172.         if arg[2]==keys.w then
  173.             if lastpos[2]~=1 then
  174.                 newpos = {lastpos[1],lastpos[2]-1}
  175.             end
  176.         elseif arg[2]==keys.s then
  177.             if lastpos[2]~=h-2 then
  178.                 newpos = {lastpos[1],lastpos[2]+1}
  179.             end
  180.         elseif arg[2]==keys.a then
  181.             if lastpos[1]~=1 then
  182.                 newpos = {lastpos[1]-1,lastpos[2]}
  183.             end
  184.         elseif arg[2]==keys.d then
  185.             if lastpos[1]~=w-2 then
  186.                 newpos = {lastpos[1]+1,lastpos[2]}
  187.             end
  188.         elseif arg[2]==keys.q then
  189.             break
  190.         end
  191.         if lastpos~=newpos then
  192.             buffer.drawPixel(buf2,lastpos[1],lastpos[2],colors.blue)
  193.             buffer.pos(newpos[1],newpos[2])
  194.             buffer.drawPixel(buf2,newpos[1],newpos[2],colors.white)
  195.             buffer.drawBuffer(buf2,2,2)
  196.         end
  197.     end
  198.     term.setBackgroundColor(colors.black)
  199.     term.setTextColor(colors.white)
  200.     term.setCursorPos(1,1)
  201.     term.clear() -- runs term.clear()
  202. end
  203. main() -- this allows for error checking if you wish
  204. ]]
  205. function createBuffer(xo,yo,monWrap) -- monWrap if it exists it will use the wraped peripheral insted of term
  206.     if monWrap then
  207.         local n = setupBufferMoniter(monWrap, xo,yo)
  208.         return n
  209.     else
  210.         local n = setupBuffer(xo,yo)
  211.         return n
  212.     end
  213. end
  214. function screenPos(x,y,n)--n is optional it allows for moniter support. linked to buffer number
  215.     local screen = buffer[n].screen or main
  216.     --[[
  217.         this function alows for you to set the position on the screen so you can use functions like read()
  218.     ]]
  219.     screen.setCursorPos(x,y)
  220. end
  221. function pos(x,y)
  222.     --[[
  223.         this function sets the Postion on the screen like the term.setCursorPos() function
  224.         This Affects the following functions:
  225.         -bWrite
  226.         -clsLx: clears the x line
  227.         -clsLy: clears the y line
  228.     ]]
  229.     Pos = {x,y}
  230. end
  231. function posCenter(l,y)
  232.     --[[
  233.         this function is for centering the text for functions like slowWrite()
  234.         this alows for you to get the text in the center of the screen but still beable to slowWrite with out writing it in
  235.     ]]
  236.     if y then
  237.         Pos = {math.floor((w/2)-(#l/2)),y}
  238.     elseif l then
  239.         Pos = {math.floor((w/2)-(#l/2)),Pos[2]}
  240.     else
  241.         error('Usage: posCenter("string",<yLine>)',2)
  242.     end
  243. end
  244. function posRight(l,y)
  245.     if y then
  246.         Pos = {math.floor(w-#l+1),y}
  247.     elseif l then
  248.         Pos = {math.floor(w-#l+1),Pos[2]}
  249.     else
  250.         error('Usage: posRight("string",<yLine>)',2)
  251.     end
  252. end
  253. function movePos(mx,my)--mx = Move over x, my = Move over y
  254.     if mx and my then
  255.         if Pos[1]+mx<0 or Pos[2]+my<0 or Pos[1]+mx>w+1 or Pos[2]+my>h+1 then
  256.             error("Can not extend bounders of screen",2)
  257.         else
  258.             Pos = {Pos[1]+mx,Pos[2]+my}
  259.         end
  260.     else
  261.         return false
  262.     end
  263. end
  264. function getPos()
  265.     --[[
  266.         this function just returns the curent posistion of your buffer
  267.         this pirnts out the last pos() function called
  268.     ]]
  269.     return Pos
  270. end
  271. function bc(c)
  272.     --[[
  273.         this Function Sets the background color like the term.setBackgroundColor() function  
  274.         This Affects the following functions:
  275.         -cls(),clsB(),clsLx(),clsLy()
  276.         -bWrite()
  277.     ]]
  278.     Bc = c
  279. end
  280. function tc(c)
  281.     --[[
  282.         this Function Sets the text color like the term.setTextColor() function
  283.         This Affects the following functions:
  284.         -bWrite()
  285.     ]]
  286.     Tc = c
  287. end
  288. function cls(n)
  289.     local screen = buffer[n].screen or main
  290.     --[[
  291.         this function only clears the screen it is exactly like term.celar()
  292.         do not use this unless you need it for specal uses
  293.     ]]
  294.     screen.clear()
  295. end
  296. function clsB(n,cBc,cTc,Cw)
  297.     --[[
  298.         this function clears the buffer. everything is set to deffalt and bc color is apllied to all pixels    
  299.     ]]
  300.     local w = #buffer[n][1]
  301.     local h = #buffer[n]
  302.     local x =0
  303.     local y =0
  304.     local cBc = cBc or Bc
  305.     local cTc = cTc or 1
  306.     local Cw = Cw or " "
  307.     for x=1,w do
  308.         for y=1,h do
  309.             buffer[n][y][x][1]= cBc
  310.             buffer[n][y][x][2]= cTc
  311.             buffer[n][y][x][3]= Cw
  312.         end
  313.     end
  314. end
  315. function clsLx(n,y,c,ctc,s) -- y,c,tc,s is optional
  316.     --[[
  317.         this function is like the term.clearLine() function it sets everthing in the
  318.         buffer on the curent x line to be defalt and have the bc color
  319.     ]]
  320.     local w = #buffer[n][1]
  321.     local oldPos = {Pos[1],Pos[2]}
  322.     local c = c or Bc
  323.     if y~=nil then
  324.         Pos = {1,y}
  325.     else
  326.         Pos = {1,Pos[2]}
  327.     end
  328.     local Ctc = ctc or Tc
  329.     local cs = s or " "
  330.     while Pos[1]<=w do
  331.         drawPixel(n,Pos[1],Pos[2],c,Ctc,cs)
  332.         Pos = {Pos[1]+1,Pos[2]}
  333.     end
  334.     Pos = oldPos
  335. end
  336. function clsLy(n,x,c,ctc,s) -- x,c,tc,s  is optional
  337.     --[[
  338.         this function acks like the clsLx() function but in steed of clearing
  339.         a line/row it clears a colaum it setes everthing on the y colaum to defalt and the bc color
  340.     ]]
  341.     local h = #buffer[n]
  342.     local oldPos = {Pos[1],Pos[2]}
  343.     local cColor = c or Bc
  344.     if x~=nil then
  345.         Pos = {x,1}
  346.     else
  347.         Pos = {Pos[1],1}
  348.     end
  349.     local Ctc = ctc or Tc
  350.     local cs = s or " "
  351.     while Pos[2]<=h do
  352.         drawPixel(n,Pos[1],Pos[2],cColor,Ctc,cs)
  353.         Pos = {Pos[1],Pos[2]+1}
  354.     end
  355.     Pos = oldPos
  356. end
  357. function bWrite(n,s,ctc,cbc) --tc and bc are optional
  358.     --[[
  359.         this adds text to the buffer /n does not work in this verstion
  360.         bc and tc both affect this function
  361.     ]]
  362.     local cBc = cbc or Bc
  363.     local Ctc = ctc or Tc
  364.     ldrawPixel(n,Pos[1],Pos[2],cBc,Ctc,s)
  365. end
  366. --needs Comments V and addet to list of functions
  367. function bWriteL(n,l,ctc,cbc)
  368.     local oldPos = Pos
  369.     local cBc = cbc or Bc
  370.     local Ctc = ctc or Tc
  371.     if #l<2 then
  372.         bWrite(n,l,Ctc,cBc)
  373.     end
  374.     local cpos = Pos
  375.     for i=1,#l do
  376.         Pos = {cpos[1],cpos[2]}
  377.         local s = string.sub(l,i,i)
  378.         bWrite(n,s,Ctc,cBc)
  379.         cpos = {cpos[1]+1,cpos[2]}
  380.     end
  381.     Pos = oldPos
  382. end
  383. function bWriteLP(n,l,ctc,cbc) --leaves pos where it left of like write()
  384.     local cBc = cbc or Bc
  385.     local Ctc = ctc or Tc
  386.     if #l<2 then
  387.         bWrite(n,l,Ctc,cBc)
  388.     end
  389.     local cpos = Pos
  390.     for i=1,#l do
  391.         Pos = {cpos[1],cpos[2]}
  392.         local s = string.sub(l,i,i)
  393.         bWrite(n,s,Ctc,cBc)
  394.         cpos = {cpos[1]+1,cpos[2]}
  395.     end
  396.     Pos = {Pos[1]+1,Pos[2]}
  397. end
  398. function wCentered(n,s,y,ctc,cbc) -- y is optional
  399.     local w = #buffer[n][1]
  400.     local cbc = cbc or Bc
  401.     local ctc = ctc or Tc
  402.     y = y or Pos[2]
  403.     Pos = {(math.floor(w/2)-math.floor(#s/2)),y}
  404.     bWriteLP(n,s,ctc,cbc)
  405. end
  406. function wLeft(n,s,y,ctc,cbc) -- y is optional
  407.     local oldPos = Pos
  408.     local cpos = Pos
  409.     if y then
  410.         cpos[2] = y
  411.     end
  412.     Pos = {1,cpos[2]}
  413.     if cbc~=nil then
  414.         bWriteL(n,s,ctc,cbc)
  415.     elseif ctc~=nil then
  416.         bWriteL(n,s,ctc)
  417.     else
  418.         bWriteL(n,s)
  419.     end
  420.     Pos = oldPos
  421. end
  422. function wRight(n,s,y,ctc,cbc) -- y is optional
  423.     local w = #buffer[n][1]
  424.     local oldPos = Pos
  425.     local cpos = Pos
  426.     if y then
  427.         cpos[2] = y
  428.     end
  429.     Pos = {w-#s+1,cpos[2]}
  430.     if cbc~=nil then
  431.         bWriteL(n,s,ctc,cbc)
  432.     elseif ctc~=nil then
  433.         bWriteL(n,s,ctc)
  434.     else
  435.         bWriteL(n,s)
  436.     end
  437.     Pos = oldPos
  438. end
  439. function slowWrite(n,l,Time,ctc,cbc)
  440.     local oldPos = Pos
  441.     local cBc = cbc or Bc
  442.     local Ctc = ctc or Tc
  443.     if #l<2 then
  444.         bWrite(n,l,Ctc,cBc)
  445.     end
  446.     if Time==nil then
  447.         Time = 1/20
  448.     else
  449.         if Time>0 then
  450.             Time = 1/Time
  451.         else
  452.             error("Rate must be positive",2)
  453.         end
  454.     end
  455.     local cpos = Pos
  456.     for i=1,#l do
  457.         Pos = {cpos[1],cpos[2]}
  458.         local s = string.sub(l,i,i)
  459.         bWrite(n,tostring(s),Ctc,cBc)
  460.         cpos = {cpos[1]+1,cpos[2]}
  461.         drawBuffer(n)
  462.         sleep(Time)
  463.     end
  464.     Pos = oldPos
  465. end
  466. function drawPixel(n,x,y,c,ctc,s)
  467.     local x = x or Pos[1]
  468.     local y = y or Pos[2]
  469.     local c = c or Bc
  470.     local Ctc = ctc or Tc
  471.     local cs = s or " "
  472.     ldrawPixel(n,x,y,c,Ctc,cs)
  473. end
  474. function drawBox(n,x1,y1,x2,y2,c,tc,s)
  475.     local y = 0
  476.     local x = 0
  477.     local c = c or Bc
  478.     local tc = tc or Tc
  479.     local s = s or " "
  480.     for y=y1,y2 do
  481.         for x=x1,x2 do
  482.             if x==x1 or y==y1 or x==x2 or y==y2 then
  483.                 drawPixel(n,x,y,c,tc,s)
  484.             end
  485.         end
  486.     end
  487. end
  488. function drawFilledBox(n,x1,y1,x2,y2,c,tc,s)
  489.     local y = 0
  490.     local x = 0
  491.     local c = c or Bc
  492.     local tc = tc or Tc
  493.     local s = s or " "
  494.     for y=y1,y2 do
  495.         for x=x1,x2 do
  496.             drawPixel(n,x,y,c,tc,s)
  497.         end
  498.     end
  499. end
  500. local tColorLookup = {}
  501. for n=1,16 do
  502.     tColorLookup[ string.byte("0123456789abcdef",n,n)] = 2^(n-1)
  503. end
  504. function loadImage(path)
  505.     local tImage = {}
  506.     if pcall(function ()
  507.         if fs.exists( path ) then
  508.             local file = io.open(path,"r")
  509.             local sLine = file:read()
  510.             while sLine do
  511.                 local tLine = {}
  512.                 for x=1,sLine:len() do
  513.                     tLine[x] = tColorLookup[string.byte(sLine,x,x)] or 0
  514.                 end
  515.                 table.insert(tImage,tLine)
  516.                 sLine = file:read()
  517.             end
  518.             file:close()
  519.             return true
  520.         end
  521.     end) then
  522.         return tImage
  523.     else
  524.         error("Attempt to load image failed: Buf:477-499, Image_Path:"..path,2)
  525.     end
  526. end
  527. function drawImage(n,xPos,yPos,tImage)
  528.     if pcall(function ()
  529.         if type(tImage)~="table" then
  530.             tImage = loadImage(tImage)
  531.         end
  532.         for y=1,#tImage do
  533.             local tLine = tImage[y]
  534.             for x=1,#tLine do
  535.                 if tLine[x] > 0 then
  536.                     ldrawPixel(n,x+xPos-1,y+yPos-1,tLine[x],Tc," ")
  537.                 end
  538.             end
  539.         end
  540.     end) then
  541.     else
  542.         error("Attempt to load image failed: Buf:477-498, Image_Path:"..tostring(path),2)
  543.     end
  544. end
  545. function loadImageASCII(path)
  546.     local tImage = {}
  547.     if fs.exists( path ) then
  548.         local file = io.open(path,"r")
  549.         local sLine = file:read()
  550.         while sLine do
  551.             local tLine = {}
  552.             for x=1,sLine:len() do
  553.                 tLine[x] = string.sub(sLine,x,x)
  554.             end
  555.             table.insert(tImage,tLine)
  556.             sLine = file:read()
  557.         end
  558.         file:close()
  559.         return tImage
  560.     end
  561. end
  562. function drawImageASCII(n,xPos,yPos,tImage,cbc,ctc)
  563.     Bc = cbc or Bc
  564.     Tc = ctc or Tc
  565.     local screen = buffer[n].screen
  566.     if type(tImage)~="table" then
  567.         tImage = loadImageASCII(tImage)
  568.     end
  569.     screen.setCursorPos(xPos,yPos)
  570.     for y=1,#tImage do
  571.         local tLine = tImage[y]
  572.         for x=1,#tLine do
  573.             ldrawPixel(n,x+xPos-1,y+yPos-1,Bc,Tc,tLine[x])
  574.         end
  575.     end
  576. end
  577. function drawLine(n,x1,y1,x2,y2,c,tc,s)
  578.     local x1 = math.floor(x1)
  579.     local x2 = math.floor(x2)
  580.     local y1 = math.floor(y1)
  581.     local y2 = math.floor(y2)
  582.     local tc = tc or Tc
  583.     local s = s or " "
  584.     local c = c or Bc
  585.     if x1==x2 and y1==y2 then
  586.         drawPixel(n,x1,y1,tc,s)
  587.         return
  588.     end
  589.     local minX = math.min(x1,x2)
  590.     if minX==x1 then
  591.         minY = y1
  592.         maxX = x2
  593.         maxY = y2
  594.     else
  595.         minY = y2
  596.         maxX = x1
  597.         maxY = y1
  598.     end
  599.     local xDiff = maxX - minX
  600.     local yDiff = maxY - minY
  601.     if xDiff > math.abs(yDiff) then
  602.         local y = minY
  603.         local dy = yDiff/xDiff
  604.         for x=minX,maxX do
  605.             drawPixel(n,x,math.floor(y+0.5),c,tc,s)
  606.             y = y+dy
  607.         end
  608.     else
  609.         local x = minX
  610.         local dx = xDiff/yDiff
  611.         if maxY>=minY then
  612.             for y=minY,maxY do
  613.                 drawPixel(n,math.floor(x+0.5),y,c,tc,s)
  614.                 x = x+dx
  615.             end
  616.         else
  617.             for y=minY,maxY,-1 do
  618.                 drawPixel(n,math.floor(x+0.5),y,c,tc,s)
  619.                 x = x-dx
  620.             end
  621.         end
  622.     end
  623. end
  624. function drawCircle(n,xc,yc,r,c) -- need to fix gaps
  625.     local x = 0
  626.     local y = r
  627.     local delta = 2-2*r
  628.     local Err = 0
  629.     local c = c or Bc
  630.     while y>=0 do
  631.         drawPixel(n,xc + x, yc + y, c) --1
  632.         drawPixel(n,xc - x, yc + y, c) --2
  633.         drawPixel(n,xc + x, yc - y, c) --3
  634.         drawPixel(n,xc - x, yc - y, c) --4
  635.         Err = 2 * (delta + y) - 1
  636.        
  637.         if delta < 0 and Err <= 0 then
  638.             x = x+1
  639.             delta = delta + 2 * x + 1
  640.         end
  641.        
  642.         Err = 2 * (delta - x) - 1
  643.        
  644.         if delta > 0 and Err > 0 then
  645.             y = y-1
  646.             delta = delta + 1 - 2 * y
  647.         end
  648.         x = x+1
  649.         delta = delta + 2 * (x - y)
  650.         y = y-1
  651.     end
  652. end
  653. function drawEllipse(n,xc,yc,w,h,c) --does not work
  654.     local w2  = w * w
  655.     local h2  = h * h
  656.     local fw2 = 4 * w2
  657.     local fh2 = 4 * h2
  658.     local xc = xc + w
  659.     local yc = yc + h
  660.  
  661.     local x  = 0
  662.     local y  = h
  663.     local s  = 2 * h2 + w2 * (1 - h)
  664.     while h2 * x <= w2 * y do
  665.         drawPixel(n,xc + x,yc + y,c)
  666.         drawPixel(n,xc - x, yc + y,c)
  667.         drawPixel(n,xc + x, yc - y,c)
  668.         drawPixel(n,xc - x, yc - y,c)
  669.         if s >= 0 then
  670.             s = s + fw2 * (1 - y)
  671.             y = y - 1
  672.         end
  673.         s = s + h2 * ((4 * x) + 6)
  674.         x = x + 1
  675.     end
  676.     local x = w
  677.     local y = 0
  678.     local s = 2 * w2 + h2 * (1 - w)
  679.     while w2 * y <= h2 * x do
  680.         drawPixel(n,xc + x, yc + y,c)
  681.         drawPixel(n,xc - x, yc + y,c)
  682.         drawPixel(n,xc + x, yc - y,c)
  683.         drawPixel(n,xc - x, yc - y,c)
  684.         if s >= 0 then
  685.             s = s + fh2 * (1 - x)
  686.             x = x - 1
  687.         end
  688.         s = s + w2 * ((4 * y) + 6)
  689.         y = y + 1
  690.     end
  691. end
  692. function drawTriagle(n,x1,y1,x2,y2,x3,y3,c)
  693.     local c = c or Bc
  694.     drawLine(n,x1,y1,x2,y2,c)
  695.     drawLine(n,x2,y2,x3,y3,c)
  696.     drawLine(n,x3,y3,x1,y1,c)
  697. end
  698. function drawPolygon(n,c, ...)
  699.     local arg = {...}
  700.     local xy = {}
  701.     if c==nil then
  702.         c=Bc
  703.     end
  704.     if #arg%2 ~= 0 then
  705.         return false
  706.     end
  707.     local pra = 1
  708.     for i=2,#arg+1,2 do
  709.         local l = {arg[pra],arg[pra+1]}
  710.         table.insert(xy,l)
  711.         pra = pra +2
  712.     end
  713.     if #xy==1 then
  714.         drawPixel(n,xy[1][1],xy[1][2],c)
  715.     elseif #xy==2 then
  716.         drawLine(n,xy[1][1],xy[1][2],xy[2][1],xy[2][2],c)
  717.     else
  718.         for i=1, #xy do
  719.             if i==#xy then
  720.                 drawLine(n,xy[i][1],xy[i][2],xy[1][1],xy[1][2],c)
  721.             else
  722.                 drawLine(n,xy[i][1],xy[i][2],xy[i+1][1],xy[i+1][2],c)
  723.             end
  724.         end
  725.     end
  726. end
  727. function drawBotton(n,x1,y1,sx,sy,c1,c2,s,c3) --(x,y,How dig x,how big y,color rim,color inside,w,color words)
  728.     drawFilledBox(n,x1,y1,x1+sx-1,y1+sy-1,c2)
  729.     drawBox(n,x1,y1,x1+sx-1,y1+sy-1,c1)
  730.     if s then
  731.         local oldPos = Pos
  732.         pos(math.floor(x1+(sx/2))-math.floor(#s/2),math.floor((y1+sy)/y1))
  733.         bWriteL(n,s,c3,c2)
  734.         pos(oldPos)
  735.     end
  736. end
  737. function createLoadbar(n2,x1,y1,x2,y2,bbc,fbc,p,ctc1,ctc2,t1,t2)
  738.     p = p or 0
  739.     ctc1 = ctc1 or Tc
  740.     ctc2 = ctc2 or Tc
  741.     t1 = t1 or " "
  742.     t2 = t2 or " "
  743.     local n = #lodingBar+1
  744.     lodingBar[n] = {x1,y1,x2,y2,bbc,fbc,p,ctc1,ctc2,t1,t2,n2}
  745.     return n
  746. end
  747. function drawLoadbar(n)
  748.     local bar = lodingBar[n]
  749.     if bar[2] == bar[4] then
  750.         drawLine(bar[12],bar[1],bar[2],bar[3],bar[4],bar[5],bar[8],bar[10])
  751.     else
  752.         drawFilledBox(bar[12],bar[1],bar[2],bar[3],bar[4],bar[5],bar[8],bar[10])
  753.     end
  754.     if bar[7]~=0 then
  755.         local lenght = bar[3]-bar[1]
  756.         local px = bar[1]+math.ceil((bar[7]*lenght)/100)
  757.         if bar[2] == bar[4] then
  758.             drawLine(bar[12],bar[1],bar[2],px,bar[4],bar[6],bar[9],bar[11])
  759.         else
  760.             drawFilledBox(bar[12],bar[1],bar[2],px,bar[4],bar[6],bar[9],bar[11])
  761.         end
  762.     end
  763. end
  764. function increnetLoadbar(n,p,draw,x2,y2) --draw if true will draw if false or nill will not
  765.     lodingBar[n][7] = tonumber(p)
  766.     if draw then
  767.         local x2 = x2 or 1
  768.         local y2 = y2 or 1
  769.         drawLoadbar(n)
  770.         drawBuffer(lodingBar[n][12],x2,y2)
  771.     else
  772.         drawLoadbar(n)
  773.     end
  774. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement