Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "image"
- "image/draw"
- "github.com/peterhellberg/gfx"
- "github.com/peterhellberg/gui"
- )
- func main() {
- gui.Run(func() {
- win, err := gui.Open(gui.Size(512, 512))
- if err != nil {
- return
- }
- mux, env := gui.NewMux(win)
- go foo(mux.Env(), gfx.IR(0, 0, 512, 256))
- go bar(mux.Env(), gfx.IR(0, 256, 512, 512))
- for event := range env.Events() {
- switch event := event.(type) {
- case gui.EventClose:
- env.Close()
- case gui.EventKeyboardDown:
- if event.Key == "escape" {
- env.Close()
- }
- }
- }
- })
- }
- func foo(env gui.Env, bounds image.Rectangle) {
- drawCircle := func(pt image.Point) func(draw.Image) image.Rectangle {
- return func(dst draw.Image) image.Rectangle {
- if pt.In(bounds) {
- c := gfx.PaletteArne16.Random()
- gfx.DrawPointCircle(dst, pt, 30, 15, c)
- }
- return bounds
- }
- }
- for event := range env.Events() {
- switch event := event.(type) {
- case gui.EventMouseMove:
- env.Draw(drawCircle(event.Point))
- case gui.EventResize:
- env.Draw(func(dst draw.Image) image.Rectangle {
- gfx.EachPixel(bounds, func(x, y int) {
- v := uint8(x ^ y)
- c := gfx.ColorNRGBA(v%192, v, v, 255)
- dst.Set(x, y, c)
- })
- return bounds
- })
- }
- }
- }
- func bar(env gui.Env, bounds image.Rectangle) {
- drawSquare := func(pt image.Point) func(draw.Image) image.Rectangle {
- return func(dst draw.Image) image.Rectangle {
- if pt.In(bounds) {
- c := gfx.PaletteEDG16.Random()
- n := 30
- r := gfx.IR(pt.X-n, pt.Y-n, pt.X+n, pt.Y+n)
- gfx.DrawColor(dst, r, c)
- }
- return bounds
- }
- }
- for event := range env.Events() {
- switch event := event.(type) {
- case gui.EventMouseMove:
- env.Draw(drawSquare(event.Point))
- case gui.EventResize:
- env.Draw(func(dst draw.Image) image.Rectangle {
- gfx.EachPixel(bounds, func(x, y int) {
- v := uint8(x ^ y)
- c := gfx.ColorNRGBA(v, v%192, v, 255)
- dst.Set(x, y, c)
- })
- return bounds
- })
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement