- Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathunits_qrcode.html
97 lines (97 loc) · 7.66 KB
/
units_qrcode.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="utf-8">
<metahttp-equiv="X-UA-Compatible" content="IE=edge">
<metaname="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | units_qrcode</title>
<metaname="description" content="SmallBASIC | One more basic">
<linkrel="canonical" href="/units_qrcode.html">
<linkrel="keywords" href="units_qrcode">
<linkrel="stylesheet" href="/css/style.css">
<linkrel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<scriptsrc="/clipboard.js"></script>
</head>
<body>
<buttononclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<scriptsrc="/backtotop.js"></script>
<divclass="wrapAll clearfix">
<navclass="navigation">
<divclass="logo">
<ahref="/"><imgsrc='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<divclass="navlinks">
<ahref="/pages/download.html">Download</a>
<ahref="/pages/news.html">News</a>
<ahref="/pages/community.html">Community</a>
<aclass='active' href="/pages/articles.html">Resources</a>
<ahref="/pages/reference.html">Language Reference</a>
<ahref="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<divclass="mainsection">
<divclass="tabs clearfix">
<divclass="tabsRight">
<atarget="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/pages/units_qrcode.markdown">Edit</a>
<atarget="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/pages/units_qrcode.markdown">History</a>
</div>
</div>
<divclass="article">
<h1id="qr-code">QR Code</h1>
<p>A QR code (quick-response code) is a two-dimensional image containing
a matrix barcode. The code contains data like a string, numbers or
binary data and can be for example scanned and read out with a
smartphone.</p>
<h2id="download-the-unit">Download the unit</h2>
<p>The unit can be downloaded or copy pasted from the <a
href="https://github.com/smallbasic/smallbasic.plugins/blob/master/units/qrcode.bas">SmallBASIC
Github website</a>. Please save the unit in the same directory as your
basic file.</p>
<h2id="using-the-unit">Using the unit</h2>
<divclass="sourceCode" id="cb1"><pre
class="sourceCode smallbasic"><codeclass="sourceCode smallbasic"><spanid="cb1-1"><ahref="#cb1-1" aria-hidden="true" tabindex="-1"></a><spanclass="pp">import</span> qrcode</span>
<spanid="cb1-2"><ahref="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb1-3"><ahref="#cb1-3" aria-hidden="true" tabindex="-1"></a><spanclass="fu">color</span><spanclass="dv">1</span>, <spanclass="dv">15</span></span>
<spanid="cb1-4"><ahref="#cb1-4" aria-hidden="true" tabindex="-1"></a><spanclass="fu">cls</span></span>
<spanid="cb1-5"><ahref="#cb1-5" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb1-6"><ahref="#cb1-6" aria-hidden="true" tabindex="-1"></a>CreateQRCode(<spanclass="st">"https://smallbasic.github.io"</span>)</span>
<spanid="cb1-7"><ahref="#cb1-7" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb1-8"><ahref="#cb1-8" aria-hidden="true" tabindex="-1"></a><spanclass="co">'### End of main program ######</span></span>
<spanid="cb1-9"><ahref="#cb1-9" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb1-10"><ahref="#cb1-10" aria-hidden="true" tabindex="-1"></a><spanclass="kw">sub </span>CreateQRCode(text)</span>
<spanid="cb1-11"><ahref="#cb1-11" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> bufLen = qrcode.bufferLenForVersion(qrcode.VERSION_MAX)</span>
<spanid="cb1-12"><ahref="#cb1-12" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> errCorLvl = qrcode.Ecc_LOW</span>
<spanid="cb1-13"><ahref="#cb1-13" aria-hidden="true" tabindex="-1"></a><spanclass="dt">dim</span> qrcode(bufLen)</span>
<spanid="cb1-14"><ahref="#cb1-14" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb1-15"><ahref="#cb1-15" aria-hidden="true" tabindex="-1"></a><spanclass="kw">if </span>(!qrcode.encodeText(text, qrcode, errCorLvl, qrcode.VERSION_MIN, qrcode.VERSION_MAX, qrcode.Mask_AUTO, <spanclass="dt">true</span>)) <spanclass="kw">then</span></span>
<spanid="cb1-16"><ahref="#cb1-16" aria-hidden="true" tabindex="-1"></a><spanclass="kw">print</span><spanclass="st">"Failed to create QR code"</span></span>
<spanid="cb1-17"><ahref="#cb1-17" aria-hidden="true" tabindex="-1"></a><spanclass="kw">else</span></span>
<spanid="cb1-18"><ahref="#cb1-18" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> size = qrcode.getSize(qrcode)</span>
<spanid="cb1-19"><ahref="#cb1-19" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> border = <spanclass="dv">0</span></span>
<spanid="cb1-20"><ahref="#cb1-20" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> x, y</span>
<spanid="cb1-21"><ahref="#cb1-21" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> xs = <spanclass="dv">5</span><spanclass="co">' Pixel size, increase to have bigger pixels</span></span>
<spanid="cb1-22"><ahref="#cb1-22" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> ys = <spanclass="dv">5</span><spanclass="co">' Pixel size, increase to have bigger pixels</span></span>
<spanid="cb1-23"><ahref="#cb1-23" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> xo = (<spanclass="dt">xmax</span> - (size * xs)) / <spanclass="dv">2</span></span>
<spanid="cb1-24"><ahref="#cb1-24" aria-hidden="true" tabindex="-1"></a><spanclass="dt">local</span> yo = (<spanclass="dt">ymax</span> - (size * xs)) / <spanclass="dv">2</span></span>
<spanid="cb1-25"><ahref="#cb1-25" aria-hidden="true" tabindex="-1"></a></span>
<spanid="cb1-26"><ahref="#cb1-26" aria-hidden="true" tabindex="-1"></a><spanclass="kw">for </span>y = <spanclass="dv">0</span><spanclass="kw">to</span> size - <spanclass="dv">1</span></span>
<spanid="cb1-27"><ahref="#cb1-27" aria-hidden="true" tabindex="-1"></a><spanclass="kw">for </span>x = <spanclass="dv">0</span><spanclass="kw">to</span> size -<spanclass="dv">1</span></span>
<spanid="cb1-28"><ahref="#cb1-28" aria-hidden="true" tabindex="-1"></a><spanclass="kw">if </span>(qrcode.getModule(qrcode, x, y)) <spanclass="kw">then</span></span>
<spanid="cb1-29"><ahref="#cb1-29" aria-hidden="true" tabindex="-1"></a><spanclass="fu">rect</span> xo + (xs * x), yo + (ys * y), xo + (xs * (x + <spanclass="dv">1</span>)), yo + (ys * (y + <spanclass="dv">1</span>)), <spanclass="dv">0</span> filled</span>
<spanid="cb1-30"><ahref="#cb1-30" aria-hidden="true" tabindex="-1"></a><spanclass="kw">endif</span></span>
<spanid="cb1-31"><ahref="#cb1-31" aria-hidden="true" tabindex="-1"></a><spanclass="kw">next </span>x</span>
<spanid="cb1-32"><ahref="#cb1-32" aria-hidden="true" tabindex="-1"></a><spanclass="kw">next </span>y</span>
<spanid="cb1-33"><ahref="#cb1-33" aria-hidden="true" tabindex="-1"></a><spanclass="kw">endif</span></span>
<spanid="cb1-34"><ahref="#cb1-34" aria-hidden="true" tabindex="-1"></a><spanclass="kw">end</span></span></code></pre></div>
</div>
<divclass="pagefooter">
This page was last edited on Sat, 9 Sep 2023 22:31:16 +0200
|
<ahref="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<ahref="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>