This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
soccer16x's profile picture

Printing Help?

Started by soccer16x, 29 January 2013 - 01:14 PM
soccer16x #1
Posted 29 January 2013 - 02:14 PM
Okay, so what i am trying to do is make a box. Sounds simple right? But what im looking for is the easiest way to print out a box, but with using term.setBackgroundColor I do not know how I can print a vertical line very easily other than having tons of lines of code that are just print(" ") so I was basically wondering if anyone can help me with getting an easier way to print out a vertical line that i can use to finish up my box, since writing a horizontal line is quite easy i just dont know how to do a vertical one.
tesla1889 #2
Posted 29 January 2013 - 02:22 PM
use a for loop to print vertical bars

for n = 1,4
do print("|	 stuff in box	 |")
end
Grim Reaper #3
Posted 29 January 2013 - 02:32 PM
use a for loop to print vertical bars

for n = 1,4
do print("|	 stuff in box	 |")
end

If you're just trying to draw a vertical line, then the code above may not do the trick.

This code here should help, assuming that you've wrapped your pinter peripheral:

local printer = peripheral.wrap(--[[ Printer side --]])
local pageWidth, pageHeight = printer.getPageSize()

-- Draws a vertical line on the page.
function printVerticalLine(verticalChar, page_xPos, startingLine, endingLine)

    local current_printerX, current_printerY = printer.getCursorPos()
    
    for line = startingLine, endingLine do
	    printer.setCursorPos(page_xPos, line)
	    printer.write(verticalChar)
    end
    
    -- Reset the cursor.
    printer.setCursorPos(current_printerX, current_printerY)

end

You will need to adpat the above function to your own code. You just need to have the printer wrapped and your ink set and all other necessities of using a printer peripheral.
soccer16x #4
Posted 29 January 2013 - 02:41 PM
Oh um, sorry by "print" I meant like write out on the screen, and im trying to draw it where like its just a line going down the screen from say, y 2 to y 40 and from your code i dont know how i'd implement that in a computer setting not a printing one.

use a for loop to print vertical bars

for n = 1,4
do print("|	 stuff in box	 |")
end

and this i do not believe would work because i need to print things inside as well, but every few lines whats inside changes so that wouldn't work i do not think.
Grim Reaper #5
Posted 29 January 2013 - 04:05 PM
Oh um, sorry by "print" I meant like write out on the screen, and im trying to draw it where like its just a line going down the screen from say, y 2 to y 40 and from your code i dont know how i'd implement that in a computer setting not a printing one.

use a for loop to print vertical bars

for n = 1,4
do print("|	 stuff in box	 |")
end

and this i do not believe would work because i need to print things inside as well, but every few lines whats inside changes so that wouldn't work i do not think.

Sorry for the misunderstanding.


function printVerticalLine(lineX, startingY, endingY, lineColor)

    local currentX, currentY = term.getCursorPos()
    term.setBackgroundColor(lineColor)
    
    for lineY = startingY, endingY do
	    term.setCursorPos(lineX, lineY)
	    term.write(' ')
    end
    
    -- Reset the cursor.
    term.setCursorPos(currentX, currentY)

end
soccer16x #6
Posted 29 January 2013 - 04:25 PM
It's okay, and thanks for the help, I really appreciate it.
Mvf314 #7
Posted 30 January 2013 - 04:05 AM
You can use the paintutils API:


paintutils.drawLine(startX,startY,endX,endY,color)

For example, you can do:


x,y = term.getSize()
paintutils.drawLine(1,1,1,y,colors.white)
paintutils.drawLine(x,1,x,y,colors.white)

Here are your vertical lines!
soccer16x #8
Posted 30 January 2013 - 09:02 AM
Oh wow thats a lot easier, but oh well already implemented Grim Reaper's code and fit it to work for drawing the lines, but thanks