本文整理汇总了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
}
}
}