How to get random color in my CreateJS form?

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(); 
+6
source share
1 answer

beginFill accepts any color, also hex, so you just need to create a random hexagonal 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(); 
+6
source

Source: https://habr.com/ru/post/981814/


All Articles