Skip to content

Instantly share code, notes, and snippets.

@peterhellberg peterhellberg/gui-xor.go
Last active May 12, 2019

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented May 7, 2019

gui-xor-undecorated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.