Skip to content

Instantly share code, notes, and snippets.

@jniac
Last active May 30, 2020 09:08
Show Gist options
  • Save jniac/5e31fb66cf2569a85457988de3a9cac4 to your computer and use it in GitHub Desktop.
Save jniac/5e31fb66cf2569a85457988de3a9cac4 to your computer and use it in GitHub Desktop.
function ScreenScalar(props = { p1:1, p2:1 }) {
const compute = () => this.value = 1 - Object.values(props).reduce((r, v) => r * (1 - v), 1)
compute()
for (const key of Object.keys(props)) {
Object.defineProperty(this, key, {
get: () => props[key],
set: value => {
props[key] = value
compute()
},
})
}
}
@jniac
Copy link
Author

jniac commented May 29, 2020

"Screen" aka the blend mode

value === 0 if every prop values are 0

usage

const fx = new ScreenScalar({ foo:.5, bar:.5 })
console.log(fx.value) // .75
fx.foo = 0
console.log(fx.value) // .5
fx.bar = 0
console.log(fx.value) // 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment