address a shape drawn on a HTML5 canvas and change its properties? - Javascript Canvas

Javascript examples for Canvas:Shape

Description

address a shape drawn on a HTML5 canvas and change its properties?

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Flash Export Test</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.createjs.com/createjs-2015.11.26.combined.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from www . j av  a 2 s .  co m
var stage = new createjs.Stage("canvas");
createjs.Ticker.on("tick", tick);

(function (lib, img, cjs, ss) {
var p; 

lib.properties = {
    width: 550,
    height: 400,
    fps: 24,
    color: "#FFFFFF",
    manifest: []
};

(lib.canvas_test = function() {
    this.initialize();
    // Layer 1
    this.shape = new cjs.Shape();
    this.shape.graphics.beginFill().beginStroke("#669966")
    .setStrokeStyle(1,1,1).moveTo(-94,-62).lineTo(94,-62).lineTo(94,62).lineTo(-94,62).closePath();
    this.shape.setTransform(198,136);
    this.shape_1 = new cjs.Shape();
    this.shape_1.graphics.beginFill("#FF933C")
    .beginStroke().moveTo(-94,62).lineTo(-94,-62).lineTo(94,-62).lineTo(94,62).closePath();
    this.shape_1.setTransform(198,136);
    this.addChild(this.shape_1,this.shape);
}).prototype = p = new cjs.Container();
p.nominalBounds = new cjs.Rectangle(378,273,190,126);
})(lib = lib||{}, images = images||{}, createjs = createjs||{}, ss = ss||{});
var lib, images, ss;
// New Code
var exportRoot = new lib.canvas_test();
stage.addChild(exportRoot);
var shape = exportRoot.shape;
var stroke = shape.graphics._stroke;
stroke.style = "#ff0000"; // Set to red.
shape = exportRoot.shape_1;
shape.graphics._fill.style = "#fff"; // set to white
function tick(event) {
    stage.update(event);
}
    }

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

Related Tutorials