is initial condition (default: 1)" [ a: max 1 to integer! any [a 1] p: min max 0 to integer! p 1 t: min max 0 1 / a * (p + to integer! t * a) 1 ] frames "Easing equation function for a tweening with specified frames. Parameter is number of frames (default: 2)" [ a: max 2 to integer! any [a 2] t: min max 0 (t: (to integer! t * a) t / (a - 1)) 1 ] jitter "Easing function for a random jittering. Parameter is percentage of jittering (default: 5%)" [ a: min max 0 any [a 5] 100 t: t + ((0 - 1 + random 1000 - (0 - 1)) / 1000 * (1 / 100.0 * a)) ;if 0 = temp: (0 - 1 + random 1000 - (0 - 1)) / 1000 * 0.05 [temp: 0.001] ;t: t + temp ;a: random 100; max 0 to integer! a ;p: 1 ;min max 0 to integer! p 1 ;t: min max 0 1 / a * (p + round/to t * a 0.01) 1 ;t: min max 0 (t: (to integer! t * a) t / (a )) 1 ;t: min max 0 1 / a * (p + to integer! t * a) 1 ] ;====ATTENTION: if you add a function here you MUST also add its "set-word" above======== ] spec: ["Easing equation function" t "Current time (in frames or seconds)." b "Starting value." c "Change needed in value." d "Expected easing duration (in frames or seconds)." a "First optional parameter for function" p "Second optional parameter for function" /local temp ] foreach [name description body] easefunctions [ spec/1: description do compose [(to-set-word name) func copy spec head insert tail insert body [if t >= d [return c + b] t: t / d] [c * t + b]] ;FIXME: if d = 0 [return b + c] ] {Most of these functions are derived from Robert Penner's Easing Equations: Disclaimer for Robert Penner's Easing Equations license: TERMS OF USE - EASING EQUATIONS Open source under the BSD License. Copyright © 2001 Robert Penner All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } easefunctions: [ ; functions that we will also reverse easeInQuad "Easing equation function for a quadratic (t^^2) easing in: accelerating from zero velocity." [ t: t * t ] ;easeOutQuad "Easing equation function for a quadratic (t^^2) easing out: decelerating to zero velocity." ;[0 - c * ((t: t / d) * (t - 2)) + b] ;[0 - c * ((t: t / d - 1) * t) + c + b] ;[c - (c * ((t: 1 - (t / d)) * t)) + b] ;[easeInQuad d - t b + c 0 - c d a p] ;easeInOutQuad "Easing equation function for a quadratic (t^^2) easing in/out: acceleration until halfway, then deceleration." ;[either t < (d * 0.5)[easeInQuad t * 2 b c * 0.5 d a p][easeOutQuad t * 2 - d b + (c * 0.5) c * 0.5 d a p]] ;easeOutInQuad "Easing equation function for a quadratic (t^^2) easing out/in: deceleration until halfway, then acceleration." ;[either t < (d * 0.5)[easeOutQuad t * 2 b c * 0.5 d a p][easeInQuad t * 2 - d b + (c * 0.5) c * 0.5 d a p]] easeInCubic "Easing equation function for a cubic (t^^3) easing in: accelerating from zero velocity." [ t: t * t * t ] easeInQuart "Easing equation function for a quartic (t^^4) easing in: accelerating from zero velocity." [ t: t * t * t * t ] easeInQuint "Easing equation function for a quintic (t^^5) easing in: accelerating from zero velocity." [ t: t * t * t * t * t ] easeInSine "Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity." [ t: 1 + sine/radians t + 3 * pi_2 ] easeInExpo "Easing equation function for an exponential (2^^t) easing in: accelerating from zero velocity." [ t: power 2 10 * (t - 1) ] easeInCirc "Easing equation function for a circular (sqrt(1-t^^2)) easing in: accelerating from zero velocity." [ t: -1 * (square-root 1 - (t * t)) + 1 ] easeInElastic "Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity. is amplitude,

is period."
[
t: t - 1
a: max 1 any [a 1]
p: min max 0.1 p 2
t: -1 * ( a * (2 ** (10 * t)) * sine/radians (( (t * 1 - ( p / (2 * pi) * arcsine/radians (1 / a))) * (2 * pi) / p)) )
]
easeInBack "Easing equation function for a back (overshooting cubic easing) easing in: accelerating from zero velocity.Parameter is amplitude"
[
a: any [a 1.70158] ; this value gives 10% of overshooting
t: t * t * ((a + 1) * t - a)
;t: t - 1 * a + t * t * t
]
;==== THIS IS NOT a Penner's function
easeInBounce "Easing equation function for a decaying bounce easing in: accelerating from zero velocity. is number of bounces."
[
a: any [a 4]
p: t - 1 * pi * a
t: t * abs (sine/radians p) / p
]
;==== THIS IS NOT a Penner's function
easeInBounceInt "Easing equation function for a bounce (integer number of times) easing in: accelerating from zero velocity. is steps number."
[
a: round-fast any [a 4]
p: t - 1 * pi * a
t: abs (sine/radians p) / p
]
; in the functions below x is t (that is t / d )
; 1 / sech(a) * sech(a / x)
; 1 / sech(a) * sech(a / x) / x
; mim max 0 (log-10 x) / 2 + 1 1
; mim max 0 1 / (1.62 - x) - 0.62 1
; a * x * x * ((2 + (1 / a)) - (2 * x)) ; similar to "back" but y-mirrored (AKA "smoothstep")
; t: t - 1 * a + 1 * t; similar to "back" but quadratic (if a = 0 is linear, if a = 1 is quadratic)
; integer! >= 1 p: pi * t * a t: 1 - (sin(2 * p) - sin(p)) / p ; Meyer wavelet
; 1 - (e ** (-3 * x * x) cos (a * 6 * x)) ; Morlet wavelet
; t: 1 - abs ((e ** (-6 * t)) * cosine/radians (a * 6 * t)) ; modified Morlet wavelet as a very nice bounce effect
;====ATTENTION: if you add a function here you MUST also add its "set-word" above========
]
new-name: "" new-body: []
foreach [name description body] easefunctions [
spec/1: description
do compose [(to-set-word name) func copy spec head insert tail insert body [if t >= d [return c + b] t: t / d] [c * t + b]]
spec/1: replace copy description "in: accelerating from" "out: decelerating to"
new-name: replace form name "In" "Out"
new-body: compose [(name) d - t b + c 0 - c d a p]
do bind compose [(to-set-word new-name) func copy spec head new-body] self
spec/1: replace copy description "in: accelerating from zero velocity." "in/out: acceleration until halfway, then deceleration."
new-body: [either t < (d * 0.5)[_ t * 2 b c * 0.5 d a p][_ t * 2 - d b + (c * 0.5) c * 0.5 d a p]]
new-body/5/1: to-word name new-body/6/1: to-word new-name
new-name: replace form name "In" "InOut"
do bind compose [(to-set-word new-name) func copy spec bind head new-body self] self
spec/1: replace copy description "in: accelerating from zero velocity." "out/in: deceleration until halfway, then acceleration."
new-name: replace form name "In" "Out"
new-body/5/1: to-word new-name new-body/6/1: to-word name
new-name: replace form name "In" "OutIn"
do bind compose [(to-set-word new-name) func copy spec bind head new-body self] self
]
yforx: context [ ; functions translated from those of Don Lancaster www.tinaja.com (optimized for 0..1 interval)
x1: 0
y1: 0
x2: 1
y2: 1
A: B: C: D: E: F: _3A: _2B: 0
xfort: func [t][
A * t + B * t + C * t
]
yfort: func [t][
D * t + E * t + F * t
]
slopedtdx: func [t] [
if 0 = t: (_3A * t + _2B * t + C) [t: 1]
t
]
tforx: func [x p /local tguess tryx][
x1: min max 0 p/1 1
y1: p/2 ; min max -2 p/2 2
x2: min max 0 p/3 1
y2: p/4 ;min max -2 p/4 2
A: x1 - x2 * 3 + 1
B: x2 - x1 - x1 * 3
C: x1 * 3
D: y1 - y2 * 3 + 1
E: y2 - y1 - y1 * 3
F: y1 * 3
_3A: 3 * A
_2B: 2 * B
tguess: x
loop 6 [ ; avoid infinite loop
tryx: xfort tguess
if tryx = x [break]
;if 0.005 > abs tryx - x [break]
tguess: min max 0 tguess - ((tryx - x) / slopedtdx tguess) 1
]
tguess
]
]
;transitions-pause: does [paused?: true]
;transitions-unpause: transitions-play: does [paused?: false]
;transitions-stop: transitions-clear-all: does [clear properties]
stop_atransition: func ["Stop a transition (only async for now)"
face [object!] "The face which has the transition to be stopped"
facet [word! path!] "The facet that is transitioning"
/async tick-face [object!] "The