mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 14:56:47 +02:00
change levels format
This commit is contained in:
@@ -3,34 +3,26 @@ function _px_gray_row(r_count, row_bits, width, height, center, invert) =
|
|||||||
half_w = width / 2,
|
half_w = width / 2,
|
||||||
half_h = height / 2,
|
half_h = height / 2,
|
||||||
offset_x = center ? 0 : half_w,
|
offset_x = center ? 0 : half_w,
|
||||||
offset_y = center ? 0 : half_h,
|
offset_y = center ? -half_h : 0,
|
||||||
level = invert ? 0 : 255
|
level = invert ? 0 : 255
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
for(i = 0; i < width; i = i + 1)
|
for(i = 0; i < width; i = i + 1)
|
||||||
if(row_bits[i] != level)
|
if(row_bits[i] != level)
|
||||||
[
|
[
|
||||||
i - half_w + offset_x,
|
[i - half_w + offset_x, r_count + offset_y],
|
||||||
r_count + offset_y,
|
|
||||||
invert ? row_bits[i] / 255 : 1 - row_bits[i] / 255
|
invert ? row_bits[i] / 255 : 1 - row_bits[i] / 255
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
function px_gray(levels, size, center = false, invert = false) =
|
function px_gray(levels, center = false, invert = false) =
|
||||||
let(
|
let(
|
||||||
squar = sqrt(len(levels)),
|
width = len(levels[0]),
|
||||||
siz = is_undef(size) ? [squar, squar] : size,
|
height = len(levels),
|
||||||
width = siz[0],
|
|
||||||
height = siz[1],
|
|
||||||
rows = [
|
|
||||||
for(row = height - 1; row > -1; row = row - 1)
|
|
||||||
[for(column = 0; column < width; column = column + 1)
|
|
||||||
levels[row * width + column]]
|
|
||||||
],
|
|
||||||
offset_i = height / 2
|
offset_i = height / 2
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
for(i = 0; i < height; i = i + 1)
|
for(i = height - 1; i > -1; i = i - 1)
|
||||||
let(row = _px_gray_row(i - offset_i, rows[i], width, height, center, invert))
|
let(row = _px_gray_row(height - i - 1, levels[i], width, height, center, invert))
|
||||||
if(row != []) each row
|
if(row != []) each row
|
||||||
];
|
];
|
Reference in New Issue
Block a user