aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2021-08-31 14:30:07 +0000
committerAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2021-08-31 14:30:07 +0000
commit323934b21700db4e6d9878ce4b8f73e204e66e6e (patch)
tree04541ec639b17da9c1cf51e892500998a7d7a2e5 /src
parentAddress review comments (diff)
downloadminiserve-323934b21700db4e6d9878ce4b8f73e204e66e6e.tar.gz
miniserve-323934b21700db4e6d9878ce4b8f73e204e66e6e.zip
Print inverted QR codes side-by-side
Diffstat (limited to '')
-rw-r--r--src/main.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 4fb191a..5259bee 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -361,12 +361,22 @@ async fn css() -> impl Responder {
.message_body(css.into())
}
-// Prints the given QrCode object to the console.
+// Prints to the console two inverted QrCodes side by side.
fn print_qr(qr: &QrCode) {
- let border: i32 = 4;
- for y in (-border..qr.size() + border).step_by(2) {
- for x in -border..qr.size() + border {
- let c: char = match (qr.get_module(x, y), qr.get_module(x, y + 1)) {
+ let border = 4;
+ let size = qr.size() + 2 * border;
+
+ for y in (0..size).step_by(2) {
+ for x in 0..2 * size {
+ let inverted = x >= size;
+ let (x, y) = (x % size - border, y - border);
+
+ //each char represents two vertical modules
+ let (mod1, mod2) = match inverted {
+ false => (qr.get_module(x, y), qr.get_module(x, y + 1)),
+ true => (!qr.get_module(x, y), !qr.get_module(x, y + 1)),
+ };
+ let c = match (mod1, mod2) {
(false, false) => ' ',
(true, false) => '▀',
(false, true) => '▄',