Created
November 24, 2023 04:09
-
-
Save nanjizal/b58c6023a5aa35c800fd0a70eb77fa84 to your computer and use it in GitHub Desktop.
Freya's Hermite Monotonic curve
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
function main() { | |
trace("Freya Hermite Monotonic curve"); | |
var w = 0.5; | |
var x = 0.; | |
for( x10 in 0...10 ){ | |
x = x10/10; | |
trace( x + ' : ' + cubicMidpointEaseInOut( x, w ) ); | |
} | |
trace( 1. + ' : ' + cubicMidpointEaseInOut( 1., w ) ); | |
} | |
inline | |
function cubicMidpointEaseInOut( x: Float, w: Float ){ | |
final s = 3*( ( w < 0.5 )? w: 1 - w ); | |
return if( x <= 0.5 ){ | |
hermiteEval( 0, 0, w, s, 2*x ); | |
} else { | |
hermiteEval( w, s, 1, 0, 2*x - 1 ); | |
} | |
} | |
inline | |
function hermiteEval( p0: Float, v0: Float | |
, p1: Float, v1: Float, x: Float ){ | |
final x2 = x*x; | |
final x3 = x2*x; | |
return x3*( 2*p0 + v0 - 2*p1 + v1 ) | |
+ x2*( -3*p0 - 2*v0 + 3*p1 - v1 ) | |
+ x*v0 | |
+ p0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment