Skip to content

Commit feb82bf

Browse files
committed
Add 50% scatter pattern
Needs the fn feature to make sure the whole matrix is exactly 50% covered. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent fb23a7d commit feb82bf

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

app.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ const patterns = {
6868
return Math.abs(adjustedRow - centerRow) + Math.abs(col - centerCol) < size;
6969
},
7070
},
71+
'Scatter 50%': {
72+
fn: ({ matrix }) => {
73+
// Start blank
74+
for (let row = 0; row < HEIGHT; row++)
75+
for (let col = 0; col < WIDTH; col++)
76+
matrix[row][col] = 1;
77+
78+
// Place a fixed number of random dots (50%)
79+
const count = Math.floor((WIDTH * HEIGHT) / 2);
80+
let placed = 0;
81+
while (placed < count) {
82+
const row = Math.floor(Math.random() * HEIGHT);
83+
const col = Math.floor(Math.random() * WIDTH);
84+
if (matrix[row][col] === 1) {
85+
matrix[row][col] = 0;
86+
placed++;
87+
}
88+
}
89+
},
90+
},
7191
};
7292

7393
const PATTERNS = Object.keys(patterns);

0 commit comments

Comments
 (0)