If you are a user of Processing or Processing.js and are mainly interested in an artistic alienation of QR codes, you have various possibilities to load the pattern of a QR code into a "sketch".
Possibilities for Processing:
Possibilities for Processing.js:
Since this page is primarily aimed at processing beginners, only the first two methods mentioned are presented here.
Text: | |
ECC Level: | |
QR Code: | |
Array Literal: | |
JSON Output: | |
Using the example of a small "sketch" that simply displays the QR code pattern unaltered, we will show how to use the pattern as an array literal:
int[][] ModuleArray = new int[][] {
insert your array literal here
};
final int ScreenSize = 512; // width and height of screen
final int minBorderWidth = 40; // min width of border around QR code
void setup () {
size(512,512); // ScreenSize,ScreenSize
background(255);
fill(0);
int QRCodeSize = ModuleArray.length;
int ModuleSize = max(1,floor((ScreenSize-2*minBorderWidth)/QRCodeSize));
int xOffset = floor((ScreenSize-QRCodeSize*ModuleSize)/2);
int yOffset = xOffset;
for (int y = 0; y < QRCodeSize; y++) {
for (int x = 0; x < QRCodeSize; x++) {
if (ModuleArray[y][x] > 0) {
rect(xOffset+x*ModuleSize,yOffset+y*ModuleSize, ModuleSize,ModuleSize);
}
}
}
noLoop();
}
Reading a pattern from a JSON file is a little more involved - in addition, the "QR-Code.json" file must be located in the same directory in which the Sketch itself was saved.
The following example simply outputs the QR code pattern unaltered:
final int ScreenSize = 512; // width and height of screen
final int minBorderWidth = 40; // min width of border around QR code
int[][] ModuleArray;
int[][] loadedQRCodePattern () {
JSONArray ModuleArray = loadJSONArray("QR-Code.json");
int RowCount = ModuleArray.size();
int[][] Result = new int[RowCount][];
for (int y = 0; y < RowCount; y++) {
Result[y] = ModuleArray.getJSONArray(y).getIntArray();
}
return Result;
}
void setup () {
size(512,512); // ScreenSize,ScreenSize
background(255);
fill(0);
ModuleArray = loadedQRCodePattern();
int QRCodeSize = ModuleArray.length;
int ModuleSize = max(1,floor((ScreenSize-2*minBorderWidth)/QRCodeSize));
int xOffset = floor((ScreenSize-QRCodeSize*ModuleSize)/2);
int yOffset = xOffset;
for (int y = 0; y < QRCodeSize; y++) {
for (int x = 0; x < QRCodeSize; x++) {
if (ModuleArray[y][x] > 0) {
rect(xOffset+x*ModuleSize,yOffset+y*ModuleSize, ModuleSize,ModuleSize);
}
}
}
noLoop();
}
This web page uses the following third-party libraries, assets or StackOverflow answers:
The author would like to thank the developers and authors of the above-mentioned contributions for their effort and willingness to make their works available to the general public.