Skip to content

Commit

Permalink
trying qrcode libraries for ubg
Browse files Browse the repository at this point in the history
  • Loading branch information
onsetsu committed Jul 25, 2024
1 parent 9b21ba5 commit 31d753c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions demos/stefan/webxr/qrcodegen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

<canvas id='canvasOutput' style='border: red 1px solid;'></canvas>

<script>
import qrgen from 'https://lively-kernel.org/lively4/aexpr/src/external/qrcodegen.js'
const get = id => lively.query(this, '#' + id)
Object.getOwnPropertyNames(qrgen)
const { QrCode } = qrgen
QrCode
var qr = QrCode.encodeText("1234", QrCode.Ecc.HIGH);


function drawCanvas(qr, scale, border, lightColor, darkColor, canvas) {
if (scale <= 0 || border < 0)
throw new RangeError("Value out of range");
const width = (qr.size + border * 2) * scale;
canvas.width = width;
canvas.height = width;
let ctx = canvas.getContext("2d");
for (let y = -border; y < qr.size + border; y++) {
for (let x = -border; x < qr.size + border; x++) {
ctx.fillStyle = qr.getModule(x, y) ? darkColor : lightColor;
ctx.fillRect((x + border) * scale, (y + border) * scale, scale, scale);
}
}
}

drawCanvas(qr, 8, 1, "#FFFFFF", "#000000", get("canvasOutput"));
</script>

0 comments on commit 31d753c

Please sign in to comment.