Can anyone find anything wrong with the noise function code below? As the following image shows, the noise seems to flatten out after the y loop passes 22 or 23. The bitwise.bit_xor function is from Carlos’ “bitwise operators in lua” module posted on the code exchange here: http://developer.anscamobile.com/code/bitwise-operators-lua
My code:
[lua]–Initialization
display.setStatusBar( display.HiddenStatusBar )
local bitwise = require “bitwise”
local n
local function noise(x, y)
n = x + y * 47
n = bitwise.bit_xor(n * math.pow(2, 13), n)
n = (n * (n * n * 15731 + 789221) + 1376312589)
n = n % 2147483648
n = n / 1073741824
n = 1 - n
–n = ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) % 2147483648) / 1073741824.0)
return n
end
local squares = {}
for x = 1, 100, 1 do
squares[x] = {}
for y = 1, 100, 1 do
squares[x][y] = display.newRect(x * 5 - 5, y * 5 - 5, 5, 5)
squares[x][y]:setFillColor(noise(x, y) * 100)
end
end[/lua]
The output mysteriously settles to “1” after a short while:
[import]uid: 99903 topic_id: 24697 reply_id: 324697[/import]

