Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. var circle = ...create a circle
  2. var circleCached = circle.clone();
  3. var mousePoint = new Point(0, 0);
  4.  
  5. // onMouseMove
  6. var tool = ...initialize a Tool()
  7. tool.onMouseMove = function (event) {
  8. mousePoint = event.point;
  9. }
  10.  
  11. // onFrame
  12. view.onFrame = function (event) {
  13. // Animation 1: Automatic circular rotation of each segment
  14. for (var i = 0; i < circle.segments.length; i++) {
  15. var offsetRotation = new Point(Math.cos(event.time + i * 2), Math.sin(event.time + i * 2)).multiply(15);
  16. circle.segments[i] = circleCached.segments[i].add(offsetRotation);
  17. }
  18.  
  19. // Animation 2: the circle moves following the mouse movements with transition
  20. var delta = mousePoint.subtract(circle.position).divide(15);
  21. circle.position = circle.position.add(delta);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement