mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
examples/noise: Refactoring
This commit is contained in:
parent
6e5830739f
commit
13974808a6
@ -47,20 +47,23 @@ func (r *rand) next() uint32 {
|
|||||||
return r.w
|
return r.w
|
||||||
}
|
}
|
||||||
|
|
||||||
var randInstance = &rand{12345678, 4185243, 776511, 45411}
|
var theRand = &rand{12345678, 4185243, 776511, 45411}
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
|
// Generate the noise with random RGB values.
|
||||||
const l = screenWidth * screenHeight
|
const l = screenWidth * screenHeight
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
x := randInstance.next()
|
x := theRand.next()
|
||||||
noiseImage.Pix[4*i] = uint8(x >> 24)
|
noiseImage.Pix[4*i] = uint8(x >> 24)
|
||||||
noiseImage.Pix[4*i+1] = uint8(x >> 16)
|
noiseImage.Pix[4*i+1] = uint8(x >> 16)
|
||||||
noiseImage.Pix[4*i+2] = uint8(x >> 8)
|
noiseImage.Pix[4*i+2] = uint8(x >> 8)
|
||||||
noiseImage.Pix[4*i+3] = 0xff
|
noiseImage.Pix[4*i+3] = 0xff
|
||||||
}
|
}
|
||||||
|
|
||||||
if ebiten.IsRunningSlowly() {
|
if ebiten.IsRunningSlowly() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.ReplacePixels(noiseImage.Pix)
|
screen.ReplacePixels(noiseImage.Pix)
|
||||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %f", ebiten.CurrentFPS()))
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %f", ebiten.CurrentFPS()))
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user