示例#1
0
func (m *SpacewarPDP1) Init(ctxt draw.Context) {
	m.ctxt = ctxt
	m.kc = ctxt.KeyboardChan()
	m.screen = ctxt.Screen()
	m.dx = m.screen.Width()
	m.dy = m.screen.Height()
	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})
	}
}
示例#2
0
文件: main.go 项目: belkiss/GoMaze
func app(inContext draw.Context)
{
    vl_screen := inContext.Screen();

    screenr := draw.Rect(0, 0, vl_screen.Width(), vl_screen.Height());
    draw.Draw(vl_screen, screenr, draw.White, nil, draw.ZP);

    squareSize := 30;

    var cell *SMazeCell = new(SMazeCell);
    cell.draw(inContext, squareSize);

    inContext.FlushImage();

    fmt.Printf("Press the any key to exit.\n");
    for
    {
        select
        {
            case r := <- inContext.KeyboardChan():
                switch r
                {
                    case 'q', 'Q', 0x04, 0x7F, 32 :
                        fmt.Printf("Exiting because of keyboard event %d\n", r);
                        os.Exit(0);
                    default :
                        fmt.Printf("Exiting because of keyboard event %d\n", r);
                }
            case <- inContext.MouseChan():
                // No-op.
            case <- inContext.ResizeChan():
                // No-op.
            case <- inContext.QuitChan():
                fmt.Printf("Exiting because of QuitChan\n");
                return;
        }
    }
}