Skip to content

Instantly share code, notes, and snippets.

@asukakenji
asukakenji / try_shiny.go
Created Jul 31, 2017
Shortest GUI program written in Golang. It displays a window and exits after 5 seconds.
View try_shiny.go
// Shortest GUI program written in Golang.
// It displays a window and exits after 5 seconds.
package main
import (
"time"
"golang.org/x/exp/shiny/driver"
"golang.org/x/exp/shiny/screen"
)
View loop3.go
func (bt *BlinkyTape) playPattern(p Pattern, delay time.Duration) {
bt.clear()
L:
for _, frame := range p {
bt.setFrame(frame)
if err := bt.render(); err != nil {
log.Fatalf("render error: %s\n", err)
}
View loop2.go
func (bt *BlinkyTape) animation(p Pattern, repeat int, delay time.Duration) {
bt.status = Running
L:
for i := 0; repeat < 0 || i < repeat; i++ {
select {
case <-bt.stop:
break L
default:
go bt.playPattern(p, delay)
View loop.go
func (bt *BlinkyTape) animation(p Pattern, repeat int, delay time.Duration) {
bt.status = Running
innerLoop := func() bool {
select {
case <-bt.stop:
return false
default:
go bt.playPattern(p, delay)
<-bt.next