當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Surface.Set方法代碼示例

本文整理匯總了Golang中github.com/banthar/Go-SDL/sdl.Surface.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Surface.Set方法的具體用法?Golang Surface.Set怎麽用?Golang Surface.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/banthar/Go-SDL/sdl.Surface的用法示例。


在下文中一共展示了Surface.Set方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Line

// Draw a line
func Line(screen *sdl.Surface, x1 int, y1 int, x2 int, y2 int, color sdl.Color) {
	if x1 == x2 || y1 == y2 {
		return
	}

	startx, stopx := minmax(x1, x2)
	starty, stopy := minmax(y1, y2)

	xdiff := stopx - startx
	ydiff := stopy - starty

	if xdiff > ydiff {
		// We're going along X
		y := float32(starty)
		ystep := float32(ydiff) / float32(xdiff)
		if y1 != starty {
			// Move in the other direction along Y
			ystep = -ystep
			y = float32(stopy)
		}
		// Draw the line
		for x := startx; x < stopx; x++ {
			screen.Set(x, int(y), color)
			y += ystep
		}
	} else {
		// We're going along Y
		x := float32(startx)
		xstep := float32(xdiff) / float32(ydiff)
		if x1 != startx {
			// Move in the other direction along X
			xstep = -xstep
			x = float32(stopx)
		}
		// Draw the line
		for y := starty; y < stopy; y++ {
			screen.Set(int(x), y, color)
			x += xstep
		}
	}
}
開發者ID:xyproto,項目名稱:rasterizer,代碼行數:42,代碼來源:rasterizer.go


注:本文中的github.com/banthar/Go-SDL/sdl.Surface.Set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。