Closed jwagner closed 2 years ago
@mreinstein @redblobgames this is not quite ready yet but I'd love to get your input on the API :)
I very much want to try this! I was travelling and catching up now, haven't had a chance.
I agree that noise2DFunction and noise2D are different enough that they shouldn't have the same name. Another possible name for noiseFunction: makeNoise2D or createNoise2D. That way instead of saying what it is ("Function") the name says what it does ("Make" or "Create" the "noise2D" function).
Ok, I tried it, I like it! With a bare bones program, minified but not gzipped:
I also tested with mapgen4. The build went from 185619 bytes to 181892 bytes (before gzip).
Are you thinking of including a convenience wrapper as a default export?
export class SimplexNoise {
constructor(random: RandomFn = Math.random) {
this.noise2D = noiseFunction2D(random);
this.noise3D = noiseFunction3D(random);
this.noise4D = noiseFunction4D(random);
}
}
export default SimplexNoise;
(not sure how to handle the alea part in a wrapper, as it means we'd have to import alea even when we're not using it; maybe that's ok with tree shaking?)
If you're not distributing alea, I think you can drop alea.md.
I feel like a verb makeNoise2D()
(makeX suggests that it will return X) would look nicer than a noun noiseFunction2D()
.
This new api looks so clean and pure! 🍀 Call the noise constructor, and you have a noise function. I can't imagine a simpler api.
LGTM, nice work @jwagner
Thank you @mreinstein . :) I'm currently working on a little demo and possibly a tutorial to go along with 4.0 and then I think it's good to release.
@redblobgames looks like using the pure annotation enables tree shaking without having to move the consts inside of the closure. Thanks for the challenge. :)
// TODO: insert typescript related rant here
:)
@mreinstein @redblobgames the release is done! Thanks a lot for your comments and support. It gave me to motivation needed to release this. I really appreciate it. :)
Release plan