mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-14 02:34:12 +02:00
use scad
This commit is contained in:
21
src/pixel/_impl/_px_from_impl.scad
Normal file
21
src/pixel/_impl/_px_from_impl.scad
Normal file
@@ -0,0 +1,21 @@
|
||||
function _px_from_row(r_count, row_bits, width, height, center, invert) =
|
||||
let(
|
||||
half_w = width / 2,
|
||||
half_h = height / 2,
|
||||
offset_x = center ? 0 : half_w,
|
||||
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_impl(binaries, center, invert) =
|
||||
let(
|
||||
width = len(binaries[0]),
|
||||
height = len(binaries),
|
||||
offset_i = height / 2
|
||||
)
|
||||
[
|
||||
for(i = height - 1; i > -1; i = i - 1)
|
||||
let(row = _px_from_row(height - i - 1, binaries[i], width, height, center, invert))
|
||||
if(row != []) each row
|
||||
];
|
@@ -8,24 +8,6 @@
|
||||
*
|
||||
**/
|
||||
|
||||
function _px_from_row(r_count, row_bits, width, height, center, invert) =
|
||||
let(
|
||||
half_w = width / 2,
|
||||
half_h = height / 2,
|
||||
offset_x = center ? 0 : half_w,
|
||||
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]];
|
||||
use <pixel/_impl/_px_from_impl.scad>;
|
||||
|
||||
function px_from(binaries, center = false, invert = false) =
|
||||
let(
|
||||
width = len(binaries[0]),
|
||||
height = len(binaries),
|
||||
offset_i = height / 2
|
||||
)
|
||||
[
|
||||
for(i = height - 1; i > -1; i = i - 1)
|
||||
let(row = _px_from_row(height - i - 1, binaries[i], width, height, center, invert))
|
||||
if(row != []) each row
|
||||
];
|
||||
function px_from(binaries, center = false, invert = false) = _px_from_impl(binaries, center, invert);
|
Reference in New Issue
Block a user