Read the input bitmap and count NxN patterns.Create an array with the dimensions of the output (called "wave" in the source). Each element of this array represents a state of an NxN region in the output. A state of an NxN region is a superposition of NxN patterns of the input with boolean coefficients (so a state of a pixel in the output is a superposition of input colors with real coefficients). False coefficient means that the corresponding pattern is forbidden, true coefficient means that the corresponding pattern is not yet forbidden.Initialize the wave in the completely unobserved state, i.e. with all the boolean coefficients being true.Repeat the following steps:By now all the wave elements are either in a completely observed state (all the coefficients except one being zero) or in the contradictory state (all the coefficients being zero). In the first case return the output. In the second case finish the work without returning anything.波函数(Wave Function): 在这个算法中,波函数维护一个二维数组, 表示每个单元格可能的状态集合。塌缩(Collapse): 塌缩是指将一个单元格的波函数减少到一个确定的状态。这是通过选择一个可能状态并将其固定下来完成的。相邻约束(Adjacency Constraints): 这些约束定义了一个单元格的状态如何影响其邻居单元格的可能状态。初始化: 为所有单元格赋予初始波函数(所有可能的状态)。选择单元格: 从所有未塌缩的单元格中选择一个优先处理。通常,选择不确定性最小的单元格,即具有最少可能状态的单元格。状态选择: 为选中的单元格随机选择一个可能状态,并将波函数塌缩到该状态。传播(Propagation): 根据相邻约束更新相邻单元格的波函数,消除不可能的状态。重复: 重复选择、塌缩和传播步骤,直到所有单元格的波函数都塌缩到确定的状态。