Hi there,
I'm having problems with the built-in noise generator. I've managed to generate an image, so it's working ok I guess, but the parameters are not affecting the result.
No matters what values I assign to the
frequency,
amplitude,
lacunarity and
persistence, I always get the same result, which makes me think that I'm not using it in the right way.
Here's the code, any help would be very appreciated.
Thanks in advance!
Global w as integer = 512
Global h as integer = 512
Global z as integer = 512
map = CreateSprite(generateperlinimage())
SetFolder( "" )
SetFolder( "/media" )
SaveImage( map, "Noise.png" )
do
sync()
loop
// --------------------------------------------------------------
function generateperlinimage()
frequency as float = 5.0 // Frequency (width) of the first octave of noise e.g. 1.0
amplitude as float = 5.0 // Amplitude (height) of the first octave of noise e.g. 1.0
lacunarity as float = 10 // Lacunarity specifies the frequency multiplier between successive octaves e.g. 2.0
persistence as float = 0.1 // Persistence is the loss of amplitude between successive octaves (usually 1/lacunarity)
scale as float = 100.0
SetupNoise(frequency, amplitude, lacunarity, persistence)
// Generate image from memblock
size = w * h * 4 + 12
mem = CreateMemblock(size)
SetMemblockInt(mem, 0, w)
SetMemblockInt(mem, 4, h)
SetMemblockInt(mem, 8, 32)
offset as integer = 12
for y = 0 to h - 1
for x = 0 to w - 1
noise = 255.0 * GetNoiseXYZ(x/scale, y/scale, z/scale)
noise = abs(noise)
SetMemblockByte(mem, offset, noise)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
offset = offset + 4
next
next
map = CreateImageFromMemblock(mem)
endfunction map