Created
April 25, 2022 18:48
-
-
Save ciju/30d0fe5da990ae4e15662ec07cd50fb9 to your computer and use it in GitHub Desktop.
line smoothing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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