本文整理匯總了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
}
}
}