func demuxEvents(w draw.Window, kc chan int) { for event := range w.EventChan() { switch e := event.(type) { case draw.KeyEvent: kc <- e.Key } } os.Exit(0) }
func flushFunc(ctxt draw.Window) func(r image.Rectangle) { if fctxt, ok := ctxt.(RectFlusherWindow); ok { return func(r image.Rectangle) { fctxt.FlushImageRect(r) } } return func(_ image.Rectangle) { ctxt.FlushImage() } }
func goplot(w draw.Window, ch chan []Point, wait chan int) { s := w.Screen() for { v := <-ch plot(s, v) w.FlushImage() if *waitForGraphics { wait <- 1 } } }
func demuxEvents(w draw.Window) { for event := range w.EventChan() { switch e := event.(type) { case draw.MouseEvent: mousec <- e case draw.ConfigEvent: resizec <- true case draw.KeyEvent: kbdc <- e.Key } } os.Exit(0) }
func (m *SpacewarPDP1) Init(ctxt draw.Window, kc chan int) { m.ctxt = ctxt m.kc = kc m.screen = ctxt.Screen() m.dx = m.screen.Bounds().Dx() m.dy = m.screen.Bounds().Dy() m.colorModel = m.screen.ColorModel() m.pix = make([][]uint8, m.dy) for i := range m.pix { m.pix[i] = make([]uint8, m.dx) } m.cmap = make([]image.Color, 256) for i := range m.cmap { var r, g, b uint8 r = uint8(min(0, 255)) g = uint8(min(i*2, 255)) b = uint8(min(0, 255)) m.cmap[i] = m.colorModel.Convert(image.RGBAColor{r, g, b, 0xff}) } }
func Play(pp []Piece, ctxt draw.Window) { display = ctxt screen = ctxt.Screen() screenr = screen.Bounds() pieces = pp N = len(pieces[0].d) initPieces() rand.Seed(int64(time.Nanoseconds() % (1e9 - 1))) whitemask = image.NewColorImage(image.AlphaColor{0x7F}) tsleep = 50 timerc = time.Tick(int64(tsleep/2) * 1e6) suspc = make(chan bool) mousec = make(chan draw.MouseEvent) resizec = make(chan bool) kbdc = make(chan int) go demuxEvents(ctxt) go suspproc() points = 0 redraw(false) play() }
func inlineplot(w draw.Window, v []Point) { s := w.Screen() plot(s, v) w.FlushImage() }