Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. bezier = function(t, p0, p1, p2, p3){
  2. var cX = 3 * (p1.x - p0.x), //
  3. bX = 3 * (p2.x - p1.x) - cX,
  4. aX = p3.x - p0.x - cX - bX;
  5.  
  6. var cY = 3 * (p1.y - p0.y),
  7. bY = 3 * (p2.y - p1.y) - cY,
  8. aY = p3.y - p0.y - cY - bY;
  9.  
  10. var x = (aX * Math.pow(t, 3)) + (bX * Math.pow(t, 2)) + (cX * t) + p0.x;
  11. var y = (aY * Math.pow(t, 3)) + (bY * Math.pow(t, 2)) + (cY * t) + p0.y;
  12.  
  13. return {x: x, y: y};
  14. },
  15.  
  16. (function(){
  17. var accuracy = 0.0001,
  18. p0 = {x: positionImages.getX(), y: positionImages.getY() - 90},
  19. p1 = {x: positionImages.getX() + 75, y: positionImages.getY() - 90},
  20. p2 = {x: positionImages.getX() + 75, y: positionImages.getY() + 60},
  21. p3 = {x: positionImages.getX(), y: positionImages.getY() + 60},
  22. context = document.getElementById('canvas').getContext('2d');
  23.  
  24. context.moveTo(p0.x, p0.y);
  25. for (var i=0; i<1; i+=accuracy){
  26. var p = bezier(i, p0, p1, p2, p3);
  27. context.lineTo(p.x, p.y);
  28. }
  29. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement