Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Last active May 12, 2019 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhellberg/ede229b9809edc17cb672dec89225d81 to your computer and use it in GitHub Desktop.
Save peterhellberg/ede229b9809edc17cb672dec89225d81 to your computer and use it in GitHub Desktop.
XOR image drawn by gfx, and displayed using gui
package main
import (
"image"
"image/draw"
"github.com/peterhellberg/gfx"
"github.com/peterhellberg/gui"
)
func main() {
gui.Run(loop)
}
func loop() {
win, err := gui.Open(
gui.Title("qui-xor"),
gui.Size(512, 512),
gui.Resizable(true),
)
if err != nil {
return
}
for event := range win.Events() {
switch event := event.(type) {
case gui.EventClose:
win.Close()
case gui.EventKeyboardDown:
if event.Key == "escape" {
win.Close()
}
case gui.EventKeyboardChar:
if event.Char == 'q' {
win.Close()
}
case gui.EventResize:
win.Draw(update)
}
}
}
func update(dst draw.Image) image.Rectangle {
gfx.EachPixel(dst.Bounds(), func(x, y int) {
c := uint8(x ^ y)
dst.Set(x, y, gfx.ColorNRGBA(c, c%192, c, 255))
})
return dst.Bounds()
}
@peterhellberg
Copy link
Author

gui-xor-undecorated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment