This commit is contained in:
Louis Dalibard 2025-01-31 22:40:14 +01:00
parent 4c182ccb8a
commit 8a1b0a0597
2 changed files with 26 additions and 10 deletions

View File

@ -47,6 +47,8 @@ type ConfigS struct {
AccentColor string AccentColor string
FirstColor string FirstColor string
ThirdColor string ThirdColor string
CopyPreviousFrame bool
CopyPreviousFrameAlpha float32
} }
var DefaultConfig = ConfigS{ var DefaultConfig = ConfigS{
@ -83,6 +85,8 @@ var DefaultConfig = ConfigS{
AccentColor: "FF0000", AccentColor: "FF0000",
FirstColor: "FF0000", FirstColor: "FF0000",
ThirdColor: "FF0000", ThirdColor: "FF0000",
CopyPreviousFrame: true,
CopyPreviousFrameAlpha: 0.4,
} }
var Config ConfigS var Config ConfigS

32
main.go
View File

@ -31,20 +31,24 @@ import (
type Game struct { type Game struct {
} }
var pressedKeys []ebiten.Key
func (g *Game) Update() error { func (g *Game) Update() error {
pressedKeys = nil
pressedKeys = inpututil.AppendPressedKeys(pressedKeys)
return nil return nil
} }
var prevFrame *ebiten.Image var prevFrame *ebiten.Image
var firstFrame = true var firstFrame = true
var ColorScale ebiten.ColorScale
func (g *Game) Draw(screen *ebiten.Image) { func (g *Game) Draw(screen *ebiten.Image) {
if firstFrame { if config.Config.CopyPreviousFrame {
prevFrame = screen if !firstFrame {
firstFrame = false op := &ebiten.DrawImageOptions{}
} else { op.ColorScale.ScaleAlpha(config.Config.CopyPreviousFrameAlpha)
screen.DrawImage(prevFrame, &ebiten.DrawImageOptions{ColorScale: ColorScale}) screen.DrawImage(prevFrame, op)
}
} }
scale := min(config.Config.WindowWidth, config.Config.WindowHeight) / 2 scale := min(config.Config.WindowWidth, config.Config.WindowHeight) / 2
var AX float32 var AX float32
@ -53,8 +57,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
var BY float32 var BY float32
var numSamples = config.Config.ReadBufferSize / audio.SampleSizeInBytes * 4 var numSamples = config.Config.ReadBufferSize / audio.SampleSizeInBytes * 4
var FFTBuffer = make([]float64, numSamples) var FFTBuffer = make([]float64, numSamples)
var pressedKeys []ebiten.Key
inpututil.AppendPressedKeys(pressedKeys)
if slices.Contains(pressedKeys, ebiten.KeyF) { if slices.Contains(pressedKeys, ebiten.KeyF) {
config.SingleChannel = !config.SingleChannel config.SingleChannel = !config.SingleChannel
} }
@ -167,7 +170,16 @@ func (g *Game) Draw(screen *ebiten.Image) {
Size: 32, Size: 32,
}, op) }, op)
} }
prevFrame = screen
if config.Config.CopyPreviousFrame {
prevFrame.Clear()
prevFrame.DrawImage(screen, nil)
}
if firstFrame {
firstFrame = false
// f, _ := os.Create("image.png")
// png.Encode(f, prevFrame)
}
} }
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
@ -190,7 +202,7 @@ func main() {
screenW, screenH := ebiten.Monitor().Size() screenW, screenH := ebiten.Monitor().Size()
ebiten.SetWindowPosition(screenW/2-int(config.Config.WindowWidth)/2, screenH/2-int(config.Config.WindowHeight)/2) ebiten.SetWindowPosition(screenW/2-int(config.Config.WindowWidth)/2, screenH/2-int(config.Config.WindowHeight)/2)
ebiten.SetVsyncEnabled(true) ebiten.SetVsyncEnabled(true)
ColorScale.SetA(0.8) prevFrame = ebiten.NewImage(int(config.Config.WindowWidth), int(config.Config.WindowHeight))
if err := ebiten.RunGameWithOptions(&Game{}, &ebiten.RunGameOptions{ScreenTransparent: true}); err != nil { if err := ebiten.RunGameWithOptions(&Game{}, &ebiten.RunGameOptions{ScreenTransparent: true}); err != nil {
log.Fatal(err) log.Fatal(err)
} }