package.path="/?;/?.lua;"..package.path local printer = peripheral.wrap"right" local load_pnm = require"load_pnm".load local file,err = io.open(arg[1],"rb") if err then error("io.open: "..err) end local ff = file:read("a") local img = load_pnm(ff) local W,H = img.width, img.height local function c2c(col) local r = math.floor(col[1]*255) local g = math.floor(col[2]*255) local b = math.floor(col[3]*255) return b + 0x100*g + 0x10000*r end local function print_tile(tilex,tiley) print("tile ",tilex,tiley) local tilex0 = tilex-1 local tiley0 = tiley-1 local xm = (8*tilex0)+1 local ym = (8*tiley0)+1 local xM = math.min(W,xm+7) local yM = math.min(H,ym+7) print(" x from ",xm,"to",xM) print(" y from ",ym,"to",yM) -- really i should have called this u and v instead of x and y. joker emoji printer.reset() shapes = {} for px = xm,xM do for py = ym,yM do local offx = px-xm local offy = py-ym table.insert(shapes,{ 14-2*offx, 14-2*offy, 15, 16-2*offx, 16-2*offy, 16, texture="sc-peripherals:block/white", tint=c2c(img[py][px]) }) end end printer.addShapes(shapes) printer.setTooltip("("..tilex..","..tiley..")") printer.commit(1) end -- 0... for tilex = 1, math.ceil(W/8) do for tiley = 1, math.ceil(H/8) do print_tile(tilex,tiley) os.pullEvent"3d_printer_complete" end end