Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- c= require("component")
- computer= require("computer")
- event= require("event")
- os= require("os")
- term = require("term")
- gpu= c.gpu
- h= c.hologram
- printer= c.printer3d;printer.reset()
- screenWidth,screenHeight=gpu.getResolution()
- screenToggled=false
- curx,cury,curz=1,1,1
- curstate=0
- figStartX,figStartY,figStartZ=0,0,0
- texture="command_block"
- h.clear()
- function intro()
- print("move cursor by arrow keys, w s layer up/down")
- print("space- start drawing model. second time for end.")
- print("t to enter name of texture.")
- print("q exit. c clear screen. p print")
- end
- function swap(incrx,incry,incrz)
- h.set(curx,cury,curz,curstate)
- curx,cury,curz=curx+incrx,cury+incry,curz+incrz
- --printvars()
- if figStartX~=0 then
- local fillStartX,fillStartY,fillStartZ=figStartX,figStartY,figStartZ
- local fillEndX,fillEndY,fillEndZ=curx,cury,curz
- --print("fillSX="..fillStartX.." fsY"..fillStartY.."fsZ"..fillStartZ)
- --print("fillEX="..fillEndX.." feY"..fillEndY.."feZ"..fillEndZ)
- if figStartX>curx then fillStartX=curx;fillEndX=figStartX end
- if figStartY>cury then fillStartY=cury;fillEndY=figStartY end
- if figStartZ>curz then fillStartZ=curz;fillEndZ=figStartZ end
- for i=fillStartX,fillEndX do
- for j=fillStartZ,fillEndZ do
- for k=fillStartY,fillEndY do
- h.set(i,k,j,2)
- end
- end
- end
- end
- curstate=h.get(curx,cury,curz)
- h.set(curx,cury,curz,1)
- end
- function moveForward()
- if curx<16 then
- swap(1,0,0)
- else computer.beep(1500,0.1) end
- end
- function moveBack()
- if curx>1 then
- swap(-1,0,0)
- else computer.beep(1500,0.1) end
- end
- function moveLeft()
- if curz>1 then
- swap(0,0,-1)
- else computer.beep(1500,0.1) end
- end
- function moveRight()
- if curz<16 then
- swap(0,0,1)
- else computer.beep(1500,0.1) end
- end
- function layerUp()
- if cury<16 then
- swap(0,1,0)
- else computer.beep(1500,0.1) end
- end
- function layerDown()
- if cury>1 then
- swap(0,-1,0)
- else computer.beep(1500,0.1) end
- end
- function mark()
- if figStartX==0 then
- figStartX,figStartY,figStartZ=curx,cury,curz
- swap(0,0,0)
- os.sleep(1)
- else
- local fillStartX,fillStartY,fillStartZ=figStartX,figStartY,figStartZ
- local fillEndX,fillEndY,fillEndZ=curx,cury,curz
- if figStartX>curx then fillStartX=curx;fillEndX=figStartX end
- if figStartY>cury then fillStartY=cury;fillEndY=figStartY end
- if figStartZ>curz then fillStartZ=curz;fillEndZ=figStartZ end
- local result, reason = printer.addShape(fillStartX-1, fillStartY-1, fillStartZ-1, fillEndX, fillEndY, fillEndZ, texture)
- if not result then
- print("Failed adding shape: " .. tostring(reason))
- end
- figStartX,figStartY,figStartZ=0,0,0
- curx,cury,curz=1,1,1
- -- swap(0,0,0)
- os.sleep(1)
- end
- end
- function printme()
- printer.setLabel("KelLiN block")
- printer.setTooltip("Printed with KelLiN software")
- local result, reason = printer.commit(1)
- if result then
- print("Job successfully committed!")
- else
- print("Failed committing job: " .. tostring(reason))
- gpu.setResolution(screenWidth,screenHeight)
- h.clear()
- os.exit()
- end
- end
- function toggleScreen()
- if screenToggled then
- gpu.setResolution(screenWidth,screenHeight)
- screenToggled=false
- intro()
- else
- gpu.setResolution(1,1)
- screenToggled=true
- end
- end
- function printvars()
- print("---------------------")
- print("curx="..curx.."; cury="..cury.."curz="..curz)
- print("figStartX"..figStartX.." figStartY"..figStartY.." figStartZ"..figStartZ)
- end
- --test keys
- --os.sleep(1);print(event.pull("key_down"))
- intro()
- swap(0,0,0)
- while true do
- _,_,key1,key2=event.pull("key_down")
- if key2==19 then term.clear();toggleScreen();--r
- elseif key2==20 then print("input texture name")texture=io.read();--t
- elseif key2==46 then term.clear();intro();--c
- elseif key2==16 then term.clear();h.clear();os.exit();--q
- elseif key2==200 then moveForward();--up arrow
- elseif key2==208 then moveBack();--down arrow
- elseif key2==203 then moveLeft();--left arrow
- elseif key2==205 then moveRight();--right arrow
- elseif key2==17 then layerUp();--w
- elseif key2==31 then layerDown();--s
- elseif key2==57 then mark();--space
- elseif key2==25 then printme();intro();--p
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment