示例#1
0
文件: boop.go 项目: karlek/boop
// Error wrapper.
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	if len(flag.Args()) < 1 {
		usage()
		os.Exit(0)
	}

	defer profile.Start(profile.CPUProfile).Stop()
	// Count go routines.
	osqChan := make(chan Osquarulda)
	for _, name := range flag.Args() {
		go errWrapLookup(name, osqChan)
	}

	// Download waitgroup.
	wg := new(sync.WaitGroup)
	for argc := flag.NArg(); argc > 0; argc-- {
		osq := <-osqChan
		// Ignore empty images.
		if osq.ImgUrl == nil {
			continue
		}

		go errWrapDownload(osq, wg)
		wg.Add(1)
	}
	// Wait for downloads!
	wg.Wait()
}
示例#2
0
文件: vanilj.go 项目: karlek/vanilj
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	defer profile.Start(profile.CPUProfile).Stop()

	err := renderMandelbrot()
	if err != nil {
		log.Fatalln(err)
	}
}
示例#3
0
文件: a.go 项目: karlek/vanilj
// simple demonstrates how to draw images using the Draw and DrawRect methods.
// It also gives an example of a basic event loop.
func simple() (err error) {
	runtime.GOMAXPROCS(runtime.NumCPU())
	defer profile.Start(profile.CPUProfile).Stop()

	// Open the window.
	err = win.Open(width, height, win.Resizeable)
	if err != nil {
		return err
	}
	defer win.Close()

	// Load image resources.
	err = loadResources()
	if err != nil {
		return err
	}
	defer freeResources()

	// start and frames will be used to calculate the average FPS of the
	// application.
	start := time.Now()
	frames := 0

	// Render the images onto the window.
	err = render()
	if err != nil {
		return err
	}

	// Update and event loop.
	for {
		// Display window updates on screen.
		err = win.Update()
		if err != nil {
			return err
		}
		frames++

		// Poll events until the event queue is empty.
		for e := win.PollEvent(); e != nil; e = win.PollEvent() {
			fmt.Printf("%T event: %v\n", e, e)
			switch obj := e.(type) {
			case we.KeyPress:
				r := obj.Key.String()
				err = zz(r)
			case we.KeyRepeat:
				r := obj.Key.String()
				err = zz(r)
			case we.KeyRune:
				r := obj.String()
				err = zz(r)
			}
			if err != nil {
				return err
			}
			switch e.(type) {
			case we.Close:
				displayFPS(start, frames)
				// Close the application.
				return nil
			case we.Resize:
				// Rerender the images onto the window after resize events.
				err = render()
				if err != nil {
					return err
				}
			}
		}

		// Cap refresh rate at 30 FPS.
		time.Sleep(time.Second / 30)
	}
}