#1
Posted 08 July 2016 - 04:07 PM
http://pastebin.com/Nu5kBxHH
That is my progam. Thanks for looking at my post.
#2
Posted 08 July 2016 - 04:18 PM
divide the currentPower/maxPower. This should return a number 0-1, and it can be multiplied by 100 to get a percent. (basically you're just getting the percent and not multiplying it, though)
Take the number which is 0-1 and times it by the size of the progress bar. For example, if the size of it you wanted was 51 (the size of a computer), you would do 51*(number, 0-1), and floor it(math.floor) to get a whole number.
Draw a line (paintutils.drawLine) from the start of the progress bar to the start of the progress bar(-1?) + the whole number. You may have to subtract one form the start to make it work better, however that may involve a bit of testing. If you would like you may also make a line the size of the whole progress bar.
#3
Posted 08 July 2016 - 04:27 PM
Twijn, on 08 July 2016 - 04:18 PM, said:
You can easily draw a horizontal line without paintutils, just set the background colour to the colour of the line and term.write(" ") as many times as the line's length is in pixels.
#4
Posted 08 July 2016 - 05:24 PM
CrazyPyroEagle, on 08 July 2016 - 04:27 PM, said:
Twijn, on 08 July 2016 - 04:18 PM, said:
You can easily draw a horizontal line without paintutils, just set the background colour to the colour of the line and term.write(" ") as many times as the line's length is in pixels.
#5
Posted 08 July 2016 - 05:24 PM
term.setBackgroundColour(colours.white)
term.write((" "):rep(math.floor(progress / maxProgress) * barWidth))
Edited by Lemmmy, 08 July 2016 - 05:25 PM.
#6
Posted 08 July 2016 - 06:01 PM
#7
Posted 08 July 2016 - 11:52 PM
minz1, on 08 July 2016 - 06:01 PM, said:
Have you checked the background / foreground colours and the cursor position? term.write does not line-wrap the text (unlike write).
#8
Posted 09 July 2016 - 01:50 AM
Show us the code you used if you're still stuck.
#9
Posted 09 July 2016 - 03:35 AM
Like this
mon = peripheral.wrap(monSide) --Wraps the peripheral oldTerm = term.redirect(mon) --Redirects the term while storing the old term in a variable named oldTerm coloredPortion = math.floor((currentPower/maxPower) * width) --Calculates the width of the colored portion paintutils.drawLine(startX, y, startX + width, y, barColor) --Draws the bar paintutils.drawLine(startX,y,startX + coloredPortion, coloredPart) --Draws the colored portion over the bar term.redirect(oldTerm) --Sets the term back to normal
However if you have an irrational aversion to paintutils like myself or you don't want to redirect the term, you can create your own draw line method like this
function drawLine(x,y,length,color) --Defines the function
oldBgColor = term.getBackgroundColor() --Gets the current background color
for i = x, (length + x) do --Starts a for loop starting at x and ending when x gets to x + length
term.setCursorPos(i,y) --Set the cursor position to i,y
term.setBackgroundColor(color) --Set the background color to the color
term.write(" ") --Write that color to the screen
end
term.setBackgroundColor(oldBgColor) --Reset the background color
end
Of course should you decide to use this function you would have to tweak the first block of code. Just change the paintutils.drawLine() functions to this.
drawLine(startX, y, width, barColor) --Draws the bar drawLine(startX, y, coloredPortion, coloredPart) --Draws the colored part over the bar
There you go, hope I could help.
#10
Posted 09 July 2016 - 05:32 AM
PossieTV, on 09 July 2016 - 03:35 AM, said:
Like this
mon = peripheral.wrap(monSide) --Wraps the peripheral oldTerm = term.redirect(mon) --Redirects the term while storing the old term in a variable named oldTerm coloredPortion = math.floor((currentPower/maxPower) * width) --Calculates the width of the colored portion paintutils.drawLine(startX, y, startX + width, y, barColor) --Draws the bar paintutils.drawLine(startX,y,startX + coloredPortion, coloredPart) --Draws the colored portion over the bar term.redirect(oldTerm) --Sets the term back to normal
However if you have an irrational aversion to paintutils like myself or you don't want to redirect the term, you can create your own draw line method like this
function drawLine(x,y,length,color) --Defines the function
oldBgColor = term.getBackgroundColor() --Gets the current background color
for i = x, (length + x) do --Starts a for loop starting at x and ending when x gets to x + length
term.setCursorPos(i,y) --Set the cursor position to i,y
term.setBackgroundColor(color) --Set the background color to the color
term.write(" ") --Write that color to the screen
end
term.setBackgroundColor(oldBgColor) --Reset the background color
end
Of course should you decide to use this function you would have to tweak the first block of code. Just change the paintutils.drawLine() functions to this.
drawLine(startX, y, width, barColor) --Draws the bar drawLine(startX, y, coloredPortion, coloredPart) --Draws the colored part over the bar
There you go, hope I could help.
http://pastebin.com/mj9TXeBu
Line 4 to line 10 is your drawline function, and line 58 to line 60 is the actual drawing of the line.
#11
Posted 09 July 2016 - 06:01 AM
Edited by PossieTV, 09 July 2016 - 06:40 AM.
#12
Posted 10 July 2016 - 03:20 PM
Bomb Bloke, on 09 July 2016 - 01:50 AM, said:
Actually I think Lemmmy performed the multiplication after the floor (instead of before), therefore the floor is always 0 unless if 100% is achieved.
minz1, on 08 July 2016 - 06:01 PM, said:
Fixed code for a manual progress bar:
term.setBackgroundColour(colours.white)
term.write((" "):rep(math.floor(progress / maxProgress * barWidth)))
Edited by CrazyPyroEagle, 10 July 2016 - 03:22 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











