Skip to content

Instantly share code, notes, and snippets.

@michiel
Last active December 15, 2015 08:19
Show Gist options
  • Select an option

  • Save michiel/5230136 to your computer and use it in GitHub Desktop.

Select an option

Save michiel/5230136 to your computer and use it in GitHub Desktop.
Bezier functions in CoffeeScript
_bez1 = (pct)->
Math.pow pct, 3
_bez2 = (pct)->
3 * Math.pow(pct, 2) * (1-pct)
_bez3 = (pct)->
3 * pct * Math.pow (1-pct), 2
_bez4 = (pct)->
Math.pow (1-pct), 3
_point = (c1, c2, c3, c4, pct)->
x : c1.x * _bez1(pct) +
c2.x * _bez2(pct) +
c3.x * _bez3(pct) +
c4.x * _bez4(pct)
y : c1.y * _bez1(pct) +
c2.y * _bez2(pct) +
c3.y * _bez3(pct) +
c4.y * _bez4(pct)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment