From b80ac71d55c6d782f0b8272ee232f7ea10c71528 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 31 Dec 2022 04:00:32 +0000 Subject: 3d print of image --- img/blahaj.ppm | Bin 0 -> 2896 bytes img/print.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 img/blahaj.ppm create mode 100644 img/print.lua diff --git a/img/blahaj.ppm b/img/blahaj.ppm new file mode 100644 index 0000000..ffdb895 Binary files /dev/null and b/img/blahaj.ppm differ diff --git a/img/print.lua b/img/print.lua new file mode 100644 index 0000000..f6bcef7 --- /dev/null +++ b/img/print.lua @@ -0,0 +1,52 @@ +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) + 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) + + -- 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,{ + 2*offx, 14-2*offy, 15, + 2*offx+2, 16-2*offy, 16, + texture="sc-peripherals:block/white", + tint=c2c(img[py][px]) + }) + end + end + printer.addShapes(shapes) + printer.setTooltip("("..tilex..","..tiley..")") + +end + +-- 0... +for tilex = 1, math.ceil(W/8) do + for tiley = 1, math.ceil(H/8) do + print_tile(tilex,tiley) + end +end -- cgit v1.2.3