summaryrefslogtreecommitdiff
path: root/img
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-12-31 04:00:32 +0000
committerubq323 <ubq323@ubq323.website>2022-12-31 04:00:32 +0000
commitb80ac71d55c6d782f0b8272ee232f7ea10c71528 (patch)
tree6f0715d9d7dbed9bcb987a4ceaa1e112bfb1b283 /img
parent5f227122324816312620dbe9a0a5ac336591c504 (diff)
3d print of image
Diffstat (limited to 'img')
-rw-r--r--img/blahaj.ppmbin0 -> 2896 bytes
-rw-r--r--img/print.lua52
2 files changed, 52 insertions, 0 deletions
diff --git a/img/blahaj.ppm b/img/blahaj.ppm
new file mode 100644
index 0000000..ffdb895
--- /dev/null
+++ b/img/blahaj.ppm
Binary files 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