From f2a214e61af00b887808656b4e2d09132ce472a7 Mon Sep 17 00:00:00 2001 From: Valansch Date: Tue, 11 Sep 2018 17:39:09 +0200 Subject: [PATCH] Implemented Mask.blurr --- Diggy/Mask.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Diggy/Mask.lua b/Diggy/Mask.lua index 5f30c629..af6819a9 100644 --- a/Diggy/Mask.lua +++ b/Diggy/Mask.lua @@ -1,6 +1,42 @@ -- this local Mask = {} + + local blurrFilters = {} + blurrFilters[5] = { + {0.003765, 0.015019, 0.023792, 0.015019, 0.003765}, + {0.015019, 0.059912, 0.094907, 0.059912, 0.015019}, + {0.023792, 0.094907, 0.150342, 0.094907, 0.023792}, + {0.015019, 0.059912, 0.094907, 0.059912, 0.015019}, + {0.003765, 0.015019, 0.023792, 0.015019, 0.003765} + } + local n = 5; + + +--[[-- + Applies a blurr filter. + + @param x_start number, center point + @param y_start number, center point + @param factor relative strengh of the entity to withstand the pressure + factor < 0 if entity is placed + factor > 0 if entity is removed number + @param callback function to execute on each tile within the mask callback(x, y, value) +]] +function Mask.blurr(x_start, y_start, factor, callback) + local filter = blurrFilters[n] + local offset = - math.floor(n / 2) - 1 --move matrix over x_start|y_start and adjust for 1 index + for x = 1, n do + for y = 1, n do + cell = filter[x][y] + value = factor * cell + callback(x_start + x + offset, y_start + y + offset, value) + end + end +end + + + --[[-- Masks in the shape of a circle.