6

I want to have a random color where "Crimson" is defined

    var stage = new createjs.Stage("demoCanvas");

    var circle = new createjs.Shape();
    circle.graphics.beginFill("Crimson").drawCircle(0, 0, 50);
    circle.x = 100;
    circle.y = 100;
    stage.addChild(circle);
    stage.update();
Lanny
  • 11,244
  • 1
  • 22
  • 30
Jim Peeters
  • 2,573
  • 9
  • 31
  • 53

1 Answers1

6

beginFill accepts any color, also hex, so you just have to generate a random hex color

var stage  = new createjs.Stage("demoCanvas");
var circle = new createjs.Shape();
var color  = '#'+(Math.random()*0xFFFFFF<<0).toString(16);

circle.graphics.beginFill(color).drawCircle(0, 0, 50);
circle.x = 100;
circle.y = 100;
stage.addChild(circle);
stage.update();
adeneo
  • 312,895
  • 29
  • 395
  • 388
  • 1
    Alternately, if you want a little more control over your color, take a look at the Graphics.getHSL() method. For instance, if you wanted a high saturation color with random hue: `circle.graphics.beginFill( createjs.Graphics.getHSL(Math.random()*360, 100, 50));` – gskinner Feb 01 '15 at 03:05