{deck}
version:1
card:0
size:[512,342]
name:"ease.deck"

{fonts}
deckbuilder:"%%[encoded data, 12424 characters]"

{card:home}
script:"home.0"
{widgets}
field1:{"type":"field","size":[241,36],"pos":[148,23],"locked":1,"font":"deckbuilder","border":0,"style":"plain","align":"center","value":"Easing Functions"}
c:{"type":"canvas","size":[188,170],"pos":[66,150],"border":0,"image":"%%IMG2ALwAqgD/AP8AuQ0EALMNDgCsDRMAqA0WAKQNGgChDR0Ang0gAJsNIwCYDQsACg0QAJYNCgAPDQ8AlA0JABINDwCRDQgAFg0QAI0NCQAYDRAAig0JABsNFACEDQgAHg0TAIINCAAgDRMAgA0JACINEQAlAQEAWg0IACUNDwAlAQEAWQ0IACkNCwAmAQEAWQ0IACsNCAAnAQEAWA0IAFsBAQBYDQgAWwEBAFcNCABcAQEAVw0IAFwBAQBWDQgAXQEBAFYNCABdAQEAVQ0IAF4BAQBVDQgAXgEBAFUNBwBfAQEAVA0IAF8BAQBUDQgAXwEBAFMNCABgAQEAUw0IAGABAQBTDQcAYQEBAFINCABhAQEAUg0IAGEBAQBSDQcAYgEBAFENCABiAQEAUQ0IAGIBAQBRDQcAYwEBAFANCABjAQEAUA0IAGMBAQBQDQcAZAEBAE8NCABkAQEATw0IAGQBAQBPDQcAZQEBAE4NCABlAQEATg0IAGUBAQBODQcAZgEBAE4NBwBmAQEATQ0IAGYBAQBNDQgAZgEBAE0NBwBnAQEATA0IAGcBAQBMDQgAZwEBAEwNBwBoAQEATA0HAGgBAQBLDQgAaAEBAEsNCABoAQEASw0HAGkBAQBLDQcAaQEBAEoNCABpAQEASg0IAGkBAQBKDQcAagEBAEoNBwBqAQEASQ0IAGoBAQBJDQgAagEBAEkNBwBrAQEASQ0HAGsBAQBJDQcAawEBAEgNCABrAQEASA0IAGsBAQBIDQcAbAEBAEgNBwBsAQEARw0IAGwBAQBHDQgAbAEBAEcNBwBtAQEARw0HAG0BAQBHDQcAbQEBAEYNCABtAQEARg0IAG0BAQBGDQcAbgEBAEYNBwBuAQEARg0HAG4BAQBFDQgAbgEBAEUNCABuAQEARQ0HAG8BAQBFDQcAbwEBAEQNCABvAQEARA0IAG8BAQBEDQcAcAEBAEQNBwBwAQEARA0HAHABAQBDDQgAcAEBAEMNCABwAQEAQw0HAHEBAQBDDQcAcQEBAEINCABxAQEAQg0IAHEBAQBCDQcAcgEBAEINBwByAQEAQg0HAHIBAQBBDQgAcgEBAEENCAByAQEAQQ0HAHMBAQBBDQcAcwEBAEANCABzAQEAQA0IAHMBAQBADQcAdAEBAD8NCAB0AQEAPw0IAHQBAQA/DQcAdQEBAD8NBwB1AQEAPg0IAHUBAQA+DQgAdQEBAD4NBwB2AQEAPQ0IAHYBAQA9DQgAdgEBAD0NBwB3AQEAPA0IAHcBAQA8DQgAdwEBADwNBwB4AQEAPA0HAHgBAQA7DQgAeAEBADsNCAB4AQEAOw0HAHkBAQA6DQgAeQEBADoNCAB5AQEAOQ0IAHoBAQA5DQgAegEBADkNBwB7AQEAOA0IAHsBAQA4DQgAewEBADgNBwB8AQEANw0IAHwBAQA3DQgAfAEBADYNCAB9AQEANg0IAH0BAQA2DQcAfgEBADUNCAB+AQEANQ0IAH4BAQA0DQgAfwEBADQNCAB/AQEAMw0IAH8NAQEBDQcALA0IAH4NAgEBDQkAKQ0IAH4NAwEBDQwAJQ0JAH4NAwGVACQNFAAgDQgAgQ0UAB4NCQCCDRUAGw0JAIoNEAAZDQgAjQ0QABYNCACRDQ8AEg0KAJMNDwAPDQoAlg0QAAoNCwCYDSMAmw0gAJ4NHQChDRoApA0WAKgNEwCsDQ4Asw0EAP8A/wC4","scale":1}
names:{"type":"grid","size":[180,136],"pos":[278,134],"locked":1,"script":"home.1","scrollbar":1,"headers":1,"lines":0,"value":{"Function Name":["lerp","inSine","outSine","inOutSine","inQuad","outQuad","inOutQuad","inCubic","outCubic","inOutCubic","inQuart","outQuart","inOutQuart","inQuint","outQuint","inOutQuint","inExpo","outExpo","inOutExpo","inCirc","outCirc","inOutCirc","inBack","outBack","inOutBack","inElastic","outElastic","inOutElastic","inBounce","outBounce","inOutBounce"]},"scroll":18,"row":24}
usage:{"type":"field","size":[180,40],"pos":[278,280],"locked":1,"value":{"text":["usage:\n\n  ","ease.inOutBack[time a b]"],"font":["","mono"],"arg":["",""]}}
field2:{"type":"field","size":[392,57],"pos":[66,65],"locked":1,"value":" Easing functions smoothly interpolate from one value to another. They're essential building-blocks of scripted animation! This deck contains an \"ease\" module with a wide variety of easing functions that each take a time (from 0 to 1, inclusive) and numeric values \"a\" and \"b\" to interpolate between. So long as \"a\" and \"b\" conform, they may be scalars, points, or entire polylines."}
field3:{"type":"field","size":[101,34],"pos":[405,22],"locked":1,"border":0,"value":{"text":["(based on ","easings.net",", by Andrey Sitnik and Ivan Solovev!)"],"font":["","",""],"arg":["","https://easings.net",""]}}
field4:{"type":"field","size":[64,14],"pos":[132,314],"locked":1,"show":"transparent","border":0,"style":"plain","align":"center","value":"time"}
field5:{"type":"field","size":[18,14],"pos":[76,308],"locked":1,"border":0,"style":"plain","align":"center","value":"0"}
field6:{"type":"field","size":[18,14],"pos":[228,308],"locked":1,"border":0,"style":"plain","align":"center","value":"1"}
field7:{"type":"field","size":[40,14],"pos":[41,227],"locked":1,"show":"transparent","border":0,"style":"plain","align":"center","value":"output"}
field8:{"type":"field","size":[18,14],"pos":[62,291],"locked":1,"border":0,"style":"plain","align":"center","value":"a"}
field9:{"type":"field","size":[18,14],"pos":[62,164],"locked":1,"border":0,"style":"plain","align":"center","value":"b"}

{script:home.0}
on view do
 names.value:select "Function Name":key from ease
 name:first names.rowvalue
 
 usage.value:rtext.cat[
  rtext.make["usage:\n\n  "]
  rtext.make["ease.%s[time a b]" format name "mono"]
 ]
 
 m:20
 i:c.size-2*m
 f:ease[name]
 c.clear[]
 c.brush:4
 c.pattern:13
 c.line[each t in range i[0]
  (m+t),(f[t/i[0] m+i[1] m])
 end]
 c.brush:0
 c.pattern:1
 c.line[m,m m,c.size[1]-m c.size-m]
end
{end}

{script:home.1}
on click do
 view[]
end
{end}

{module:ease}
description:"a collection of easing functions"
version:1
{script}
on tween f do
 # for ease of use (har har), wrap all the basic
 # easing functions with clamping and interpolation:
 on ease t a b do a+(b-a)*f[0|1&t] end
end

module.lerp:tween[on lerp x do x end]

module.inSine    :tween[on inSine    x do 1-cos.5*pi*x end]
module.outSine   :tween[on outSine   x do sin.5*pi*x end]
module.inOutSine :tween[on inOutSine x do -.5*-1+cos pi*x end]

module.inQuad    :tween[on inQuad    x do x^2 end]
module.outQuad   :tween[on outQuad   x do 1-(1-x)^2 end]
module.inOutQuad :tween[on inOutQuad x do if x<.5 2*x^2 else 1-.5*(2+-2*x)^2 end end]

module.inCubic   :tween[on inCubic    x do x^3 end]
module.outCubic  :tween[on outCubic   x do 1-(1-x)^3 end]
module.inOutCubic:tween[on inOutCubic x do if x<.5 4*x^3 else 1-.5*(2+-2*x)^3 end end]

module.inQuart   :tween[on inQuart    x do x^4 end]
module.outQuart  :tween[on outQuart   x do 1-(1-x)^4 end]
module.inOutQuart:tween[on inOutQuart x do if x<.5 8*x^4 else 1-.5*(2+-2*x)^4 end end]

module.inQuint   :tween[on inQuint    x do x^5 end]
module.outQuint  :tween[on outQuint   x do 1-(1-x)^5 end]
module.inOutQuint:tween[on inOutQuint x do if x<.5 16*x^5 else 1-.5*(2+-2*x)^5 end end]

module.inExpo    :tween[on inExpo     x do 2^-10+10*x end]
module.outExpo   :tween[on outExpo    x do 1-2^-10*x end]
module.inOutExpo :tween[on inOutExpo  x do .5*if x<.5 2^-10+20*x else 2-2^10+-20*x end end]

module.inCirc    :tween[on inCirc     x do 1-sqrt 1-x^2 end]
module.outCirc   :tween[on outCirc    x do sqrt 1-(x-1)^2 end]
module.inOutCirc :tween[on inOutCirc  x do .5*if x<.5 1-sqrt 1-(2*x)^2 else 1+sqrt 1-(2+-2*x)^2 end end]

c1:1.70158
c2:c1*1.525
c3:c1+1
module.inBack      :tween[on inBack     x do (c3*x^3)-(c1*x^2) end]
module.outBack     :tween[on outBack    x do 1+(c3*(x-1)^3)+(c1*(x-1)^2) end]
module.inOutBack   :tween[on inOutBack  x do .5*if x<.5 ((2*x)^2)*((c2+1)*(2*x))-c2 else 2+(((2*x)-2)^2)*((c2+1)*(-2+2*x))+c2 end end]

c4:(2*pi)/3
c5:(2*pi)/4.5
module.inElastic   :tween[on inElastic    x do (- 2^-10+10*x)*(sin c4*-10.75+10*x) end]
module.outElastic  :tween[on outElastic   x do 1+(2^-10*x)*(sin c4*-.75+10*x) end]
module.inOutElastic:tween[on inOutElastic x do t:sin c5*-11.125+20*x if x<.5 .5*-t*(2^-10+20*x) else 1+.5*t*(2^10+-20*x) end end]

n1:7.5625 d1:2.75
on outBounce x do
 if     x<1  /d1                      n1*x^2
 elseif x<2  /d1 x:x-1.500/d1 .750000+n1*x^2
 elseif x<2.5/d1 x:x-2.250/d1 .937500+n1*x^2
 else            x:x-2.625/d1 .984375+n1*x^2 end 
end
module.inBounce   :tween[on inBounce    x do 1-outBounce[1-x] end]
module.outBounce  :tween[outBounce]
module.inOutBounce:tween[on inOutBounce x do .5*if x<.5 1-outBounce[1-2*x] else 1+outBounce[-1+2*x] end end]
{end}

