mirror of
https://github.com/status-im/QR-Code-generator.git
synced 2026-08-31 01:31:10 +00:00
Changed QrCode.getModule() in {Java, JavaScript, Python, C++} language versions to return Boolean instead of 0/1 - to match {C, Rust} language versions - and updated comments and usages.
This commit is contained in:
@@ -161,7 +161,7 @@ def print_qr(qrcode):
|
||||
border = 4
|
||||
for y in range(-border, qrcode.get_size() + border):
|
||||
for x in range(-border, qrcode.get_size() + border):
|
||||
print(u"\u2588 "[qrcode.get_module(x,y)] * 2, end="")
|
||||
print(u"\u2588 "[1 if qrcode.get_module(x,y) else 0] * 2, end="")
|
||||
print()
|
||||
print()
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ def main():
|
||||
print(qr.get_version())
|
||||
for y in range(qr.get_size()):
|
||||
for x in range(qr.get_size()):
|
||||
print(qr.get_module(x, y))
|
||||
print(1 if qr.get_module(x, y) else 0)
|
||||
|
||||
except ValueError as e:
|
||||
if e.args[0] != "Data too long":
|
||||
|
||||
+5
-5
@@ -37,7 +37,7 @@ This module "qrcodegen", public members:
|
||||
- Method get_size() -> int
|
||||
- Method get_error_correction_level() -> QrCode.Ecc
|
||||
- Method get_mask() -> int
|
||||
- Method get_module(int x, int y) -> int
|
||||
- Method get_module(int x, int y) -> bool
|
||||
- Method to_svg_str(int border) -> str
|
||||
- Enum Ecc:
|
||||
- Constants LOW, MEDIUM, QUARTILE, HIGH
|
||||
@@ -226,9 +226,9 @@ class QrCode(object):
|
||||
|
||||
def get_module(self, x, y):
|
||||
"""Returns the color of the module (pixel) at the given coordinates, which is either
|
||||
0 for white or 1 for black. The top left corner has the coordinates (x=0, y=0).
|
||||
If the given coordinates are out of bounds, then 0 (white) is returned."""
|
||||
return 1 if ((0 <= x < self._size) and (0 <= y < self._size) and self._modules[y][x]) else 0
|
||||
False for white or True for black. The top left corner has the coordinates (x=0, y=0).
|
||||
If the given coordinates are out of bounds, then False (white) is returned."""
|
||||
return (0 <= x < self._size) and (0 <= y < self._size) and self._modules[y][x]
|
||||
|
||||
|
||||
# ---- Public instance methods ----
|
||||
@@ -241,7 +241,7 @@ class QrCode(object):
|
||||
parts = []
|
||||
for y in range(-border, self._size + border):
|
||||
for x in range(-border, self._size + border):
|
||||
if self.get_module(x, y) == 1:
|
||||
if self.get_module(x, y):
|
||||
parts.append("M{},{}h1v1h-1z".format(x + border, y + border))
|
||||
return """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ Examples:
|
||||
border = 4
|
||||
for y in range(-border, qr1.get_size() + border):
|
||||
for x in range(-border, qr1.get_size() + border):
|
||||
color = qr1.get_module(x, y) # 0 for white, 1 for black
|
||||
color = qr1.get_module(x, y) # False for white, True for black
|
||||
# (... paint the module onto pixels ...)
|
||||
|
||||
More complete set of examples: https://github.com/nayuki/QR-Code-generator/blob/master/python/qrcodegen-demo.py .
|
||||
|
||||
Reference in New Issue
Block a user