Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local numAPI = {}
- local component = require('component')
- numAPI.numTable = {
- [0] = {"a", "b", "c", "d", "e", "f"},
- [1] = {"b", "c"},
- [2] = {"a", "b", "d", "e", "g"},
- [3] = {"a", "b", "c", "d", "g"},
- [4] = {"b", "c", "f", "g"},
- [5] = {"a", "c", "d", "f", "g"},
- [6] = {"a", "c", "d", "e", "f", "g"},
- [7] = {"a", "b", "c"},
- [8] = {"a", "b" ,"c", "d", "e", "f", "g"},
- [9] = {"a", "b", "c", "d", "f", "g"},
- ["null"] = {}
- }
- function numAPI.createNum(x, y, scal, colorOn, colorOff, cardOutput)
- local x, y, scal = tonumber(x) or 1, tonumber(y) or 1, tonumber(scal) or 1
- local gpu
- if cardOutput == nil then
- gpu = component.gpu
- else
- gpu = component.proxy(component.get(cardOutput))
- end
- local dial = {
- lamps = {a = false, b = false, c = false, d = false, e = false, f = false, g = false}, -- Сосотояние каждой пиксиля
- posDials = { --Положение всех пиксилей
- a = {x = x + 1, y = y, w = 2 + scal, h = 1},
- b = {x = x + 3 + scal, y = y + 1, w = 1, h = 1 + scal},
- c = {x = x + 3 + scal, y = y + 3 + scal, w = 1, h = 1 + scal},
- d = {x = x + 1, y = y + 4 + (scal * 2), w = 2 + scal, h = 1},
- e = {x = x, y = y + 3 + scal, w = 1, h = 1 + scal},
- f = {x = x, y = y + 1, w = 1, h = 1 + scal},
- g = {x = x + 1, y = y + 2 + scal, w = 2 + scal, h = 1}
- },
- colors = {[0] = colorOff, [1] = colorOn}, -- цвет включенной и выключеной пиксиля.
- setNumber = function(di, num) --установить число
- di.lamps = {a = false, b = false, c = false, d = false, e = false, f = false, g = false}
- local sellectedNumber = numAPI.numTable[num]
- for n = 1, #sellectedNumber do
- di.lamps[sellectedNumber[n]] = true
- end
- return true
- end,
- drawNum = function(di) --нарисовать число
- for lamp in pairs(di.lamps) do
- if di.lamps[lamp] then
- gpu.setBackground(di.colors[1])
- else
- gpu.setBackground(di.colors[0])
- end
- gpu.fill(di.posDials[lamp].x, di.posDials[lamp].y, di.posDials[lamp].w, di.posDials[lamp].h, ' ')
- end
- gpu.setBackground(0)
- end,
- }
- return dial
- end
- return numAPI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement