Advertisement
TangentFox

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

Sep 22nd, 2018 (edited)
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.66 KB | None | 0 0
  1. -- finds the number of pseudo-random vectors the LÖVE engine uses for its noise function
  2. -- (256 is the answer by the way, as expected)
  3. local results = { }
  4. local sequence_found = false
  5. local check
  6. check = function(results)
  7.   local j = math.floor(#results / 2)
  8.   for i = 1, j do
  9.     j = j + 1
  10.     print(results[i], results[j], results[i] == results[j])
  11.     if results[i] ~= results[j] then
  12.       return false
  13.     end
  14.   end
  15.   return true
  16. end
  17. local i = 0.5
  18. table.insert(results, love.math.noise(i))
  19. i = i + 1
  20. while not sequence_found do
  21.   table.insert(results, love.math.noise(i))
  22.   sequence_found = check(results)
  23.   i = i + 1
  24. end
  25. return print(#results/2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement