Inverse of a Function
copy const expoIn = t => ( t== 0 ) ? 0 : Math .pow ( 2 , 10 * ( t - 1 ) ) const expoInInverse= t => ( t== 0 ) ? 0 : ( ( Math .log ( t) + 10 * Math .log ( 2 ) ) / Math .log ( 2 ) ) / 10 console.log ( expoIn( .35) + ' ' + expoInInverse( expoIn( .35) ) )
Try it out…
Very nice inverse function calculator by user fawad over at Wolfram Alpha . Was attempting to invert a standard “exponential in” easing function – after some futzing I resorted to the calculator 😀
Decompose Matrix
copy const deltaTransformPoint = ( matrix, point) => { return { x: point.x * matrix.a + point.y * matrix.c , y: point.x * matrix.b + point.y * matrix.d } } const decomposeMatrix = matrix => { let px = deltaTransformPoint( matrix, { x: 0 , y: 1 } ) let py = deltaTransformPoint( matrix, { x: 1 , y: 0 } ) let skewX = FROM_RADS * Math .atan2 ( px.y , px.x ) - 90 let skewY = FROM_RADS * Math .atan2 ( py.y , py.x ) return { tx: matrix.e , ty: matrix.f , scaleX: Math .sqrt ( matrix.a * matrix.a + matrix.b * matrix.b ) , scaleY: Math .sqrt ( matrix.c * matrix.c + matrix.d * matrix.d ) , skewX: skewX, skewY: skewY, rotation: skewX } }
Get the scale, translation, rotationa and skew values from a matrix.
Great stackoverflow answer from user dave
Iterative Square Root
copy //------------------------------------------------------------------ float function_IterativeSquareRoot ( float x) { // http://en.wikipedia.org/wiki/Methods_of_computing_square_roots // Ancient Babylonian technology functionName = "Iterative (Heron's) Square Root" ; float y = 0.5 ; int n = 6 ; for ( int i= 0 ; i< n; i++ ) { y = ( y + x/ y) / 2.0 ; } return y; }
Was browsing some code by Golan Levin and stumbled on this…
There are some real gems in the repo – might port some stuff from there in the future…
Fibonacci Triangle Golfed
copy // by Arnauld - https://codegolf.stackexchange.com/users/58563/arnauld f= ( n, a= b= 1 , p) => n? '' .padEnd ( p) + a+ `+ ${ b} = ${ b+= a} `+ f( n- 1 , b- a, ( a+ "" ) .length - ~p) : '' console.log ( f( 20 ) )
Try it out…
Great golfed solution to this question at codegolf stackexchange by user Arnauld