Advertisement
Guest User

SVG3d: Controlling the rotation of a path with an easing fun

a guest
Nov 30th, 2013
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2.  
  3.    <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:ns1="http://sozi.baierouge.fr" xmlns:xlink="http://www.w3.org/1999/xlink" width="210mm"
  4.   height="297mm"
  5.   xml:space="preserve" xmlns:z="http://debeissat.nicolas.free.fr/svg3d/svg3d.rng">
  6.    <!--Include this library and remember to update the svg3d_parsing.js file-->
  7.    <script type="text/ecmascript" xlink:href="svg3d/svg3d.js"></script>
  8.    <script type="text/ecmascript" xlink:href="svg3d/svg3d_parsing.js"></script>
  9.    <script type="text/ecmascript" xlink:href="svg3d/dom_utils.js"></script>
  10.    <g id="anim_container"
  11.      z:xOrigin="0"
  12.      z:yOrigin="0"
  13.      z:zRatio="1000"
  14.      z:sortAlgo="none"
  15.      z:rotationTime="60"
  16.      onload="init(this);">
  17.       <path
  18.         d="M 460.2203,600.93365 248.25964,263.59573 C 248.63437,272.77915 249.10289,281.86852 249.66521,290.86388 250.03994,298.54799 250.32105,306.70032 250.50856,315.32088 250.88328,323.75461 251.07069,331.251 251.07079,337.81007 L 251.07079,600.93365 203.28125,600.93365 203.28125,204.84271 265.68876,204.84271 479.89835,544.42955 C 479.33579,535.24653 478.77356,526.06345 478.21166,516.88029 477.83651,509.00916 477.4617,500.48202 477.0872,491.29883 476.71206,481.92845 476.52465,473.02649 476.52497,464.59291 L 476.52497,204.84271 524.87674,204.84271 524.87674,600.93365 460.2203,600.93365"
  19.         id="path_n"
  20.         >
  21.          <z:translation x="364.0790100097656" y="402.88818359375"/>
  22.          <z:rotation id="rot" incRotY="0.5"/>
  23.          <z:translation x="-364.0790100097656" y="-402.88818359375"/>
  24.       </path>
  25.     </g>
  26.     <script
  27.      xlink:href="http://code.createjs.com/easeljs-0.7.0.min.js"
  28.      id="easeljs" />
  29.       <script
  30.      xlink:href="http://code.createjs.com/tweenjs-0.5.0.min.js"
  31.      id="tweenjs" />
  32.       <script id="rotate">
  33.          var v = document.getElementById("rot");         //Get z:rotation tag element
  34.          var numberSpins = 3.5;                          //Set number of spins
  35.          //Setting object with variables to tween.
  36.          //deg will be the current angle value, finalDeg the final value (both in degrees)
  37.          degrees = {deg: 0, finalDeg: numberSpins*360};  
  38.          createjs.Tween.get( degrees, { loop: false } )  //apply tweening of degrees object
  39.          .wait(1800)
  40.          .to( { deg: degrees.finalDeg }, 3000, createjs.Ease.quadInOut )  //Here we set the variable to tween within the object (deg), the final value (finalDeg, the duration and the easing function
  41.          .call(function(){createjs.Ticker.removeEventListener('tick',update)}); //Once we finish spinning, remove listener
  42.          //Then set the update function to be called for each tick
  43.          var update = function(){
  44.             var rad = degrees.deg*Math.PI/180;            //Transform the current angle to radians
  45.             v.setAttribute("rotY",rad);                   //Setting the rotation attribute to be read by transform()
  46.             transform();                                  //Apply rotation with the values we've set on z:rotation tag element
  47.          }
  48.          createjs.Ticker.setFPS( 60 );                   //Just creates a ticker. See TweenJs Documentation
  49.          createjs.Ticker.addEventListener( 'tick', update ); //For each tick execute the update function
  50.       </script>
  51. </svg>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement