This video shows how to define random colors for a 3D object within your AnyLogic model. Specifically, we will show how to create cars of different colors.
This can be done in several ways and we have previously posted a video with one of the possible solutions. The good point about it is that it works for both 2D and 3D animation. However, it requires creating a bunch of agent types, thus making it long and tedious.
This time we will do it in a much easier way, but the new approach will work for 3D animation only.
The alternative code lines we use in the scenario:
car.setColor( "Material__4__Surf", randomColor() );
car.setColor( "Material__4__Surf", randomFrom( colors ) ); *
*requires creating the "colors" collection