QR code font

Hello
I did this in Grasshopper. It outputs surfaces, each cell has a size of 1 unit, so the size of qr code depends on the size of the string.


it uses the library from Raffael Herrmann
https://github.com/codebude/QRCoder/tree/master/QRCoder
Documentation here
https://en.code-bude.net/2013/10/17/qrcoder-an-open-source-qr-code-generator-implementation-in-csharp/
The “unblocked” dll (QRCoder.dll and UnityEngine.dll) needed are from
https://www.nuget.org/api/v2/package/QRCoder/1.2.6 (it will download a file named qrcoder.1.2.6.nupkg)
https://www.nuget.org/packages/QRCoder/1.2.6
the dll can be extracted from the nupkg unzipping it and putting it in the same directory as the gh script

QR_Code_Surface.gh (6.5 KB)

implementation
Inputs :
string text
int error (0, 1, 2 or 3) for levels L, M, Q, H
Code

List<Surface> black = new List<Surface>();
List<Surface> white = new List<Surface>();
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.H;
if (error == 0)eccLevel = QRCodeGenerator.ECCLevel.L;
if (error == 1)eccLevel = QRCodeGenerator.ECCLevel.M;
if (error == 2)eccLevel = QRCodeGenerator.ECCLevel.Q;
if (error == 3)eccLevel = QRCodeGenerator.ECCLevel.H;
QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, eccLevel);
QRCode qrCode = new QRCode(qrCodeData);

for  (int i = 0; i < qrCodeData.ModuleMatrix.Count; i++)
{
  for  (int j = 0; j < qrCodeData.ModuleMatrix[i].Count; j++)
  {
    Point3d corner1 = new Point3d((double) j, -(double) i, 0.0);
    Point3d corner2 = new Point3d((double) j + 1, -(double) i, 0.0);
    Point3d corner3 = new Point3d((double) j + 1, -(double) i - 1, 0.0);
    Point3d corner4 = new Point3d((double) j, -(double) i - 1, 0.0);
    if (qrCodeData.ModuleMatrix[i][j])
    {
      black.Add(NurbsSurface.CreateFromCorners(corner1, corner2, corner3, corner4));
    }
    else
    {
      white.Add(NurbsSurface.CreateFromCorners(corner1, corner2, corner3, corner4));
    }
  }
}
Black = black;
White = white;

Outputs
Black : List of surfaces for black coloring, you could extract edges to hatch that !
White : List of surfaces for white coloring

Just some fun


QR_Code_Surface_not_sharp.gh (41.1 KB)

5 Likes