Avg. Rating 3.0

Problem

You need to randomize an objects color without assigning them to an array for distribution

Solution

You can use the Math.random() method to randomize the colors

Detailed explanation

For example you are creating a circle shape by using the graphics API.

Normally you would create it like this:

graphics.beginFill( 0xff0000, 1 );

graphics.drawCircle( 0, 0, 20 );

graphics.endFill();

 

To create a random colorized circle using the same method as above you just need to rewrite this ( in bold )

 

graphics.beginFill( Math.random() * 0xFFFFFF, 1 );

graphics.drawCircle( 0, 0, 20 );

graphics.endFill();


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes