Scripting: SetColor on individual elements of a sequence?

mekaj shared this question 7 years ago

I've made a grid of square cells like this:

    Sequence[Sequence[Polygon[(i, j), (i + cellSize, j), 4], i, 0, gridSize, cellSize], j, 0, gridSize, cellSize]

Now I want to run SetColor or SetFill on individual cells in the grid.

First I tried wrapping the Polygon expression above with SetColor[<polygon>, 0, 1, 0], but I guess SetColor can only be used in a script. Next I tried the following OnUpdate script for my grid to color the first cell Green.

    SetColor[Element[Element[grid, 1], 1], 0, 1, 0]

When I update cellSize there's no change. No errors either. But if I change the code to color the whole grid green it works.

    SetColor[grid, 0, 1, 0]

The UI doesn't seem to have any way to manually color individual cells either.

Is the problem that GeoGebra models each "object" as having no more than one color, and "objects" can't be composed of other first-class "objects"? If so, are there any plans to change this?

Short of manually drawing and coloring gridSize*gridSize cells, is there any way to color the cells independently?

Comments (2)


Hi, i don't know if the following suggestion works, because I'm writing here using my cellphone and cannot try it :flushed:

My idea is to copy the generated sequence into the spreadsheet (just drag it from Algebra View into the Spreadsheet), then change the attributes of each cell. These changes should be applied to the single elements of the sequence).

I hope it works :)





imossible to change color or a property of a single element in a list.

Simona offers a way with the spreadsheet, and the ability to manually change each cell.

Another way is to create an object for each element and thereby for programmatically altering the properties of each element.(with script).

command : Execute[sequence[ "..."+i+"..." , i , 1 , n ] ]

© 2021 International GeoGebra Institute