-
Notifications
You must be signed in to change notification settings - Fork 4
/
seed.js
35 lines (30 loc) · 678 Bytes
/
seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
exports.seed = function seed(engine, hash, [maxRow, maxCol]) {
var bytes = hexStringToByte(hash);
let row = 0;
let col = 0;
for (let i = 0; i < bytes.length; i++) {
const byte = bytes[i];
for (let j = 0; j < 7; j++) {
const bit = byte & 1;
if (bit > 0) {
engine.draw(row, col);
}
col++;
if (col >= maxCol) {
col = 0;
row++;
}
if (row >= maxRow) row = 0;
}
}
}
function hexStringToByte(str) {
if (!str) {
return new Uint8Array();
}
var a = [];
for (var i = 0, len = str.length; i < len; i+=2) {
a.push(parseInt(str.substr(i,2),16));
}
return new Uint8Array(a);
}