The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Path animation, take 1
Posted by: Robin Gavin | July 26, 2010 @ 3:24pm
Javascript Code
[
Download
]
var path = {top: [0, 100, 300, 400], left: [0, 100, 300, 400], distance:[], percent:[]}; var totalDistance = 0; // Calculate distance between points using Pythagoras theorem var distanceX; var distanceY; for(var i = 1; i< path.top.length; ++i) { distanceX = path.top[i] - path.top[i-1]; distanceY = path.left[i] - path.left[i-1]; path.distance[i] = Math.sqrt((distanceX * distanceX) + (distanceY * distanceY)); totalDistance += path.distance[i]; } // Calculate and add property for how many percent part of the animation should take up for(i = 1; i < path.distance.length; ++i) { path.percent[i] = path.distance[i] / totalDistance; console.log(i, path.percent[i]); } var frameCounter = 0; var fps = 10; var animationDurationInSeconds = 10; //setInterval(updatePosition, 1000 / fps); function updatePosition() { if((frameCounter / fps) <= animationDurationInSeconds) { var animationPercent = frameCounter / (fps * animationDurationInSeconds); ++frameCounter; } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.56 / 8
41 Votes
http://codebin.yi.org/759
page generated in 0.01 seconds