diff options
author | Marvin Borner | 2020-04-04 18:42:25 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-04 18:42:25 +0200 |
commit | d452393fdc957503b0387932f442851265175f08 (patch) | |
tree | a00861bef15b4975f7ae616bb141c13c4a5895d6 /qml/Bit.qml | |
parent | 0574b4b19fc6592453a0323e2f927925d98ed76c (diff) |
Sooo many things - you wouldn't believe it!
Diffstat (limited to 'qml/Bit.qml')
-rw-r--r-- | qml/Bit.qml | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/qml/Bit.qml b/qml/Bit.qml index 7bb63ce..c017760 100644 --- a/qml/Bit.qml +++ b/qml/Bit.qml @@ -15,21 +15,40 @@ Loader { } } + function pad(n, width) { + return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n; + } + Component { id: bit_index Label { + id: bit_label text: parent.index.toString() width: Theme.paddingLarge * 2 height: width horizontalAlignment: TextInput.AlignHCenter verticalAlignment: TextInput.AlignVCenter Component.onCompleted: { + // This code could definitely be improved ;) if (index > bits) { - var num = Math.floor(Math.random() * Math.pow(bits - 1, 2)) + 1; + grid.row++; + + var indices = root.matrix.slice(0, bits); + var transformed = []; + indices.forEach(function(elem) { + console.log(elem + " " + pad((parseInt(elem) >>> 0).toString(2), bits)); + transformed.push((pad((parseInt(elem) >>> 0).toString(2), bits))[grid.row - 1]); + }); + + var transformed_num = parseInt(transformed.join(""), 2); + this.text = transformed_num; + root.matrix[index] = transformed_num; + console.log(indices); + console.log(transformed); + } else { + var num = Math.floor(Math.random() * (Math.pow(2, bits) - 1)) + 1; this.text = num; root.matrix[index] = num; - } else { - this.text = "?"; } } } |