Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. //
  2. // Display termbox 256 colors.
  3. // Usage:
  4. // go run termbox-256colors.go
  5. //
  6. // Press Esc to quit.
  7. //
  8.  
  9. package main
  10.  
  11. import (
  12. "strconv"
  13. "time"
  14.  
  15. termbox "github.com/nsf/termbox-go"
  16. )
  17.  
  18. const textColor = termbox.ColorBlack
  19. const backgroundColor = termbox.ColorBlack
  20.  
  21. func main() {
  22. err := termbox.Init()
  23. if err != nil {
  24. panic(err)
  25. }
  26. defer termbox.Close()
  27.  
  28. termbox.SetOutputMode(termbox.Output256)
  29. termbox.Clear(backgroundColor, backgroundColor)
  30.  
  31. for i := 1; i < 256; i++ {
  32. z := i / 100
  33. y := (i % 100) / 10
  34. x := (i % 100) % 10 / 1
  35.  
  36. Render256(i, x, y, z)
  37. }
  38.  
  39. termbox.Flush()
  40.  
  41. eventQueue := make(chan termbox.Event)
  42. go func() {
  43. for {
  44. eventQueue <- termbox.PollEvent()
  45. }
  46. }()
  47.  
  48. for {
  49. ev := <-eventQueue
  50. if ev.Type == termbox.EventKey {
  51. switch {
  52. case ev.Key == termbox.KeyEsc:
  53. return
  54. }
  55. }
  56. time.Sleep(1 * time.Second)
  57. }
  58.  
  59. }
  60.  
  61. func Render256(i, x, y, z int) {
  62. row := i % 16
  63. col := i / 16
  64.  
  65. color := termbox.Attribute(z*100 + y*10 + x)
  66. termbox.SetCell(col*3, row, []rune(strconv.Itoa(z))[0], textColor, color)
  67. termbox.SetCell(col*3+1, row, []rune(strconv.Itoa(y))[0], textColor, color)
  68. termbox.SetCell(col*3+2, row, []rune(strconv.Itoa(x))[0], textColor, color)
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement