"Wave Collapse Function" algorithm in Processing

@needfulthing: Thanks for your feedback and the kind words !

If I had more time I could possibly, and laboriously, come up with a Java version but it would certainly be clumsy and inneficient. I would rather see someone with a good understanding of Java data types implement it in the best possible way.

An example: I chose Python sets() because they are efficient and easy to manipulate. I could simply look for the Java equivalent but:

  • Would they be as efficient ? (compared to other Java data types)
  • Would they be as easy to manipulate ? (it seems they’re not)
  • Is there a better alternative ?
  • Could I compute intersections with it ?

Only someone with a good experience of the Java language could answer these questions.

@Chrisir: Thank you for your interest !

Have you looked at the annotations I provided in the second script (just above the first gif) ?

''' Then we check all the patterns that COULD be placed at that location. 
    EX: if the neighboring cell is on the left of the current cell (east side), 
    we look at all the patterns that can be placed on the left of each pattern 
    contained in the current cell. '''

    possible = {n for idP in W[idC] for n in A[idP][dir]}

Breaking that line down:

  • brackets {} indicate we’re dealing with a Python set(). I chose this data type not only because it is efficient but also because we need later to compute the intersection of 2 sets (intersection only works with sets, not operable with lists)
  • idC is the index of the Current cell (the one whose neighbors are updated)
  • idP is the index of the available Pattern in that cell
  • n is the index of the pattern than can be adjacent to pattern idP in direction dir

Basically we look at all the indices of the patterns available in the current cell, then for each one of them we look at all the indices of patterns that can be placed next to it, in a specific direction.
Avoiding that one-liner, it would give something like this:

possible = []
for availablePattern in currentCell:
    for adjacentPattern in listOfAdjacentPatternsToavailablePatternInThisDirection:
        possible.append(adjacentPattern)

2 Likes