Festelo

Untitled

Jan 14th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.38 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "time"
  5.  
  6.     "github.com/google/gxui"
  7.     "github.com/google/gxui/drivers/gl"
  8.     "github.com/google/gxui/gxfont"
  9.     "github.com/google/gxui/math"
  10.     "github.com/google/gxui/samples/flags"
  11. )
  12.  
  13. var hello = []string {"Hi", "Ave", "Привет", "Salam", "Hola", "Shalom"}
  14.  
  15. func appMain(driver gxui.Driver) {
  16.     theme := flags.CreateTheme(driver)
  17.  
  18.     font, err := driver.CreateFont(gxfont.Default, 75)
  19.     if err != nil {
  20.         panic(err)
  21.     }
  22.  
  23.     window := theme.CreateWindow(380, 100, "Hi")
  24.     window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))
  25.  
  26.     label := theme.CreateLabel()
  27.     label.SetFont(font)
  28.     label.SetText("Hello world")
  29.  
  30.     window.AddChild(label)
  31.  
  32.     tickerSecond := time.NewTicker(time.Millisecond * 30)
  33.     go func() {
  34.         phase := float32(0)
  35.         i := 0
  36.         for range tickerSecond.C {
  37.             a := 0.50 + 0.50*math.Cosf(phase * 10)
  38.             c := gxui.Color{
  39.                 R: 0.75 + 0.25*math.Cosf((phase+0.000)*math.TwoPi),
  40.                 G: 0.75 + 0.25*math.Cosf((phase+0.333)*math.TwoPi),
  41.                 B: 0.75 + 0.25*math.Cosf((phase+0.666)*math.TwoPi),
  42.                 A: a,
  43.             }
  44.  
  45.             if(a < 0.001){
  46.                 driver.Call(func() {
  47.                     label.SetText(hello[i])
  48.                 })
  49.                 i++
  50.                 if(i == len(hello)){
  51.                     i = 0
  52.                 }
  53.             }
  54.             phase += 0.01
  55.             driver.Call(func() {
  56.                 label.SetColor(c)
  57.             })
  58.         }
  59.     }()
  60.  
  61.     window.OnClose(tickerSecond.Stop)
  62.     window.OnClose(driver.Terminate)
  63. }
  64.  
  65. func main() {
  66.     gl.StartDriver(appMain)
  67. }
Advertisement
Add Comment
Please, Sign In to add comment