Last active
May 12, 2019 17:36
-
-
Save peterhellberg/ede229b9809edc17cb672dec89225d81 to your computer and use it in GitHub Desktop.
XOR image drawn by gfx, and displayed using gui
This file contains 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" | |
"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() | |
} |
Author
peterhellberg
commented
May 7, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment