diff --git a/init.lua b/init.lua index e6cd6ba..15cec17 100644 --- a/init.lua +++ b/init.lua @@ -346,9 +346,24 @@ local analyze_noiseparams = function(noiseparams) local o_min, o_max = 0, 0 for o=1, np.octaves do local exp = o-1 - o_max = o_max + (1 * np.persistence ^ exp) + -- Calculate the two possible extreme values + -- with the octave value being either at 1 or -1. + local limit1 = (1 * np.persistence ^ exp) + local limit2 = (-1 * np.persistence ^ exp) + + -- To add to the maximum, pick the higher value + if limit1 > limit2 then + o_max = o_max + limit1 + else + o_max = o_max + limit2 + end if not is_absolute then - o_min = o_min + (- 1 * np.persistence ^ exp) + -- To add to the minimum, pick the LOWER value + if limit1 > limit2 then + o_min = o_min + limit2 + else + o_min = o_min + limit1 + end -- Note: If absvalue flag is set, the sum of the octaves -- is always 0, so we don't need to calculate it end