examples/stars: refactor (#2070)

Minor adjustments because of:

* Function abs(int) is unused.
* Color fields are assigned without explicit names
* Color variable shadows the color package name
This commit is contained in:
Julian Merkle 2022-04-13 11:42:04 +02:00 committed by GitHub
parent 8e8831a4d4
commit d68f770561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,13 +34,6 @@ const (
starsNum = 1024 starsNum = 1024
) )
func abs(a int) int {
if a < 0 {
return -a
}
return a
}
type Star struct { type Star struct {
fromx, fromy, tox, toy, brightness float64 fromx, fromy, tox, toy, brightness float64
} }
@ -68,11 +61,11 @@ func (s *Star) Update(x, y float64) {
} }
func (s *Star) Draw(screen *ebiten.Image) { func (s *Star) Draw(screen *ebiten.Image) {
color := color.RGBA{uint8(0xbb * s.brightness / 0xff), c := color.RGBA{R: uint8(0xbb * s.brightness / 0xff),
uint8(0xdd * s.brightness / 0xff), G: uint8(0xdd * s.brightness / 0xff),
uint8(0xff * s.brightness / 0xff), B: uint8(0xff * s.brightness / 0xff),
0xff} A: 0xff}
ebitenutil.DrawLine(screen, s.fromx/scale, s.fromy/scale, s.tox/scale, s.toy/scale, color) ebitenutil.DrawLine(screen, s.fromx/scale, s.fromy/scale, s.tox/scale, s.toy/scale, c)
} }
type Game struct { type Game struct {