File Manager
Pro
/data/web/virtuals/8819/virtual/www/subdom/archive/el
PHP 7.4.33
Linux
/data/web/virtuals/8819/virtual/www/subdom/archive/el/jquery.crSpline.js
5.3 KB
0640
Back
/** * @history 2013-01-29 Jan Smid <jan@smid.sk> - *buildSequence() with specify: {left|right} x {top|bottom} coords; +plotSequence() * * jQuery.crSpline v0.0.2 * http://github.com/MmmCurry/jquery.crSpline * * Supports animation along Catmull-Rom splines based on a series of waypoints. * Usage: See demo.js, demo.html * * Copyright 2010, M. Ian Graham * MIT License * */ (function($){ $.crSpline = {}; // Catmull-Rom interpolation between p0 and p1 for previous point p_1 and later point p2 // http://en.wikipedia.org/wiki/Cubic_Hermite_spline#Catmull.E2.80.93Rom_spline var interpolate = function (t, p_1, p0, p1, p2) { return Math.floor((t * ((2 - t) * t - 1) * p_1 + (t * t * (3 * t - 5) + 2) * p0 + t * ((4 - 3 * t) * t + 1) * p1 + (t - 1) * t * t * p2 ) / 2); }; // Extend this p1,p2 sequence linearly to a new p3 var generateExtension = function (p1, p2) { return [ p2[0] + (p2[0] - p1[0]), p2[1] + (p2[1] - p1[1]) ]; }; // Return an animation object based on a sequence of points // pointList must be an array of [x,y] pairs $.crSpline.buildSequence = function(pointList, asX, asY) { var res = {}; var seq = []; var numSegments; if (asX == undefined || (asX != 'left' && asX != 'right')) { asX = 'left'; } if (asY == undefined || (asY != 'top' && asY != 'bottom')) { asY = 'left'; } if (pointList.length < 2) { throw "crSpline.buildSequence requires at least two points"; } // Generate the first p_1 so the caller doesn't need to provide it seq.push(generateExtension(pointList[1], pointList[0])); // Throw provided points on the list for (var i = 0; i < pointList.length; i++) { seq.push(pointList[i]); } // Generate the last p2 so the caller doesn't need to provide it seq.push(generateExtension(seq[seq.length-2], seq[seq.length-1])); numSegments = seq.length - 3; res.getPos = function (t) { // XXX For now, assume all segments take equal time var segNum = Math.floor(t * numSegments); if (segNum === numSegments) { var result = {}; result[asX] = seq[seq.length-2][0]; result[asY] = seq[seq.length-2][1]; return result; } var microT = (t - segNum/numSegments) * numSegments; var result = {}; result[asX] = interpolate(microT, seq[segNum][0], seq[segNum+1][0], seq[segNum+2][0], seq[segNum+3][0]) + "px"; result[asY] = interpolate(microT, seq[segNum][1], seq[segNum+1][1], seq[segNum+2][1], seq[segNum+3][1]) + "px"; return result; }; return res; }; $.crSpline.plotSequence = function(spline, pointList, asX, asY, parent) { $(".waypoint").remove(); $(".path-dot").remove(); var dotsPerSeg = 10; var opt = {}; for (var i=0; i<pointList.length; i++) { for (var j=0; j<dotsPerSeg; j++) { var t = (i + j/dotsPerSeg) / pointList.length; var pos = spline.getPos(t); opt = { position: 'absolute', display: ("inline") }; opt[asX] = (asX == 'left' ? pos.left : pos.right ); opt[asY] = (asY == 'top' ? pos.top : pos.bottom); $('<div class="path-dot" style="background-color:cyan;width:2px;height:2px;position:absolute;" />') .appendTo(parent) .css(opt); } opt = { position: 'absolute', display: ("inline") }; opt[asX] = pointList[i][0]; opt[asY] = pointList[i][1]; $('<div class="path-waypoint" style="background-color:white;border:silver 1px red;position:absolute;font-weight:bold;padding:2px;">'+i+'</div>') .appendTo(parent) .css(opt); } }; $.fx.step.crSpline = function (fx) { var css = fx.end.getPos(fx.pos); for (var i in css) { fx.elem.style[i] = css[i]; } }; })(jQuery);
Cancel
Download
Save changes
File Manager Pro · single-file PHP 7.4.33 on Linux · paths encrypted in URL (AES-256-CTR)