实时调试插值方程:interpolator​

QuibblerQuibbler 2022-07-17 约 3 分钟 2193 次阅读

实时调试插值方程:interpolator

分享一个实时调试插值方程的开源工具:interpolator,在动效开发中会有帮助,预览插值器效果,所见即所得。关于插值器另见动画插值器Interpolator一文。

GitHub地址:github/inloop/interpolator。

interpolator是用JavaScript和Html实现的前端项目,clone到本地打开index.html文件即可。也可以直接打开在线页面:http://inloop.github.io/interpolator/,基于GitHub搭建的博客就是用这种静态页面的方式。



内置常见插值函数,可修改/编辑自定义函数,并实时预览函数图像。再结合平移、放缩、旋转、透明度四种动画预览插值器效果。

调好插值方程后(当成辅助工具使用,通常动效方程由动效设计师设计),可以非常方便的自定义一个插值器。自定义Interpolator在动画插值器Interpolator一文中有详细介绍。

class AnticipateOvershoot : Interpolator {
        private val tension = 2.0f * 1.5f
        
        fun a(t: Float, s: Float): Float = t * t * ((s + 1) * t - s)
        
        fun o(t: Float, s: Float): Float = t * t * ((s + 1) * t + s)
        
        override fun getInterpolation(x: Float): Float {
            return if (x < 0.5f) 0.5f * a(x * 2.0f, tension)
            else 0.5f * (o(x * 2.0f - 2.0f, tension) + 2.0f)
        }
        
    }

将自定义的插值器设置给补间动画Animation、属性动画Animator:

val animator: Animator = ObjectAnimator.ofFloat(imageView, "rotation", 0f, 180f)
    //给动画设置自定义插值器
    animator.interpolator = AnticipateOvershoot()
    animator.duration = 1000
    animator.start()

相关推荐

精选
Airbnb开源项目
开源

Airbnb开源项目

Airbnb Engineering & Data ScienceAirflow Use Apache Airflow (incubating) to author workflows as directed acyclic graphs (DAGs) of tasks12,263Airpal Web UI for PrestoDB2,502Aerosolve A machine learning

1.8k
OkHttp线程池和连接池
开源

OkHttp线程池和连接池

OkHttp线程池和连接池了解了OkHttp的网络请求流程以及拦截器实现原理,再关注OkHttp中两个重要的:OkHttp的线程池和连接池。1、OkHttp线程池在OkHttp网络请求流程一文中,我们分析了OkHttp异步和同步请求流程。请求最后都在Dispatcher中分发调度处理,最后被ExecutorService执行。1.1、DispatcherDispatcher中执行任务的执行器是ex

5.2k
优美的开源动效库:Lottie
开源

优美的开源动效库:Lottie

优美的开源动效库:Lottie1、强大的动效LottieLottie是一个适用于Android,iOS,Web和Windows的库,它可以使用Bodymovin解析以json格式导出的Adobe After Effects动画,并在移动设备和Web上原生渲染它们!GitHub:https://github.com/airbnb/lottie-androidLottie官网:http://airbn

4.3k