diff --git a/confetti/confetti.go b/confetti/confetti.go index 167912c..b3aee21 100644 --- a/confetti/confetti.go +++ b/confetti/confetti.go @@ -93,14 +93,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil case frameMsg: m.system.Update() - - for i := len(m.system.Particles) - 1; i >= 0; i-- { - p := m.system.Particles[i].Physics.Position() - if p.X > float64(m.system.Frame.Width) || p.X < 0 || p.Y > float64(m.system.Frame.Height) { - m.system.Particles = simulation.RemoveParticleFromArray(m.system.Particles, i) - } - } - return m, animate() case tea.WindowSizeMsg: m.system.Frame.Width = msg.Width diff --git a/fireworks/fireworks.go b/fireworks/fireworks.go index 870da4e..715731c 100644 --- a/fireworks/fireworks.go +++ b/fireworks/fireworks.go @@ -94,14 +94,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil case frameMsg: m.system.Update() - - for i := len(m.system.Particles) - 1; i >= 0; i-- { - p := m.system.Particles[i].Physics.Position() - if p.X > float64(m.system.Frame.Width) || p.X < 0 || p.Y > float64(m.system.Frame.Height) { - m.system.Particles = simulation.RemoveParticleFromArray(m.system.Particles, i) - } - } - return m, animate() case tea.WindowSizeMsg: m.system.Frame.Width = msg.Width diff --git a/simulation/simulation.go b/simulation/simulation.go index e7a494b..5ec862b 100644 --- a/simulation/simulation.go +++ b/simulation/simulation.go @@ -29,8 +29,13 @@ func RemoveParticleFromArray(s []Particle, i int) []Particle { } func (s *System) Update() { - for _, p := range s.Particles { - p.Physics.Update() + for i := len(s.Particles) - 1; i >= 0; i-- { + p := s.Particles[i].Physics.Position() + if p.X > float64(s.Frame.Width) || p.X < 0 || p.Y > float64(s.Frame.Height) { + s.Particles = RemoveParticleFromArray(s.Particles, i) + } else { + s.Particles[i].Physics.Update() + } } }