Created
October 4, 2021 23:40
-
-
Save sago35/aa684d7580e2e7c1434f8b80d6e4c127 to your computer and use it in GitHub Desktop.
TinyGo with QR Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"image/color" | |
"time" | |
"github.com/boombuler/barcode" | |
"github.com/boombuler/barcode/qr" | |
"tinygo.org/x/tinyfont" | |
"tinygo.org/x/tinyfont/freemono" | |
) | |
var ( | |
black = color.RGBA{0, 0, 0, 255} | |
white = color.RGBA{255, 255, 255, 255} | |
) | |
func main() { | |
// display : tinygo.org/x/drivers/ili9341.Device | |
display.FillScreen(white) | |
url := `https://tinygo.org/` | |
qc, _ := qr.Encode(url, qr.M, qr.Auto) | |
qc, _ = barcode.Scale(qc, 150, 150) | |
for y := 0; y < qc.Bounds().Max.Y; y++ { | |
for x := 0; x < qc.Bounds().Max.X; x++ { | |
r, g, b, a := qc.At(x, y).RGBA() | |
display.SetPixel(int16(x)+1, int16(y)+1, color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: uint8(a)}) | |
} | |
} | |
tinyfont.WriteLine(display, &freemono.Regular9pt7b, 0, int16(qc.Bounds().Max.X)+20, url, black) | |
for { | |
time.Sleep(500 * time.Millisecond) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment