Skip to content

Instantly share code, notes, and snippets.

@ciju
Created April 25, 2022 18:48
Show Gist options
  • Save ciju/30d0fe5da990ae4e15662ec07cd50fb9 to your computer and use it in GitHub Desktop.
Save ciju/30d0fe5da990ae4e15662ec07cd50fb9 to your computer and use it in GitHub Desktop.
line smoothing
const blur1 = (data) =>
data.map((d, i) => {
const previous = i === 0 ? i : i - 1;
const next = i === data.length - 1 ? i : i + 1;
const sum = (data[previous] || 0) + d + (data[next] || 0);
d = sum / 3;
return d;
});
const twice = (fn) => (x) => fn(fn(x));
const fourTimes = (fn) => twice(twice(fn));
const sixtyfourTimes = (fn) => fourTimes(fourTimes(fn));
const blur = (x) => sixtyfourTimes(blur1)(x);
export default blur;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment