Forked from: Quasimondo's forked from: Dynamic Interpolation diff:22 Linear Dynamic Interpolation Quasimondo forked:0favorite:0lines:28license : MIT License modified : 2011-01-14 23:04:45 Embed Tweet // forked from Quasimondo's forked from: Dynamic Interpolation // forked from Quasimondo's Dynamic Interpolation package { import flash.geom.Point; import flash.display.Sprite; public class LinearDynamicInterpolation extends Sprite { public function LinearDynamicInterpolation() { var points:Vector.<Point> = Vector.<Point>( [ new Point(0.1,0.4), new Point(0.6,0.3)]); graphics.lineStyle(0,0); graphics.drawRect(0,0,200,200); for ( var i:int = 0; i < 100; i++ ) { var v:Number = interpolate(i / 100,points); graphics.drawCircle( i * 2, v * 200,1 ); } } // all arguments must be in the range 0...1 private function interpolate( value:Number, points:Vector.<Point> ):Number { if ( points[0].x > 0 ) points.unshift( new Point(0,0) ); if ( points[points.length-1].x < 1 ) points.push( new Point(1,1) ); for ( var i:int = 0; i < points.length; i++ ) if ( value < points[i].x ) break; var p1:Point = points[ i-1]; var p2:Point = points[ i]; var d:Number = (value - p1.x) / ( p2.x - p1.x ); return p1.y + d * ( p2.y - p1.y ); } } } Code Fullscreen Preview Fullscreen interpolation math tween Point.interpolate Point unshift length push Vector Sprite int Number