mirror of
https://github.com/maaslalani/confetty.git
synced 2024-12-22 06:06:39 +00:00
small tweaks to firework sim
This commit is contained in:
parent
2918dcbd88
commit
3a02ea29ce
@ -20,12 +20,12 @@ import (
|
||||
|
||||
const (
|
||||
framesPerSecond = 60.0
|
||||
numParticles = 75
|
||||
numParticles = 50
|
||||
)
|
||||
|
||||
var (
|
||||
colors = []string{"#fdff6a", "#ff718d"}
|
||||
characters = []string{"•"}
|
||||
characters = []string{"+", "*", "•"}
|
||||
// characters = []string{"▄", "▀"}
|
||||
)
|
||||
|
||||
@ -53,7 +53,6 @@ type model struct {
|
||||
type Particle struct {
|
||||
char string
|
||||
physics *physics.Physics
|
||||
radius float64
|
||||
}
|
||||
|
||||
func spawn() []*Particle {
|
||||
@ -64,7 +63,6 @@ func spawn() []*Particle {
|
||||
|
||||
color := lipgloss.Color(array.Sample(colors))
|
||||
v := float64(rand.Intn(10) + 20.0)
|
||||
r := float64(rand.Intn(5) + 10)
|
||||
|
||||
particles := []*Particle{}
|
||||
|
||||
@ -76,13 +74,12 @@ func spawn() []*Particle {
|
||||
physics: physics.New(
|
||||
physics.Point{X: x, Y: y},
|
||||
physics.Vector{X: math.Cos(float64(i)) * v, Y: math.Sin(float64(i)) * v / 2},
|
||||
physics.Vector{Y: 2},
|
||||
physics.Vector(physics.Gravity),
|
||||
framesPerSecond,
|
||||
),
|
||||
char: lipgloss.NewStyle().
|
||||
Foreground(color).
|
||||
Render(array.Sample(characters)),
|
||||
radius: r,
|
||||
}
|
||||
|
||||
particles = append(particles, p)
|
||||
@ -120,14 +117,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
particlesVisible -= 1
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user