Randomize rotation of a defined shape inside the cells of a square grid?

Using a square grid, I want to apply a triangular shape inside of each square. What I am trying to figure out is how to randomize the rotation of each of these triangles. The screenshot below shows the desired triangle shape, but they are all rotated the same way.

Method used for constructing the triangle:

  1. Select one of the four available segments
  2. From the centre of each square, draw two lines to both end points of this line segment.

How can I randomize which segment gets selected per cell?

I have done an alternate version where I split the grid into 4 groups of cells (which are randomly distributed), and then I just manually configure each rotation by List Item selecting the appropriate segment. But Iā€™m curious whether one can simplify this. The project that I have in mind has multiple shapes on the same layout, which if I had to configure each rotation separately it would make things quite laborious.

Any assistance would be appreciated!

triangles test.gh (6.8 KB)

1 Like

As you suggest, there are many ways of doing this.


triangles test._2022Jan27a.gh (11.2 KB)

P.S. Rotation works only when the grid cells are square. If they are rectangles, a different strategy is required. (which also works with squares, of course)


triangles test._2022Jan27b.gh (13.3 KB)

3 Likes

Perfect, thank you very much! Much less bulky than the solution I came up with.

And thanks for including the rectangular grid version, I have been mulling about using a rectangular grid i.l.o. a square one in order to allow for more flexibility.