Basically I want to do this:
What's happening:
1. an array of pixels drawn as a 2d square exists
2. a randomly drawn line from one side to the other (also works if it loops back to the same side) shows where pixels have been removed
3. the square array is split into two smaller arrays of half-ish squares
How can I do this in code? The things can be anything from numbers to characters to sprites
Another diagram I drew in paint in case the previous one is too small:
Splitting a group of things from an array of things
Root / Programming Questions / [.]
spaceturtlesCreated:
I'm trying to recreate the break-off mechanics from games like Space Engineers and KSP. If two halves of an object occupy a 2d grid and the parts holding the pieces together are removed, the pieces are put into their own grid arrays and become their own entities
The line represents the objects removed from the grid, not necessarily a literal line. If you have a grid arranged like this:
00000000
01100110
01111110
01100110
01111110
01100110
00000000
Where 1s are existing objects and 0s represent an imaginary part of the array which doesn't exist (deleted elements, for instance)
Then if you remove the "middle" parts:
00000000
01100110
01100110
01100110
01100110
01100110
00000000
It creates two groups of things. I can understand how they could connect to each other using an array of adjacent IDs per object, but I don't know how to separate them into two or more new arrays using this information:
0000 0000
0110 0110
0110 0110
0110 0110
0110 0110
0110 0110
0000 0000
another example:
00000000
01100110
01100110
01100110
01111110
01100110
00000000
00000000
01100110
01100110
01100000
01100110
01100110
00000000
0000 0000
0110 0110
0110 0110
0110 0000
0110
0110
0000
0000
0110
0110
0000
I think I found what I've been looking for for the past three months
After searching google for it using roughly matching terms I came across "finding connected components in graphs" which explains my problem quite well in the search string and gives me https://www.geeksforgeeks.org/connected-components-in-an-undirected-graph/ and a bunch of others. Now I just need to implement it. Thanks for trying help