examples/triangles: Fix terms

This commit is contained in:
Hajime Hoshi 2018-08-14 01:55:22 +09:00
parent 1b8cad4e1d
commit 7807488cc7

View File

@ -43,8 +43,8 @@ func init() {
var (
vertices []ebiten.Vertex
numVerticesToDraw = 10
prevNumVerticesToDraw = 0
ngon = 10
prevNgon = 0
)
func genVertices(num int) []ebiten.Vertex {
@ -106,21 +106,21 @@ func genVertices(num int) []ebiten.Vertex {
func update(screen *ebiten.Image) error {
if inpututil.IsKeyJustPressed(ebiten.KeyLeft) {
numVerticesToDraw--
if numVerticesToDraw < 1 {
numVerticesToDraw = 1
ngon--
if ngon < 1 {
ngon = 1
}
}
if inpututil.IsKeyJustPressed(ebiten.KeyRight) {
numVerticesToDraw++
if numVerticesToDraw > 120 {
numVerticesToDraw = 120
ngon++
if ngon > 120 {
ngon = 120
}
}
if prevNumVerticesToDraw != numVerticesToDraw || len(vertices) == 0 {
vertices = genVertices(numVerticesToDraw)
prevNumVerticesToDraw = numVerticesToDraw
if prevNgon != ngon || len(vertices) == 0 {
vertices = genVertices(ngon)
prevNgon = ngon
}
if ebiten.IsDrawingSkipped() {
@ -129,12 +129,12 @@ func update(screen *ebiten.Image) error {
op := &ebiten.DrawTrianglesOptions{}
indices := []uint16{}
for i := 0; i < numVerticesToDraw; i++ {
indices = append(indices, uint16(i), uint16(i+1)%uint16(numVerticesToDraw), uint16(numVerticesToDraw))
for i := 0; i < ngon; i++ {
indices = append(indices, uint16(i), uint16(i+1)%uint16(ngon), uint16(ngon))
}
screen.DrawTriangles(vertices, indices, emptyImage, op)
msg := fmt.Sprintf("TPS: %0.2f\nVertices: %d\nPress <- or -> to change the number of the vertices", ebiten.CurrentTPS(), numVerticesToDraw)
msg := fmt.Sprintf("TPS: %0.2f\n%d-gon\nPress <- or -> to change the number of the vertices", ebiten.CurrentTPS(), ngon)
ebitenutil.DebugPrint(screen, msg)
return nil
}