From 2902201388a11eade8117edf52848971eb8085b2 Mon Sep 17 00:00:00 2001 From: Darius Auding <darius.auding@teckids.org> Date: Sun, 22 Dec 2024 15:40:32 +0100 Subject: [PATCH] rework placment logic --- tree.lua | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tree.lua b/tree.lua index 7785048..1a33372 100644 --- a/tree.lua +++ b/tree.lua @@ -1,11 +1,21 @@ +-- NUR DURCH 4 TEILBARE ZAHLEN > 20 VERWENDEN!!! local leds = { - 32, - 28, - 16, - 8, - 4, + 64, + 56, + 48, + 36, + 20, } +for i = 1, #leds do + if leds[i] % 4 ~= 0 then + error("[ledtree] led count per layer must be divisible by 4. Error location: 'leds' table, item "..i..": "..leds[i]) + end + if leds[i] < 20 then + error("[ledtree] led count per layer must be greater than or qual to 20. Error location: 'leds' table, item "..i..": "..leds[i]) + end +end + local height_increment = 3 local function breite(n) @@ -28,13 +38,13 @@ local function place_layer(center, breite) breite = breite * 2 + 1 local needles = {} local leds = {} - local max_offset = math.ceil(breite / 2) - for y = -height_increment / 2, height_increment / 2 do + local max_offset = math.floor(breite / 2) + for y = math.ceil(-height_increment / 2), math.floor(height_increment / 2) do for x = -max_offset, max_offset do for z = -max_offset, max_offset do local pos = vector.new({x = center.x + x, y = center.y + y, z = center.z + z}) table.insert(needles, pos) - if is_led(center, breite, pos) then + if y == 0 and is_led(center, breite, pos) then table.insert(leds, pos) end end -- GitLab