Hello!
I’m working on part two of my Pixelblaze & Lux Lavalier code tutorial, and trying to understand the ranges of values passed to and returned from the perlin function.
This code shows perlin returning numbers ranging from approx -0.5 to 0.5. Note that I’m using 0.01 for time just so the min and max vars that I’m watching (in the vars watch) update quicker.
export var min
export var max
export function beforeRender(delta) {
t = time(.01)
noiseSpeed = t * 256 // noise inputs range from 0 to 256?
w = perlin(noiseSpeed, 0, 0, 0)
if (w < min) min = w
if (w > max) max = w
w = w + 0.5 // perlin returns values ranging from -0.5 to 0.5? adjust them to 0.0 to 1.0
}
export function render2D(index, x, y) {
h = x - w
hsv(h, 1, 1)
}
That makes a 1D rainbow (vertical bands) that moves horizontally back and forth irregularly.
Question one: It works, but seems to freeze in place periodically, not sure why?
Then, when I try to make a 2D noise rainbow with this code, I get a different range of return values from perlin (-0.885971 to 0.772766):
export var min
export var max
export function beforeRender(delta) {
t = time(.01) // very slow sawtooth wave, every 458.752 seconds!
noiseSpeed = t * 256 // noise inputs range from 0 to 256
}
export function render2D(index, x, y) {
x2 = x + noiseSpeed
y2 = y
w = perlin(x2, y2, 0, 0)
if (w < min) min = w
if (w > max) max = w
w = (w * 1.1 + 1) / 2 // adjust the value to 0.0 to 1.0
h = w
hsv(h, 1, 1)
}
Question 2: what is the expected range of inputs and outputs, to and from the perlin noise function? Question 3: Why multiply noiseSpeed (ranging from 0.0 to 1.0) by 256? Wouldn’t that result in a range from 0 to 256? I would expect, if it’s a one byte range, that you’d multiply by 255 to get 0 to 255.
Any assistance would be greatly appreciated, thanks!