From 49e544d1b788f6db63ac76199cbbcf77eda9ca00 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 8 Jul 2019 02:00:16 +0200 Subject: ... --- fire/main.go | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/fire/main.go b/fire/main.go index 1f8f035..093ef2a 100644 --- a/fire/main.go +++ b/fire/main.go @@ -5,7 +5,6 @@ package main import ( "errors" "flag" - "fmt" "image" "image/color" "log" @@ -14,7 +13,6 @@ import ( "github.com/disintegration/imaging" "github.com/hajimehoshi/ebiten" - "github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/inpututil" ) @@ -58,9 +56,8 @@ var palette = color.Palette{ } type drawContext struct { - img *image.Paletted - isOn bool - debug bool + img *image.Paletted + on bool } func newDrawContext(x, y int) *drawContext { @@ -69,16 +66,19 @@ func newDrawContext(x, y int) *drawContext { return &drawContext{img: img} } -func (dc *drawContext) toggle() *drawContext { - var c uint8 - if !dc.isOn { - c = uint8(len(palette) - 1) +func seed(img *image.Paletted, c int) { + for x := 0; x < img.Bounds().Max.X; x++ { + img.SetColorIndex(x, 0, uint8(c)) } - r := dc.img.Bounds().Max - for x := 0; x < r.X; x++ { - dc.img.SetColorIndex(x, 0, c) +} + +func (dc *drawContext) toggle() *drawContext { + if dc.on { + seed(dc.img, 0) + } else { + seed(dc.img, len(palette)-1) } - dc.isOn = !dc.isOn + dc.on = !dc.on return dc } @@ -100,17 +100,12 @@ func (dc *drawContext) update(screen *ebiten.Image) error { switch { case inpututil.IsKeyJustPressed(ebiten.KeyQ): return errors.New("exit") - case inpututil.IsKeyJustPressed(ebiten.KeyD): - dc.debug = !dc.debug case inpututil.IsKeyJustPressed(ebiten.KeySpace): dc.toggle() } drawTo(dc.img) if !ebiten.IsDrawingSkipped() { screen.ReplacePixels(imaging.FlipV(dc.img).Pix) - if dc.debug { - ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f", ebiten.CurrentTPS())) - } } return nil } -- cgit v1.2.3