small tweaks to firework sim

This commit is contained in:
Maas Lalani 2021-08-07 20:09:20 -04:00
parent 2918dcbd88
commit 3a02ea29ce
No known key found for this signature in database
GPG Key ID: F53774FA051C052A

View File

@ -20,12 +20,12 @@ import (
const ( const (
framesPerSecond = 60.0 framesPerSecond = 60.0
numParticles = 75 numParticles = 50
) )
var ( var (
colors = []string{"#fdff6a", "#ff718d"} colors = []string{"#fdff6a", "#ff718d"}
characters = []string{"•"} characters = []string{"+", "*", "•"}
// characters = []string{"▄", "▀"} // characters = []string{"▄", "▀"}
) )
@ -53,7 +53,6 @@ type model struct {
type Particle struct { type Particle struct {
char string char string
physics *physics.Physics physics *physics.Physics
radius float64
} }
func spawn() []*Particle { func spawn() []*Particle {
@ -64,7 +63,6 @@ func spawn() []*Particle {
color := lipgloss.Color(array.Sample(colors)) color := lipgloss.Color(array.Sample(colors))
v := float64(rand.Intn(10) + 20.0) v := float64(rand.Intn(10) + 20.0)
r := float64(rand.Intn(5) + 10)
particles := []*Particle{} particles := []*Particle{}
@ -76,13 +74,12 @@ func spawn() []*Particle {
physics: physics.New( physics: physics.New(
physics.Point{X: x, Y: y}, physics.Point{X: x, Y: y},
physics.Vector{X: math.Cos(float64(i)) * v, Y: math.Sin(float64(i)) * v / 2}, physics.Vector{X: math.Cos(float64(i)) * v, Y: math.Sin(float64(i)) * v / 2},
physics.Vector{Y: 2}, physics.Vector(physics.Gravity),
framesPerSecond, framesPerSecond,
), ),
char: lipgloss.NewStyle(). char: lipgloss.NewStyle().
Foreground(color). Foreground(color).
Render(array.Sample(characters)), Render(array.Sample(characters)),
radius: r,
} }
particles = append(particles, p) particles = append(particles, p)
@ -120,14 +117,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
particlesVisible -= 1 particlesVisible -= 1
continue continue
} }
// Particle has reached its distance from the radius.
// In the fireworks simulation, firework particles fade after reaching a certain point
// just like in real life, so we don't render them if they've passed a certain distance
if p.physics.Displacement() > p.radius {
particlesVisible -= 1
continue
}
} }
if particlesVisible <= 0 { if particlesVisible <= 0 {