Advertisement
QuicksilverBoy

numberAPI.lua

Jan 21st, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. local numAPI = {}
  2.  
  3. local component = require('component')
  4.  
  5. numAPI.numTable = {
  6.     [0] = {"a", "b", "c", "d", "e", "f"},
  7.     [1] = {"b", "c"},
  8.     [2] = {"a", "b", "d", "e", "g"},
  9.     [3] = {"a", "b", "c", "d", "g"},
  10.     [4] = {"b", "c", "f", "g"},
  11.     [5] = {"a", "c", "d", "f", "g"},
  12.     [6] = {"a", "c", "d", "e", "f", "g"},
  13.     [7] = {"a", "b", "c"},
  14.     [8] = {"a", "b" ,"c", "d", "e", "f", "g"},
  15.     [9] = {"a", "b", "c", "d", "f", "g"},
  16.     ["null"] = {}
  17. }
  18.  
  19. function numAPI.createNum(x, y, scal, colorOn, colorOff, cardOutput)
  20.     local x, y, scal = tonumber(x) or 1, tonumber(y) or 1, tonumber(scal) or 1
  21.  
  22.     local gpu
  23.  
  24.     if cardOutput == nil then
  25.         gpu = component.gpu
  26.     else
  27.         gpu = component.proxy(component.get(cardOutput))
  28.     end
  29.  
  30.     local dial = {
  31.         lamps = {a = false, b = false, c = false, d = false, e = false, f = false, g = false}, -- Сосотояние каждой пиксиля
  32.         posDials = { --Положение всех пиксилей
  33.             a = {x = x + 1, y = y, w = 2 + scal, h = 1},
  34.             b = {x = x + 3 + scal, y = y + 1, w = 1, h = 1 + scal},
  35.             c = {x = x + 3 + scal, y = y + 3 + scal, w = 1, h = 1 + scal},
  36.             d = {x = x + 1, y = y + 4 + (scal * 2), w = 2 + scal, h = 1},
  37.             e = {x = x, y = y + 3 + scal, w = 1, h = 1 + scal},
  38.             f = {x = x, y = y + 1, w = 1, h = 1 + scal},
  39.             g = {x = x + 1, y = y + 2 + scal, w = 2 + scal, h = 1}
  40.         },
  41.         colors = {[0] = colorOff, [1] = colorOn}, -- цвет включенной и выключеной пиксиля.
  42.         setNumber = function(di, num) --установить число
  43.             di.lamps = {a = false, b = false, c = false, d = false, e = false, f = false, g = false}
  44.             local sellectedNumber = numAPI.numTable[num]
  45.             for n = 1, #sellectedNumber do
  46.                 di.lamps[sellectedNumber[n]] = true
  47.             end
  48.             return true
  49.         end,
  50.         drawNum = function(di) --нарисовать число
  51.             for lamp in pairs(di.lamps) do
  52.                 if di.lamps[lamp] then
  53.                     gpu.setBackground(di.colors[1])
  54.                 else
  55.                     gpu.setBackground(di.colors[0])
  56.                 end
  57.                 gpu.fill(di.posDials[lamp].x, di.posDials[lamp].y, di.posDials[lamp].w, di.posDials[lamp].h, ' ')
  58.             end
  59.             gpu.setBackground(0)
  60.         end,
  61.     }
  62.     return dial
  63. end
  64.  
  65. return numAPI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement