示例#1
0
文件: main.go 项目: belkiss/GoMaze
func main()
{
    flag.Parse(); // scans the arg list and sets up flags

    if flag.NArg() > 0
    {
        fmt.Printf("Args given :\n");
    }
    else
    {
        fmt.Printf("No args\n")
    }

    for i := 0; i < flag.NArg(); i++
    {
        os.Stdout.WriteString(flag.Arg(i) + "\n")
    }

//     var cell *SMazeCell = new(SMazeCell);
// //     var cell *SMazeCell = &SMazeCell{false, false, false, false};
// 
//     cell.displayText();

    // window init start
    x11Context, x11Error := x11.NewWindow();
    if x11Error != nil
    {
        fmt.Printf("Error: %v\n", x11Error);
        return;
    }
    // window init end
    app(x11Context);

}
示例#2
0
func main() {
	urls := make(chan string, 4)
	imgReady := make(chan *image.Image, 4)

	go imagePuller(urls, imgReady)
	go urlGen(urls)

	xdisp, err := x11.NewWindow()
	if err != nil {
		log.Exit("X11 error: ", err)
	}
	screen := xdisp.Screen()

	//2010/11/29 16:23:17 one tile is sized (0,0)-(256,256)
	//2010/11/29 16:23:17 the screen is sized (0,0)-(800,600)

	//	log.Print("one tile is sized ", img.Bounds())
	//	log.Print("the screen is sized ", screen.Bounds())

	tileHeight := 256
	tileWidth := 256
	numTiles := screen.Bounds().Dx()/tileWidth + 2
	tileStrip := image.NewRGBA(numTiles*tileWidth, tileHeight)

	// pre-load the tile strip
	for i := 0; i < numTiles; i++ {
		iptr := <-imgReady
		img := *iptr
		draw.Draw(tileStrip, image.Rect(i*tileWidth, 0, i*tileWidth+tileWidth, tileHeight), img, image.ZP)
	}

	topBlack := (screen.Bounds().Dy() - tileHeight) / 2
	for {
		for x := 0; x < tileWidth; x += 15 {
			then := time.Nanoseconds()
			draw.Draw(screen, image.Rect(0, topBlack, screen.Bounds().Dx(), topBlack+tileHeight), tileStrip, image.Pt(x, 0))
			now := time.Nanoseconds()
			frameTime := now - then

			// a flush is just a write on a channel, so it takes negligible time
			xdisp.FlushImage()

			toSleep := 0.1*1e9 - frameTime
			//			log.Print("Took ", frameTime, " ns to draw, will sleep ", toSleep, " ns")
			time.Sleep(toSleep)
			processEvent(xdisp.EventChan())
		}

		// shift tiles in tileStrip and put in new last one
		draw.Draw(tileStrip, image.Rect(0, 0, (numTiles-1)*tileWidth, tileHeight), tileStrip, image.Pt(tileWidth, 0))
		iptr := <-imgReady
		img := *iptr
		draw.Draw(tileStrip, image.Rect((numTiles-1)*tileWidth, 0, numTiles*tileWidth, tileHeight), img, image.ZP)
	}
}
示例#3
0
文件: chaos.go 项目: taysom/tau
func NewGraph(domain, yrange Range) (g Graph) {
	w, err := x11.NewWindow()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	g.window = w
	g.domain = domain
	g.yrange = yrange
	g.color = image.RGBAColor{0, 0xff, 0, 0xff}
	g.setScale()
	return
}
示例#4
0
文件: box.go 项目: taysom/tau
func main() {
	color := image.RGBAColor{255, 255, 255, 255}
	//	red := image.RGBAColor{255, 255, 0, 255}
	//	var color image.Color
	//	color = 0xff00ff
	//	color.RGBA(1000, 0, 0, 1000)
	w, err := x11.NewWindow()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	s := w.Screen()
	for x := 0; x < 256; x++ {
		for y := 0; y < 256; y++ {
			color = image.RGBAColor{uint8(x), uint8(y), 0, 255}
			s.Set(x, y, color)
		}
	}
	b := s.Bounds()
	for x := 0; x < b.Max.Y; x++ {
		y := x * x
		if y >= b.Max.X {
			break
		}
		s.Set(x, y, color)
	}
	w.FlushImage()
	fmt.Printf("Press any key to exit.\n")
	i := 0
	for event := range w.EventChan() {
		i++
		fmt.Println("event type: ", event, i)
		switch e := event.(type) {
		case draw.KeyEvent:
			if e.Key > 0 {
				switch e.Key {
				case 'q':
					return
				default:
					fmt.Println("key=", e.Key)
				}
			}
		case draw.ConfigEvent:
			s = w.Screen()
			b = s.Bounds()
			fmt.Println("Bounds: ", b)
			return
		}
	}
}
示例#5
0
func main() {
	var error os.Error
	game := new(Game)
	game.Reset = make(chan bool)
	game.Context, error = x11.NewWindow()
	if error != nil {
		fmt.Fprintf(os.Stderr, "x11失敗 %s\n", error)
		os.Exit(1)
	}
	game.Img = game.Context.Screen()
	game.Start = false

	// スレッド実行
	runtime.GOMAXPROCS(4)

	go func() {
		ch := game.Context.EventChan()
		for {
			// チャネル入力があるまでストップ
			i := <-ch
			switch i.(type) {
			case draw.MouseEvent:
				// マウスイベント待ち受け
				data, _ := i.(draw.MouseEvent)
				game.mouseEvent(data)
			case draw.KeyEvent:
				// キーボードイベント待ち受け
				data, _ := i.(draw.KeyEvent)
				game.keyboardEvent(data)
			case draw.ConfigEvent:
			case draw.ErrEvent:
				os.Exit(0)
			}
		}
	}()
	// タイマイベント待ち受け
	go game.timerEvent()

	for {
		// 初期設定
		initGame(game)
		game.createBlock()
		game.putBlock(game.Current, false)
		game.printBoard()
		game.Start = true
		<-game.Reset
	}
	close(game.Reset)
}
示例#6
0
文件: drw.go 项目: timtadh/goplay
func main() {
	//var x draw.Context;
	//var y os.Error;
	x, y := x11.NewWindow()
	if y != nil {
		fmt.Println("error")
	}
	if x == nil {
		fmt.Println("error")
	}
	fmt.Println("hello")
	for i := 0; i < 1000000000; i++ {
		fmt.Print("x")
	}
}
示例#7
0
func main() {
	defer nicetrace.Print()
	block = make(chan bool, 1)
	var err os.Error
	window, err = x11.NewWindow()
	if err != nil {
		fmt.Printf("%v\n", err)
	}
	clearScreen()
	cfg := roar.PosteriorCFGDefault()
	cfg.Partition = 1
	cfg.M = 1
	rpost = roar.New(cfg)
	running = true
	go drawLoop()
	go inferenceLoop()
	processEvents(window.EventChan())
	running = false
}
示例#8
0
func main() {
	runtime.GOMAXPROCS(2)
	context, error := x11.NewWindow()
	if error != nil {
		fmt.Fprintf(os.Stderr, "x11失敗 %s\n", error)
		os.Exit(1)
	}
	// 初期設定
	game := initGame()
	game.img = context.Screen()
	game.printBoard()

	go func() {
		// チャネル入力があるまでストップ
		<-context.QuitChan()
		os.Exit(0)
	}()

	block := false
	for {
		mouse := <-context.MouseChan()
		go func() {
			if (mouse.Buttons & 0x01) == 0x01 {
				// 左クリック検知
				x := mouse.Point.X / 31
				y := mouse.Point.Y / 31
				if x < MASU && y < MASU {
					if block == false {
						block = true
						game.startTurn(y, x)
						block = false
					} else {
						println("AI思考中・・・")
					}
				}
			}
		}()
		context.FlushImage()
	}
}
示例#9
0
func main() {
	ctxt, err := x11.NewWindow()
	if ctxt == nil {
		log.Fatalf("no window: %v", err)
	}
	screen := ctxt.Screen()

	bg := canvas.NewBackground(screen.(*image.RGBA), image.White, flushFunc(ctxt))
	cvs = canvas.NewCanvas(nil, bg.Rect())
	bg.SetItem(cvs)
	ec := ctxt.EventChan()
	cvs.Flush()

	for {
		select {
		case e := <-ec:
			switch e := e.(type) {
			case nil:
				if closed(ec) {
					log.Fatal("quitting")
					return
				}
			case draw.MouseEvent:
				if e.Buttons == 0 {
					break
				}
				if cvs.HandleMouse(cvs, e, ec) {
					fmt.Printf("handled mouse\n")
					break
				}
				fmt.Printf("raster maker\n")
				rasterMaker(e, ec)
			}
		}
	}
}
示例#10
0
文件: mandel.go 项目: zenoss/rog-go
func main() {
	flag.Parse()
	wctxt, err := x11.NewWindow()
	if wctxt == nil {
		log.Exitf("no window: %v", err)
	}
	screen := wctxt.Screen()

	ctxt := &context{}
	ctxt.iterations = *iterations

	bg := canvas.NewBackground(screen.(*image.RGBA), draw.White, flushFunc(wctxt))
	ctxt.cvs = canvas.NewCanvas(nil, bg.Rect())
	bg.SetItem(ctxt.cvs)

	ctxt.cache = NewTileTable()
	ctxt.setFractal(NewMandelbrot(topArea, ctxt.cvs.Rect(), false, 0, ctxt.iterations), draw.ZP)

	qc := wctxt.QuitChan()
	kc := wctxt.KeyboardChan()
	mc := wctxt.MouseChan()
	ctxt.cvs.Flush()
	for {
		select {
		case <-qc:
			log.Exit("quitting")
			return
		case m0 := <-mc:
			// b1 drag - drag mandel around.
			// double-b1 drag - zoom in to rectangle
			// douible-b1 click - zoom in a little
			// b2 click - julia
			// b2 drag - interactive julia
			// b3 zoom out
			if m0.Buttons == 0 {
				break
			}
			nclick := 0
			clicks, finalm := clicker(m0, mc)
			for _ = range clicks {
				nclick++
			}
			m := <-finalm
			dragging := m.Buttons != 0
			switch {
			case m0.Buttons&1 != 0:
				switch nclick {
				case 1:
					if dragging {
						ctxt.cvs.HandleMouse(ctxt.cvs, m, mc)
					}
				case 2:
					if dragging {
						ctxt.zoomRect(m, mc)
					} else {
						ctxt.zoomABit(m, mc)
					}
				}
			case m0.Buttons&2 != 0:
				switch nclick {
				case 1:
					if dragging {
						ctxt.interactiveJulia(m, mc)
					} else {
						ctxt.julia(m.Point)
					}
				}
			case m0.Buttons&4 != 0:
				ctxt.pop()
			}
		case <-kc:
		}
	}
}
示例#11
0
文件: ifsrnd.go 项目: taysom/va
func main() {
	flag.Parse()
	n := 100000
	if flag.NArg() > 0 {
		n, _ = strconv.Atoi(flag.Arg(0))
	}
	if flag.NArg() > 1 {
		Scale, _ = strconv.ParseFloat(flag.Arg(1), 64)
	}
	w, err := x11.NewWindow()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	v := make([]Point, n)
	ch := make(chan []Point)
	wait := make(chan int)

	if !*inlineGraphics {
		go goplot(w, ch, wait)
	}

	pic := Fern
	s := w.Screen()
	b := s.Bounds()
	fmt.Printf("Press 'q' to exit.\n\tinline: %v\n\twait:   %v.\n",
		*inlineGraphics, *waitForGraphics)
	ifs(v, pic)
	if *inlineGraphics {
		inlineplot(w, v)
	} else {
		ch <- v
		if *waitForGraphics {
			<-wait
		}
	}
	for event := range w.EventChan() {
		switch e := event.(type) {
		case draw.KeyEvent:
			if e.Key > 0 {
				switch e.Key {
				case 'c':
					clear(w.Screen())
				case 'f':
					pic = Fern
				case 'k':
					pic = Sierpinski
				case 's':
					pic = Square
				case 't':
					pic = Tree
				case 'q':
					return
				default:
					fmt.Println("key=", e.Key)
				}
			}
		case draw.MouseEvent:
			if e.Buttons != 0 {
				clear(s)
			}
			red := uint8((e.Loc.X << 8) / b.Max.X)
			green := uint8((e.Loc.Y << 8) / b.Max.Y)
			Color = color.RGBA{red, green, 0, 0xff}
			//fmt.Println("mouse=", m)
		case draw.ConfigEvent:
			s = w.Screen()
			b = s.Bounds()
			fmt.Println("Bounds: ", b)
			return
		}
		ifs(v, pic)
		if *inlineGraphics {
			inlineplot(w, v)
		} else {
			ch <- v
			if *waitForGraphics {
				<-wait
			}
		}
	}
	/*
		for {
			ifs(v, pic)
			if *inlineGraphics {
				inlineplot(c, v)
			} else {
				ch <- v
				if *waitForGraphics {
					<- wait
				}
			}
			select {
			case key := <- c.KeyboardChan():
				if (key > 0) {
					switch key {
					case 'c': clear(c.Screen());
					case 'f': pic = Fern
					case 'k': pic = Sierpinski
					case 's': pic = Square
					case 't': pic = Tree
					case 'q': return
					default: fmt.Println("key=", key)
					}
				}
			case m := <- c.MouseChan():
				if (m.Buttons != 0) {
					clear(s)
				}
				red := uint8((m.Point.X << 8) / b.Max.X)
				green := uint8((m.Point.Y << 8) / b.Max.Y)
				Color = image.RGBAColor{red, green, 0, 0xff}
				//fmt.Println("mouse=", m)
			case resize := <- c.ResizeChan():
				fmt.Println("Resize=", resize)
			case <- c.QuitChan():
				return
			}
		}
	*/
}