Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: A random noise component #618

Open
hinum opened this issue Feb 25, 2025 · 1 comment
Open

feat: A random noise component #618

hinum opened this issue Feb 25, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@hinum
Copy link
Contributor

hinum commented Feb 25, 2025

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)
@hinum hinum added the enhancement New feature or request label Feb 25, 2025
@niceEli
Copy link
Member

niceEli commented Feb 26, 2025

this would be pretty cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

2 participants