View difference between Paste ID: 3dc5HJDJ and x7CQPbZH
SHOW: | | - or go back to the newest paste.
1-
os = require("os")
1+
os = require("os")
2-
term = require("term")
2+
term = require("term")
3-
component = require("component")
3+
component = require("component")
4-
4+
5-
gpu = component.gpu
5+
gpu = component.gpu
6-
6+
7-
function throwError(errorMessage)
7+
function throwError(errorMessage)
8-
  gpu.setResolution(gpu.maxResolution())
8+
  gpu.setResolution(gpu.maxResolution())
9-
  gpu.setForeground(0xff0000)
9+
  gpu.setForeground(0xff0000)
10-
  gpu.setBackground(0x000000)
10+
  gpu.setBackground(0x000000)
11-
  term.clear()
11+
  term.clear()
12-
  print("The program ran into a serious error during execution.")
12+
  print("The program ran into a serious error during execution.")
13-
  print(errorMessage)
13+
  print(errorMessage)
14-
  gpu.setForeground(0xffffff)
14+
  gpu.setForeground(0xffffff)
15-
  os.exit()
15+
  os.exit()
16
end
17-
17+
18-
function addRect(x1,y1,x2,y2,color)
18+
function addRect(x1,y1,x2,y2,color)
19-
  temp = gpu.getBackground()
19+
  temp = gpu.getBackground()
20-
  gpu.setBackground(color)
20+
  gpu.setBackground(color)
21-
  gpu.fill(x1,y1,x2-x1+1,y2-y1+1," ")
21+
  gpu.fill(x1,y1,x2-x1+1,y2-y1+1," ")
22-
  gpu.setBackground(temp)
22+
  gpu.setBackground(temp)
23
end
24-
24+
25-
function addProgressBar(x1,y1,x2,y2,sideWidth,sideHeight,borderColor,filledBarColor,emptyBarColor,textColor,headerText,filledPercentage,isSideways,isInverted)
25+
function addProgressBar(x1,y1,x2,y2,sideWidth,sideHeight,borderColor,filledBarColor,emptyBarColor,textColor,headerText,filledPercentage,isSideways,isInverted)
26-
  isSideways = isSideways or false
26+
  isSideways = isSideways or false
27-
  isInverted = isInverted or false
27+
  isInverted = isInverted or false
28-
  if type(x1)~="number" then throwError("addProgressBar() argument 1 (x1) type int expected, "..type(x1).." found") end
28+
  if type(x1)~="number" then throwError("addProgressBar() argument 1 (x1) type int expected, "..type(x1).." found") end
29-
  if type(x2)~="number" then throwError("addProgressBar() argument 3 (x2) type int expected, "..type(x2).." found") end
29+
  if type(x2)~="number" then throwError("addProgressBar() argument 3 (x2) type int expected, "..type(x2).." found") end
30-
  if type(y1)~="number" then throwError("addProgressBar() argument 2 (y1) type int expected, "..type(y1).." found") end
30+
  if type(y1)~="number" then throwError("addProgressBar() argument 2 (y1) type int expected, "..type(y1).." found") end
31-
  if type(y2)~="number" then throwError("addProgressBar() argument 4 (y2) type int expected, "..type(y2).." found") end
31+
  if type(y2)~="number" then throwError("addProgressBar() argument 4 (y2) type int expected, "..type(y2).." found") end
32-
  if type(sideWidth)~="number" then throwError("addProgressBar() argument 5 (sideWidth) type int expected, "..type(sideWidth).." found") end
32+
  if type(sideWidth)~="number" then throwError("addProgressBar() argument 5 (sideWidth) type int expected, "..type(sideWidth).." found") end
33-
  if type(sideHeight)~="number" then throwError("addProgressBar() argument 6 (sideHeight) type int expected, "..type(sideHeight).." found") end
33+
  if type(sideHeight)~="number" then throwError("addProgressBar() argument 6 (sideHeight) type int expected, "..type(sideHeight).." found") end
34-
  if type(filledPercentage)~="number" then throwError("addProgressBar() argument 11 (filledPercentage) type float expected, "..type(filledPercentage).." found") end
34+
  if type(filledPercentage)~="number" then throwError("addProgressBar() argument 11 (filledPercentage) type float expected, "..type(filledPercentage).." found") end
35-
  
35+
  if filledPercentage > 1 then filledPercentage = 1 end
36-
  if isSideways == false then
36+
  if isSideways == false then
37-
    addRect(x1,y1,x2,y2,borderColor)
37+
    addRect(x1,y1,x2,y2,borderColor)
38-
    addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y2-sideHeight,emptyBarColor)
38+
    addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y2-sideHeight,emptyBarColor)
39-
    barSize = (y2-y1-2*sideHeight)
39+
    barSize = (y2-y1-2*sideHeight)
40-
    pixelsFilled = math.floor(filledPercentage*barSize+0.5)
40+
    pixelsFilled = math.floor(filledPercentage*barSize+0.5)
41-
    if isInverted == false then
41+
    if isInverted == false then
42-
      addRect(x1+sideWidth,y2-sideHeight-pixelsFilled,x2-sideWidth,y2-sideHeight,filledBarColor)
42+
      addRect(x1+sideWidth,y2-sideHeight-pixelsFilled,x2-sideWidth,y2-sideHeight,filledBarColor)
43-
    elseif isInverted == true then
43+
    elseif isInverted == true then
44-
      addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y1+sideHeight+pixelsFilled,filledBarColor)
44+
      addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y1+sideHeight+pixelsFilled,filledBarColor)
45-
    else
45+
    else
46-
      throwError("addProgressBar() argument 13 (isInverted) type boolean expected, "..type(isInverted).." found")
46+
      throwError("addProgressBar() argument 13 (isInverted) type boolean expected, "..type(isInverted).." found")
47-
    end
47+
    end
48-
  elseif isSideways == true then
48+
  elseif isSideways == true then
49-
    addRect(x1,y1,x2,y2,borderColor)
49+
    addRect(x1,y1,x2,y2,borderColor)
50-
    addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y2-sideHeight,emptyBarColor)
50+
    addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y2-sideHeight,emptyBarColor)
51-
    barSize = (x2-x1-2*sideWidth)
51+
    barSize = (x2-x1-2*sideWidth)
52-
    pixelsFilled = math.floor(filledPercentage*barSize+0.5)
52+
    pixelsFilled = math.floor(filledPercentage*barSize+0.5)
53-
    if isInverted == false then
53+
    if isInverted == false then
54-
      addRect(x1+sideWidth,y1+sideHeight,x1+sideWidth+pixelsFilled,y2-sideHeight,filledBarColor)
54+
      addRect(x1+sideWidth,y1+sideHeight,x1+sideWidth+pixelsFilled,y2-sideHeight,filledBarColor)
55-
    elseif isInverted == true then
55+
    elseif isInverted == true then
56-
      addRect(x2-sideWidth-pixelsFilled,y1+sideHeight,x2-sideWidth,y2-sideHeight,filledBarColor)
56+
      addRect(x2-sideWidth-pixelsFilled,y1+sideHeight,x2-sideWidth,y2-sideHeight,filledBarColor)
57-
    else
57+
    else
58-
      throwError("addProgressBar() argument 13 (isInverted) type boolean expected, "..type(isInverted).." found")
58+
      throwError("addProgressBar() argument 13 (isInverted) type boolean expected, "..type(isInverted).." found")
59-
    end
59+
    end
60-
  else
60+
  else
61-
    throwError("addProgressBar() argument 12 (isSideways) type boolean expected, "..type(isSideways).." found")
61+
    throwError("addProgressBar() argument 12 (isSideways) type boolean expected, "..type(isSideways).." found")
62-
  end
62+
  end
63-
  if sideHeight>0 then
63+
  if sideHeight>0 then
64-
    col = {f = gpu.getForeground(),b = gpu.getBackground()}
64+
    col = {f = gpu.getForeground(),b = gpu.getBackground()}
65-
    centerX = math.ceil((x1+x2)/2)
65+
    centerX = math.ceil((x1+x2)/2)
66-
    centerY = math.floor(y1+sideHeight/2)
66+
    centerY = math.floor(y1+sideHeight/2)
67-
    gpu.setForeground(textColor)
67+
    gpu.setForeground(textColor)
68-
    gpu.setBackground(borderColor)
68+
    gpu.setBackground(borderColor)
69-
    gpu.set(centerX-(string.len(tostring(headerText))/2),centerY,tostring(headerText))
69+
    gpu.set(centerX-(string.len(tostring(headerText))/2),centerY,tostring(headerText))
70-
    gpu.setForeground(col.f)
70+
    gpu.setForeground(col.f)
71-
    gpu.setBackground(col.b)
71+
    gpu.setBackground(col.b)
72-
    centerX = nil
72+
    centerX = nil
73-
    centerY = nil
73+
    centerY = nil
74-
    col = nil
74+
    col = nil
75-
  end
75+
  end
76
end