Coloring lists and classes of objects

List of objects with the same color

First, let's create a list of objects. For example, the following ggb script: L_1 = Sequence(Circle((4 random(), 4 random()), RandomUniform(0.2, 1)), i, 1, 10) creates a list of circles with different radius in the region [0,4]x[0,4].  If you change the color of the list L_1, then all the objects in that list will have the same color you selected.

Example 1: Same color

If you want to use a different color for each object in the list, you can select one object and then apply the color, but that will be very laborious and time consuming. Instead we can use ggb scripting to create different objects and then apply dynamic colors.

Using different color for same classes of objects

In order to apply different colors to each object of the same class, we can use the command Execute(). First, we need to create a class of objects with specific labels. That is:  Execute(Sequence("C"+i+"=Circle((4 random(), 4 random()), RandomUniform(0.2, 1))", i, 1, 10)) The script above plots the same number of circles with different radius in the same region as before.

Example 2: A class of objects

Now, we can use the command SetDynamicColor() to apply different colors to each object (circles, in this case). That is: Execute(Sequence("SetDynamicColor(C"+i+", random(), random(), random(), 0.5)", i, 1, 10)) This script assigns random colors to each one of the objects defined previously and also assigns the value 0.5 to the opacity.

Example 3: Different colors for each object in the same class

Now try to make your own version. Modify the previous ggb scripting lines to explore different options for coloring objects of the same class. In case you are not familiar with the Scripting commands used here, you can review them by clicking in the following links: Here is my final version after adjusting some values:

Gallery of random colorful circles

That's it! I hope you found this useful. If so, send me a tweet: @jcponcemath