kaplay
kaplay copied to clipboard
feat: A random noise component
Most games need a way to generate number in a smooth manner. while you can do this with an external solutions like noisejs and others, i think a native solution would be nice.
explation
some thing like this
type NoiseType = "perlin"
type NoiseOpt = {
type?: NoiseType
seed?: number
step?: number
roughness?: number
}
function noise(opts?: NoiseOpt): NoiseComp
interface NoiseComp extends Comp {
rand(stepBy?: number): number
randVec(stepBy?: number): vec2
randColor(stepBy?: number): Color
}
it keep a private state of the position. and the steps are how much to move it after a noise is generated.
example
an example of how this might be used
randomly changing an object's color:
const obj = k.add([
k.rect(16, 16),
k.color(),
k.noise()
])
k.onUpdate(() => obj.color = obj.randColor(k.dt()))
alternatives
using components might not be the most ideal so maybe making it just a normal class might be more appropriate.
const noise = new k.NoiseGenerator()
noise.rand()
or maybe make it a global function like
k.perlinRand(somePosition)
this would be pretty cool
this is probably good plugin material