Esempio n. 1
0
func main() {
	termbox.Init()
	defer termbox.Close()

	quit := make(chan bool, 1)
	go pollForQuit(quit)

	positions := []struct {
		x    int
		y    int
		flip bool
	}{
		{0, 0, false},
		{12, 0, true},
		{24, 0, false},
		{24, 11, true},
		{12, 11, false},
		{0, 11, true},
	}

	colors := []termbox.Attribute{
		termbox.ColorCyan,
		termbox.ColorGreen,
		termbox.ColorYellow,
		termbox.ColorRed,
		termbox.ColorMagenta,
		termbox.ColorBlue,
	}

	for j := 0; ; j++ {
		group := dit.Group{X: 3, Y: 2}

		for i, position := range positions {
			color := (i + j) % len(colors)
			group.Drawables = append(group.Drawables, makeTriangle(
				position.x, position.y, colors[color], position.flip))
		}

		dit.Draw(dit.Group{Drawables: []dit.Drawable{
			dit.Text{Content: "Press Ctrl-C to quit"},
			group,
		}})

		select {
		case <-quit:
			termbox.Close()
			os.Exit(0)
		case <-time.After(time.Millisecond * 80):
		}
	}
}
Esempio n. 2
0
func main() {
	termbox.Init()
	defer termbox.Close()

	arg := ""
	if len(os.Args) > 1 {
		arg = " " + os.Args[1]
	}

	quit := make(chan bool, 1)
	go pollForQuit(quit)

	b := dit.Box{
		X: 10, Y: 3,
		Width: 20, Height: 6,
		Background: termbox.ColorGreen, Foreground: termbox.ColorWhite,
		Content:   "Welcome to dit!\n\nPlease stay calm and enjoy the winds~",
		Alignment: dit.RightAlignment,
	}

	dit.Draw(b)

	positions := []struct {
		x    int
		y    int
		flip bool
	}{
		{0, 0, false},
		{12, 0, true},
		{24, 0, false},
		{24, 11, true},
		{12, 11, false},
		{0, 11, true},
	}

	colors := []termbox.Attribute{
		termbox.ColorCyan,
		termbox.ColorGreen,
		termbox.ColorYellow,
		termbox.ColorRed,
		termbox.ColorMagenta,
		termbox.ColorBlue,
	}

	for j := 0; ; j++ {
		group := dit.Group{X: 3, Y: 2}

		for i, position := range positions {
			color := (i + j) % len(colors)
			group.Drawables = append(group.Drawables, makeTriangle(
				position.x, position.y, colors[color], position.flip))
		}

		dit.Draw(dit.Group{Drawables: []dit.Drawable{
			dit.Text{Content: "HellowWorld(2!)" + arg},
			group,
		}})

		select {
		case <-quit:
			termbox.Close()
			os.Exit(0)
		case <-time.After(time.Millisecond * 80):
		}
	}
}