Beispiel #1
0
// blendCheckered is basically a copy of xgraphics.Blend with no interfaces.
// (It's faster.) Also, it is hardcoded to blend into a checkered background.
func blendCheckered(dest *xgraphics.Image) {
	dsrc := dest.Bounds()
	dmnx, dmxx, dmny, dmxy := dsrc.Min.X, dsrc.Max.X, dsrc.Min.Y, dsrc.Max.Y

	clr1 := xgraphics.BGRA{B: 0xff, G: 0xff, R: 0xff, A: 0xff}
	clr2 := xgraphics.BGRA{B: 0xde, G: 0xdc, R: 0xdf, A: 0xff}

	var dx, dy int
	var bgra, clr xgraphics.BGRA
	for dx = dmnx; dx < dmxx; dx++ {
		for dy = dmny; dy < dmxy; dy++ {
			if dx%30 >= 15 {
				if dy%30 >= 15 {
					clr = clr1
				} else {
					clr = clr2
				}
			} else {
				if dy%30 >= 15 {
					clr = clr2
				} else {
					clr = clr1
				}
			}

			bgra = dest.At(dx, dy).(xgraphics.BGRA)
			dest.SetBGRA(dx, dy, xgraphics.BlendBGRA(clr, bgra))
		}
	}
}
Beispiel #2
0
func updater(img *xgraphics.Image, win *xwindow.Window) {
	//We keep track of times based on 1024 frames
	frame := 0
	start := time.Now()
	var genStart, drawStart time.Time
	var genTotal, drawTotal time.Duration

	for {
		frame = frame + 1
		if frame > 1024 {
			frame = 0
			log.Printf("Time elapsed: %s\n", time.Now().Sub(start))
			log.Printf("Time generate: %s\n", genTotal)
			log.Printf("Time drawing: %s\n", drawTotal)
			start = time.Now()
			drawTotal, genTotal = 0, 0
		}

		genStart = time.Now()
		var x, y, i int
		for y = 0; y < 768; y++ {
			//set last pixel back to black
			img.SetBGRA(frame-1, y, xgraphics.BGRA{0, 0, 0, 255})
			for i = 0; i < 10; i++ {
				x = i + frame
				if x > 1024 {
					x = 1024
				}
				img.SetBGRA(x, y, xgraphics.BGRA{0, 0, 255, 255})
			}
		}
		genTotal += time.Now().Sub(genStart)

		drawStart = time.Now()
		//hopefully using checked will block us from drawing again before x
		//draws although XDraw might block anyway, we can check for an error
		//here
		err := img.XDrawChecked()
		if err != nil {
			log.Println(err)
			return
		}
		//img.XDraw()

		img.XPaint(win.Id)
		drawTotal += time.Now().Sub(drawStart)
	}
}