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

[1.42][API]MultiColor Printer API (MCP)

Started by Orwell, 28 September 2012 - 12:24 PM
Orwell #1
Posted 28 September 2012 - 02:24 PM
The multicolor printer API (MCP)

Updated: This API can now be used in vanilla ComputerCraft 1.42. No need for BuildCraft anymore.

Description
This API manages the printing of multiple colors on one page. This is done be recycling the printed page trough the printer while changing dyes.

Usage
This is a turtle API. The turtle holds all 15 dyes (white would be useless in general) like shown in this picture:
Spoiler
You also need a correct setup. The point is that you have the turtle with a printer in front of it. The paper gets printed in one color and then gets cycled to the top slot again. By default the turtle moves to fetch the page out of the printer and put it back in on the top. This can very simply be altered (for example for RP/BC) by editing the functions at the top of the code.
The default setup looks as follows:
Spoiler
My API can be used like the term/monitor/printer API in computercraft. Here's a simple example:

os.loadAPI('MCP')
local page = MCP.newPage()
page.write('test', colors.red)
page.setCursorPos(1,2)
page.write('test', colors.blue)
page.print()

Practically; to actually print a page, make sure that before the printing of the page there's exactly one paper item in the upper slot of the printer. Also make sure that the ink slot of the printer is empty and that the turtle slots are filled with the dyes as layed out in the first image.

Screenshots
Only one for now. This is the output of the test program:
Spoiler

Downloads
API:
current version (v0.4):
Pastebin:
http://pastebin.com/RHKR8sj4
Can be downloaded in game by running this in the ComputerCraft terminal:
pastebin get RHKR8sj4 MCP

Test program:
http://pastebin.com/twzPbqj3
pastebin get twzPbqj3 MCP-test

Changelog
v0.4 (29 sept '12):
got rid of BuildCraft for paper cycling and made it vanilla (lead to a reasonable speed improvement)
added support for adding titles to pages
other minor tweaks
v0.3 (28 sept '12):
fixed removing the 'printer.newPage()' line
v0.2 (28 sept '12):
fixed an error on checking the dye level
v0.1 (28 sept '12):
release
Sebra #2
Posted 28 September 2012 - 06:31 PM
You can try to use turtle to move paper by removing white die. Is it needed really?
Cranium #3
Posted 28 September 2012 - 06:35 PM
You can try to use turtle to move paper by removing white die. Is it needed really?
Not unless you have a texture pack that changes the paper color.
Orwell #4
Posted 28 September 2012 - 07:11 PM
You can try to use turtle to move paper by removing white die. Is it needed really?
You can try to use turtle to move paper by removing white die. Is it needed really?
Not unless you have a texture pack that changes the paper color.

I was planning exactly that. But Cranium has a good point, which makes me doubt… I might just use a boolean to switch between the two… Anyways, adapting my API to move paper through RP/BC/vanilla is really the easy part for anyone. : )
stilldabomb #5
Posted 28 September 2012 - 09:46 PM
Uhm… It won't work for me XD. I'm using the MCP-test and it comes up with the error of "Out of dye in slot 1. MCP:121: Page not started"… The first slot in the turtle is full though…
Orwell #6
Posted 28 September 2012 - 10:48 PM
Uhm… It won't work for me XD. I'm using the MCP-test and it comes up with the error of "Out of dye in slot 1. MCP:121: Page not started"… The first slot in the turtle is full though…

Fixed. I kinda didn't pay attention when I changed something quick right before the upload. >.< It was a veeery stupid mistake. : ) I can't test it right now, but let me know. : )
stilldabomb #7
Posted 28 September 2012 - 11:16 PM
Ok, I'll switch back to 1.3.2 and test it real quick :P/>/>
stilldabomb #8
Posted 28 September 2012 - 11:18 PM
Oh yeah, and you might want to edit this,
pastebing get J6yGL7iH MCP
to
pastebin get J6yGL7iH MCP
Orwell #9
Posted 28 September 2012 - 11:20 PM
Oh yeah, and you might want to edit this,
pastebing get J6yGL7iH MCP
to
pastebin get J6yGL7iH MCP

Thanks. :P/>/>
Orwell #10
Posted 28 September 2012 - 11:31 PM
Version 0.3 available. I got the chance to test it again and apparently I removed the obvious function call 'printer.newPage()' >.< . Updated in version 0.3 .

EDIT: If the page cycled once and you got an an error saying that 'the page hasn't been started': your redstone engine probably isn't warmed up yet and the sleep(8) in cyclePage() will be too short.
stilldabomb #11
Posted 28 September 2012 - 11:40 PM
-snip-
EDIT: Haha, just noticed you changed it XD
stilldabomb #12
Posted 28 September 2012 - 11:42 PM
Orwell, you got a Skype?
Orwell #13
Posted 28 September 2012 - 11:42 PM
I found the problem, you're not making a new page each time!

	  for x=1,w do
		for y=1,h do
		  local pixel = page.image[y][x]
		  if pixel and pixel.color == v then
			printer.setCursorPos(x,y)
			printer.write(pixel.char)
		  end
		end
	  end
should be

	  for x=1,w do
		for y=1,h do
		  local pixel = page.image[y][x]
		  if pixel and pixel.color == v then
			printer.newPage()
			printer.setCursorPos(x,y)
			printer.write(pixel.char)
		  end
		end
	  end

That would be crazy expensive :P/>/> Cause you'd spend one dye for every pixel. I fixed it right before your post though. : ) You're right about the fact that there was a printer.newPage() missing though :D/>/> Try version 0.3, it worked for me without issues.

EDIT: No, no Skype I'm afraid. :/ I'm on IRC though?
stilldabomb #14
Posted 28 September 2012 - 11:44 PM
Aww, ok :/
stilldabomb #15
Posted 28 September 2012 - 11:48 PM
And you might want to set the sleep(8) to sleep(10) because It keeps giving the "Page not started" error because the page hasn't gone all the way yet.
stilldabomb #16
Posted 29 September 2012 - 12:07 AM
Orwell #17
Posted 29 September 2012 - 12:11 AM
And you might want to set the sleep(8) to sleep(10) because It keeps giving the "Page not started" error because the page hasn't gone all the way yet.
I believe 8 seconds work after the redstone engine has warmed up. I'm gonna try the transposer and tubes from RP, I believe they're faster.

Nice :P/>/> and thanks :D/>/>
Orwell #18
Posted 30 September 2012 - 12:42 AM
The MCP API got updated to version 0.4. Everything is done by the turtle itself now. So you just need vanilla ComputerCraft 1.42. The setup is now a turtle with a printer in front of it, a chest two blocks above the printer for input (fill this one with paper) and a chest two blocks below the printer to output printed pages to.
This change leads to a rather large speed improvement.

Test it out! Some feedback would be nice. : )

EDIT: Make sure that you're turtle is fueled if needed. Next version has a simple check so you know when it's not.