Advertisement
superkh

Graph

Oct 12th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. --Vars-------------------------------------------------------------------
  2. local w,h = term.getSize()
  3. local rng = true
  4. --buffer
  5. local buffer = buf.createBuffer(w,h)
  6. --Graphs
  7. local Graphs = {}
  8. local Cvertex = {math.floor(w/2),math.floor(h/2)}
  9. ----------------------------------------------------------------------
  10. local function setupGraph(Xs,Ys,Vx,Vy,Scale) -- X screen, Y screen, X vertex, Y vertex, Bc color, Scale = Add later
  11.     local Xs = Xs or w
  12.     local Ys = Ys or h
  13.     local Vx = Vx or math.floor(w/2)
  14.     local Vy = Vy or math.floor(h/2)
  15.     table.insert(Graphs,{})
  16.     local n = #Graphs
  17.     for y=1, Ys do
  18.         table.insert(buffer[n],{})
  19.         for x=1, Xs do
  20.             local i = {1,32768," "}
  21.             table.insert(buffer[n][Ys],i)
  22.         end
  23.     end
  24.     return n
  25. end
  26. local function drawCrass(Vx,Vy,Bc,Cc) --vertex
  27.     local Vx = Vx or math.floor(w/2)
  28.     local Vy = Vy or math.floor(h/2)
  29.     local Bc = Bc or colors.white
  30.     local CC = Cc or colors.blue
  31.     buf.clsB(buffer,Bc)
  32.     for y=1,h,2 do
  33.         if 0 < Vx and Vx <= 52 then
  34.             buf.drawPixel(buffer,Vx,y,Cc)
  35.         end
  36.     end
  37.     for x=1,w,2 do
  38.         if 0 < Vy and Vy <= 19 then
  39.             buf.drawPixel(buffer,x,Vy,Cc)
  40.         end
  41.     end
  42. end
  43.  
  44. local function main()
  45.     drawCrass()
  46.     buf.drawBuffer(buffer)
  47.     term.setTextColor(colors.black)
  48.     while rng do
  49.         local args = { os.pullEvent() }
  50.         if args[1] == "terminate" then
  51.             rng = false
  52.         end
  53.     end
  54.     return true
  55. end
  56. local ok, err = pcall(main)
  57. if not ok then
  58.     term.setBackgroundColor(colors.white)
  59.     term.clear()
  60.     term.setCursorPos(1,1)
  61.     term.setTextColor(colors.black)
  62.     write(err)
  63.     sleep(5)
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement