Skip to content

Commit 1aa8d5d

Browse files
authored
Create units_qrcode.markdown
1 parent 2425d0d commit 1aa8d5d

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

_build/pages/units_qrcode.markdown

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# QR Code
2+
3+
A QR code (quick-response code) is a two-dimensional image containing a matrix barcode. The code contains data like a string, numbers or
4+
binary data and can be for example scanned and read out with a smartphone.
5+
6+
## Download the unit
7+
8+
The unit can be downloaded or copy pasted from the [SmallBASIC Github website](https://github.com/smallbasic/smallbasic.plugins/blob/master/units/qrcode.bas).
9+
Please save the unit in the same directory as your basic file.
10+
11+
## Using the unit
12+
13+
```Freebasic
14+
import qrcode
15+
16+
color 1, 15
17+
cls
18+
19+
CreateQRCode("https://smallbasic.github.io")
20+
21+
'### End of main program ######
22+
23+
sub CreateQRCode(text)
24+
local bufLen = qrcode.bufferLenForVersion(qrcode.VERSION_MAX)
25+
local errCorLvl = qrcode.Ecc_LOW
26+
dim qrcode(bufLen)
27+
28+
if (!qrcode.encodeText(text, qrcode, errCorLvl, qrcode.VERSION_MIN, qrcode.VERSION_MAX, qrcode.Mask_AUTO, true)) then
29+
print "Failed to create QR code"
30+
else
31+
local size = qrcode.getSize(qrcode)
32+
local border = 0
33+
local x, y
34+
local xs = 5 ' Pixel size, increase to have bigger pixels
35+
local ys = 5 ' Pixel size, increase to have bigger pixels
36+
local xo = (xmax - (size * xs)) / 2
37+
local yo = (ymax - (size * xs)) / 2
38+
39+
for y = 0 to size - 1
40+
for x = 0 to size -1
41+
if (qrcode.getModule(qrcode, x, y)) then
42+
rect xo + (xs * x), yo + (ys * y), xo + (xs * (x + 1)), yo + (ys * (y + 1)), 0 filled
43+
endif
44+
next x
45+
next y
46+
endif
47+
end
48+
```

0 commit comments

Comments
 (0)