From 6c570ef757bbc596ba30c9242c9009df7fadc04d Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 25 Aug 2019 17:56:34 +0800 Subject: [PATCH] size is not necessary --- src/pixel/px_from.scad | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/pixel/px_from.scad b/src/pixel/px_from.scad index 8c3429db..57b23fbc 100644 --- a/src/pixel/px_from.scad +++ b/src/pixel/px_from.scad @@ -13,26 +13,19 @@ function _px_from_row(r_count, row_bits, width, height, center, invert) = half_w = width / 2, half_h = height / 2, offset_x = center ? 0 : half_w, - offset_y = center ? 0 : half_h, + offset_y = center ? -half_h : 0, bit = invert ? 0 : 1 ) [for(i = 0; i < width; i = i + 1) if(row_bits[i] == bit) [i - half_w + offset_x, r_count + offset_y]]; -function px_from(binaries, size, center = false, invert = false) = +function px_from(binaries, center = false, invert = false) = let( - squar = sqrt(len(binaries)), - siz = is_undef(size) ? [squar, squar] : size, - width = siz[0], - height = siz[1], - rows = [ - for(row = height - 1; row > -1; row = row - 1) - [for(column = 0; column < width; column = column + 1) - binaries[row * width + column]] - ], + width = len(binaries[0]), + height = len(binaries), offset_i = height / 2 ) [ - for(i = 0; i < height; i = i + 1) - let(row = _px_from_row(i - offset_i, rows[i], width, height, center, invert)) + for(i = height - 1; i > 0; i = i - 1) + let(row = _px_from_row(height - i - 1, binaries[i], width, height, center, invert)) if(row != []) each row ]; \ No newline at end of file