TangentFox icon

Calculating period of love.math.noise in 1 dimension.lua

TangentFox | PRO | 11/21/23 02:32:52 AM UTC (Edited) | 0 ⭐ | 946 👁️ | Never ⏰ | []
Lua |

660 B

|

None

|

0 👍

/

0 👎

-- finds the number of pseudo-random vectors the LÖVE engine uses for its noise function
-- (256 is the answer by the way, as expected)
local results = { }
local sequence_found = false
local check
check = function(results)
  local j = math.floor(#results / 2)
  for i = 1, j do
    j = j + 1
    print(results[i], results[j], results[i] == results[j])
    if results[i] ~= results[j] then
      return false
    end
  end
  return true
end
local i = 0.5
table.insert(results, love.math.noise(i))
i = i + 1
while not sequence_found do
  table.insert(results, love.math.noise(i))
  sequence_found = check(results)
  i = i + 1
end
return print(#results/2)

Comments