好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

关于html5中图片抛物线运动技巧分享

本文主要介绍了浅谈关于h5中图片抛物线运动的一些心得,详细的介绍了沿贝塞尔曲线运动的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能帮助到大家。

function getBezierPath(p1, p2, p3, p4, times) {
    function Point2D(x,y){  
        this.x = x || 0.0;  
        this.y = y ||0.0;  
    }  
    
    function PointOnCubicBezier( cp, t ) {  
        var   ax, bx, cx;  
        var   ay, by, cy;  
        var   tSquared, tCubed;  
        var   result = new Point2D ;  
        cx = 3.0 * (cp[1].x - cp[0].x);  
        bx = 3.0 * (cp[2].x - cp[1].x) - cx;  
        ax = cp[3].x - cp[0].x - cx - bx;        
        cy = 3.0 * (cp[1].y - cp[0].y);  
        by = 3.0 * (cp[2].y - cp[1].y) - cy;  
        ay = cp[3].y - cp[0].y - cy - by;        
        tSquared = t * t;  
        tCubed = tSquared * t;        
        result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;  
        result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;        
        return result;  
    }  
    function ComputeBezier( cp, numberOfPoints, curve ){  
        var   dt;  
        var   i;        
        dt = 1.0 / ( numberOfPoints - 1 );  
         for( i = 0; i < numberOfPoints; i++)  
            curve[i] = PointOnCubicBezier( cp, i*dt );  
    }  
      
    var cp=[  
        new Point2D(parseInt(p4[0]), parseInt(p4[1])), new Point2D(p2[0], p2[1]), new Point2D(p3[0], p3[1]), new Point2D(p1[0], p1[1])  
    ];  
    var numberOfPoints = times;  
    var curve=[];  
    ComputeBezier( cp, numberOfPoints, curve );  
    return curve;
} 

相关推荐:

两种JS实现小球抛物线轨迹运动的方法

JavaScript中弹性势能动画之关于抛物线运动的代码案例

jQuery抛物线运动实现方法(附完整demo源码下载)_jquery

以上就是关于html5中图片抛物线运动技巧分享的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于关于html5中图片抛物线运动技巧分享的详细内容...

  阅读:53次