tween a line color in tweenjs canvas - Javascript Canvas

Javascript examples for Canvas:Line

Description

tween a line color in tweenjs canvas

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Line color tween/animation</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://rawgit.com/CreateJS/Combined/master/builds/1.0.0/createjs.min.js"></script> 
      <script type="text/javascript" src="https://rawgit.com/CreateJS/TweenJS/master/src/tweenjs/plugins/ColorPlugin.js"></script> 
      <style id="compiled-css" type="text/css">

body, html {
   margin: 0; padding: 0;
}
canvas {/*from w w w  .ja va  2s. c  o  m*/
   background-color: black;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var stage = new createjs.Stage("canvas");
createjs.Ticker.timingMode = createjs.Ticker.RAF;
createjs.Ticker.on("tick", tick);

stage.autoClear = false;

var fade = new createjs.Shape();
fade.graphics.beginFill("#000000").drawRect(0,0,800,600);
fade.alpha = 0.01;
stage.addChild(fade);

var s = new createjs.Shape(),
      g = s.graphics;

var strokeCommand = g.beginStroke("#0000ff").command; // color
s.graphics.setStrokeStyle(15,"round").setStrokeDash([20,20]);
var startCommand = g.moveTo(0,0).command, // start point
      endCommand = g.lineTo(300,400).command; // end point
stage.addChild(s);

createjs.ColorPlugin.install(); // Note: not included in the min file by default.

createjs.Tween.get(strokeCommand, {loop:true, bounce:true}).to({style:"#ff0000"}, 1000);

stage.on("stagemousemove", function(e) {
   endCommand.x = e.stageX;
  endCommand.y = e.stageY;
});

var index = 0;
function tick(event) {

   startCommand.x = endCommand.x + Math.sin(index+=0.2) * 400;
   startCommand.y = endCommand.y + Math.cos(index) * 400;

   stage.update(event);
}
    }

      </script> 
   </head> 
   <body> 
      <canvas id="canvas" width="800" height="600"></canvas>  
   </body>
</html>

Related Tutorials