appendPattern static method
@param target encode black/white pattern into this array
@param pos position to start encoding at in target
@param pattern lengths of black/white runs to encode
@param startColor starting color - false for white, true for black
@return the number of elements added to target.
Implementation
static int appendPattern(
List<bool> target,
int pos,
List<int> pattern,
bool startColor,
) {
bool color = startColor;
int numAdded = 0;
for (int len in pattern) {
for (int j = 0; j < len; j++) {
target[pos++] = color;
}
numAdded += len;
color = !color; // flip color after each segment
}
return numAdded;
}