# Hexagon Sections

Get help using Construct 2

### » Wed Apr 18, 2018 6:12 pm

I'm attempting to create my own hexagon based grid for testing. I've been able to assemble hexagons the way I want and now I'm trying to have separate sections for each hexagon. Here's a pic of what I'm trying to accomplish.

How do I setup the hexagon so that each of the 6 equal triangles appear to fit inside the hexagon together equally? You can easily place the 6 triangles on the hexagon and they fit. I'm just not sure what events would place them all together so that every hexagon on the layout has the 6 triangles. Each triangle is a separate sprite.

Also, is it possible to randomly have each hexagon get a random arrangement of the 6 triangles? Any help would be appreciated.
B
250
S
139
G
15
Posts: 198
Reputation: 27,929

### » Wed Apr 18, 2018 9:37 pm

Put the origin point at a tip of the triangle.

For each hexagon x/y
Repeat 6 times - Spawn triangle at x/y, rotate loopindex*60 degrees.

To get a random color for each triangle, assuming you are using a single object with different animation frames, add an action to set animation frame to floor(random(6)).

To get a non-repeating random color for each triangle, create an array size 0,1,1.
Step 1 - Populate the array
Repeat 6 times - Array Push Back loopindex
Step 2 - Pick a number out of the array out of the remaining available numbers (use a variable)
Set PickedIndexVariable to floor(random(array.width))
Step 3 - Apply the picked number
Set triangle animation frame to Array.At(PickedIndexVariable)
Step 4 - Delete the picked index so it can't be picked again
Array delete index at PickedIndexVariable

Repeat steps 2-4 until all numbers are picked
Repeat step 1 for next set of triangles.
Repopulate array
B
61
S
30
G
134
Posts: 1,964
Reputation: 75,430

### » Sat Apr 21, 2018 3:39 pm

oosyrag wrote:Put the origin point at a tip of the triangle.

For each hexagon x/y
Repeat 6 times - Spawn triangle at x/y, rotate loopindex*60 degrees.

To get a random color for each triangle, assuming you are using a single object with different animation frames, add an action to set animation frame to floor(random(6)).

To get a non-repeating random color for each triangle, create an array size 0,1,1.
Step 1 - Populate the array
Repeat 6 times - Array Push Back loopindex
Step 2 - Pick a number out of the array out of the remaining available numbers (use a variable)
Set PickedIndexVariable to floor(random(array.width))
Step 3 - Apply the picked number
Set triangle animation frame to Array.At(PickedIndexVariable)
Step 4 - Delete the picked index so it can't be picked again
Array delete index at PickedIndexVariable

Repeat steps 2-4 until all numbers are picked
Repeat step 1 for next set of triangles.
Repopulate array

Well that first suggestion actually worked. The triangles are a little uneven but I guess I have to create a better triangle. Thanks again.
B
250
S
139
G
15
Posts: 198
Reputation: 27,929