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

2D/3D printer

Started by columna1, 26 November 2012 - 03:29 PM
columna1 #1
Posted 26 November 2012 - 04:29 PM
2D/3D turtle printer

by:columna1





This is my first program that I have released on the computercraft forums.

I have spent a lot of time and effort making this and making it relatively bug free.

On this post i will include the printer program as well as some screenshots and 2 demo files to print






I know nitrogen fingers has a 3D printer but this was in the works before he released his.

I would Love to see what pictures you can make with this so please post pictures showing what you have made


First is the pictures
Spoiler

All of these have been printer by a turtle using my printing program.

Nyan cat!

computer 2d image
(can be printed two different ways)

computer 3d

Main menu

2D menu

3D menu




Next is the star of the show The printing program!

Spoiler
--[[ Made by columna1 Please dont claim as your own ]]--
plane = 0
line = {}
x = 0
selecteditem = 1
mainmenu = true
menu2d = false
menu3d = false
col = {
w = 1,
o = 2,
m = 3,
b = 4,
y = 5,
l = 6,
p = 7,
G = 8,
g = 9,
c = 10,
P = 11,
B = 12,
n = 13,
e = 14,
r = 15,
d = 16,
s = 20
}
--functions
function forward()
forw = true
while forw do
  if turtle.forward() then
   forw = false
  else
   turtle.dig()
   turtle.attack()
  end
end
end
function placeDown()
if turtle.getItemCount(selected) > 1 then
  turtle.placeDown()
else
  nom = true
  print("Enter material")
  while nom do
   sleep(1)
   if turtle.getItemCount(selected) > 1 then
	nom = false
	print("continuing")
	turtle.placeDown()
   end
  end
end
end
function place()
if turtle.getItemCount(selected) > 1 then
  turtle.place()
else
  nom = true
  print("Enter material")
  while nom do
   sleep(1)
   if turtle.getItemCount(selected) > 1 then
	nom = false
	print("continuing")
	turtle.place()
   end
  end
end
end
function printer()
sleep(0.1)
up = job.readLine()
for j = 1,tonumber(up) do
  curline = job.readLine()
  if x == 1 then
   curline = curline:reverse()
  end
  for i = 1,#curline do
   line[i] = curline:sub(i,i)
  end
  for i = 1,#line do
   if col[line[i]] == 20 then
	--no selecting
   else
	turtle.select(col[line[i]])
	selected = col[line[i]]
   end
   if plane == 0 then
	if col[line[i]] == 20 then
	 --no placing
	else
	 placeDown()
	end
	forward()
   else
	if x == 0 then
	 if col[line[i]] == 20 then
	  --no placing
	 else
	  place()
	 end
	 turtle.turnRight()
	 forward()
	 turtle.turnLeft()
	elseif x == 1 then
	 if col[line[i]] == 20 then
	  --no placing
	 else
	  place()
	 end
	 turtle.turnLeft()
	 forward()
	 turtle.turnRight()
	end
   end
  end
  if plane == 0 then
   if x == 0 then
	turtle.turnRight()
	forward()
	turtle.turnRight()
	forward()
	x = 1
   elseif x == 1 then
	turtle.turnLeft()
	forward()
	turtle.turnLeft()
	forward()
	x = 0
   end
  else
   if x == 0 then
	turtle.down()
	turtle.turnLeft()
	forward()
	turtle.turnRight()
	x = 1
   elseif x == 1 then
	turtle.down()
	turtle.turnRight()
	forward()
	turtle.turnLeft()
	x = 0
   end
  end
end
end
function exit()
main = false
term.clear()
term.setCursorPos(1,1)
print("Thanks for using Columna1's printer")
end
function face()
plane = 1
end
function d3()
  sleep(0.1)
  selecteditem = 1
  menu3d = true
  while menu3d do
	term.clear()
	term.setCursorPos(1,1)
	printmenu(menu3)
	event,key = os.pullEvent("key")
	onkeypress(key,menu3)
  end
end
function d2()
  selecteditem = 1
  menu2d = true
  while menu2d do
	term.clear()
	term.setCursorPos(1,1)
	printmenu(menu2)
	event,key = os.pullEvent("key")
	onkeypress(key,menu2)
  end
end
function exit3d()
  selecteditem = 1
  menu3d = false
  selecteditem = 1
end
function exit2d()
  selecteditem = 1
  menu2d = false
  selecteditem = 1
end
function print3d()
	sleep(0.1)
x = 0
if tip then
  files = job.readLine()
  job.close()
  for k = 1,tonumber(files) do
   job = fs.open(timp.."_"..k,"r")
   printer()
   if #curline %2 == 0 then
	turtle.turnLeft()
	for h = 1,#curline do
	 forward()
	end
	turtle.turnRight()
	turtle.up()
   else
	turtle.turnRight()
	for h = 1,#curline do
	 forward()
	 end
	turtle.turnLeft()
	for h = 1,#curline-1 do
	 forward()
	end
	turtle.turnLeft()
	turtle.turnLeft()
	turtle.up()
   end
   job.close()
   x = 0
   tip = nil
  end
else
  print("No file Entered")
  sleep(1)
end
end
function print2d()
x = 0
if tipe then
  printer()
  tipe = nil
else
  print("No file entered")
  sleep(1)
end
end
function enter3d()
print("Enter file prefix")
timp = read()
if fs.exists(timp) then
  job = fs.open(timp,"r")
  tip = job.readLine()
  if tip == "3d" then
   -- over with
  else
   print("Not a 3d file")
   sleep(1)
  end
else
  print("invalid file")
  tip = nil
  sleep(1)
end
end
function enter2d()
print("Enter filename")
local temp = read()
if fs.exists(temp) then
  job = fs.open(temp,"r")
  tipe = job.readLine()
  if tipe == "2d" then
	--another comment to do nothing
  else
   print("Not a 2d file")
   sleep(1)
  end
else
  print("invalid file")
  tipe = nil
  sleep(1)
end
end
menu = {
[1] = {text = "2D",handler = d2},
[2] = {text = "3D",handler = d3},
[3] = {text = "Exit",handler = exit}
}
menu2 = {
[1] = {text = "Enter filename",handler = enter2d},
[2] = {text = "Print",handler = print2d},
[3] = {text = "Plane y",handler = face},
[4] = {text = "Main menu",handler = exit2d}
}
menu3 = {
[1] = {text = "Enter filename",handler = enter3d},
[2] = {text = "Print",handler = print3d},
[3] = {text = "Main menu",handler = exit3d}
}
--printmenu
function printmenu(menu)
  for i = 1,#menu do
	if i == selecteditem then
	  print("[[ "..menu[i].text.." ]]")
	else
	  print("   "..menu[i].text.."   ")
	end
  end
end
--handlers
function onkeypress(key,menu)
  if key == keys.enter then
	onitemselected(menu)
  elseif key == keys.up then
	if selecteditem > 1 then
	  selecteditem = selecteditem - 1
	end
  elseif key == keys.down then
	if selecteditem < #menu then
	  selecteditem = selecteditem + 1
	end
  end
end
function onitemselected(menu)
  menu[selecteditem].handler()
end
--main
function main()
  while main do
	term.clear()
	term.setCursorPos(1,1)
	printmenu(menu)
	event,key = os.pullEvent()
	onkeypress(key,menu)
  end
end
main()

Next is the demo print files

Spoiler3D computer (yes you need all the files)
Spoilername comp

3d
16
name comp_1

16
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
dddddddddddddddd
name comp_2

16
dggggggggggggggd
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
dggggggggggggggd
name comp_3

16
dggggggggggggggd
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
dgggggggggggddgd
name comp_4

16
dggggggggggggggd
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
dggggggggggggggd
name comp_5

16
dggggggggggggggd
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
dgddddddddddddgd
name comp_6

16
dggggggggggggggd
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
dgddddddddddddgd
name comp_7

16
dggggggggggggggd
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
gssssssssssssssg
dgddddddddddddgd
name comp_8

16
dGGGGGGGGGGGGGGd
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
dGddddddddddddGd
name comp_9

16
dGGGGGGGGGGGGGGd
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
dGddddddddddddGd
name comp_10

16
dGGGGGGGGGGGGGGd
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
dGddddddddddddGd
name comp_11

16
dGGGGGGGGGGGGGGd
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
dGdwddddddddddGd
name comp_12

16
dGGGGGGGGGGGGGGd
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
dGddwdddddddddGd
name comp_13

16
dGGGGGGGGGGGGGGd
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
dGdwddddddddddGd
name comp_14

16
dGGGGGGGGGGGGGGd
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
dGddddddddddddGd
name comp_15

16
dGGGGGGGGGGGGGGd
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
GssssssssssssssG
dGGGGGGGGGGGGGGd
name comp_16

16
dddddddddddddddd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dGGGGGGGGGGGGGGd
dddddddddddddddd

Now for the 2D file
Spoilerjust 1 file this time


2d
16
dddddddddddddddd
dGGGGGGGGGGGGGGd
dGddddddddddddGd
dGdwddddddddddGd
dGddwdddddddddGd
dGdwddddddddddGd
dGddddddddddddGd
dGddddddddddddGd
dGddddddddddddGd
dgddddddddddddgd
dgddddddddddddgd
dgddddddddddddgd
dggggggggggggggd
dgggggggggggddgd
dggggggggggggggd
dddddddddddddddd

How to make a file to print
Spoiler3D:
first you make a file that is the prefix and then put something like this into it ie test

3d
5
3d is the file type and 5 is the number of files(layers) that it will print
Next for 3d you make the files test_1 through test_5 and in them you put sonething like this


3
wdw
dwd
wdw
the 3 tells how many lines there are in the file and the rest is the actual picture which ill tell you how to make later



Next is the 2D files

this one is simple just make a file and put something like this into it


2d
3
dwd
wdw
dwd
the 2d is declairing what type of file it is
the 3 tells how many lines there are in the file
and the rest is the actual pic


How to make the pics

This should be easy to figure out so ill just give a list of the colors and what letters they are represented by

w = white
o = orange
m = magenta
b = lightblue
y = yellow
l = lime
p = pink
G = grey
g = lightgrey
c = cyan
P = purple
B = blue
n = brown
e = green
r = red
d = black
s = space

Now for links

To get the printer program from pastebin go to
http://pastebin.com/7R2rvCEf

to get all the demo files easily get this program and run it
http://pastebin.com/T91JUu4w

EDIT: I just realized that i forgot to say how to load the turtle. lol
- To load the turtle you just grab the colors out of the creative menu and stick them in the same order that they are in in the menu the same goes for NEI or TMI.

Thank you for Viewing my post and a like/upvote is appreciated :D/>
ErolDude #2
Posted 05 July 2013 - 05:08 AM
Awesome! Why did no body see this coolyness? :rolleyes:/>
hazard1nc #3
Posted 07 July 2013 - 04:15 AM
nice! that is a great program!
Cutecurtain #4
Posted 11 July 2013 - 07:13 AM
This is really cool! ;)/>
goldensecret #5
Posted 14 April 2014 - 01:04 PM
id love to be able to get a Turtle built with this, awesome job!
columna1 #6
Posted 14 April 2014 - 02:20 PM
Thank you Everyone. This was the first thing I released and It never got much attention.
Edited on 23 April 2014 - 12:14 PM