mirror of
https://github.com/maaslalani/confetty.git
synced 2024-11-22 07:36:40 +00:00
simulatin package
This commit is contained in:
parent
c5f3d26331
commit
316b181e43
@ -1,5 +1,3 @@
|
|||||||
// TODO: Lots of code duplication between fireworks and confetti extract to a
|
|
||||||
// `particle system` package
|
|
||||||
package fireworks
|
package fireworks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -9,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/maaslalani/confetty/array"
|
"github.com/maaslalani/confetty/array"
|
||||||
"github.com/maaslalani/confetty/physics"
|
"github.com/maaslalani/confetty/physics"
|
||||||
|
"github.com/maaslalani/confetty/simulation"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
@ -35,20 +34,20 @@ func animate() tea.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
system *System
|
system *simulation.System
|
||||||
}
|
}
|
||||||
|
|
||||||
func spawn(width, height int) []Particle {
|
func spawn(width, height int) []simulation.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)
|
||||||
|
|
||||||
particles := []Particle{}
|
particles := []simulation.Particle{}
|
||||||
|
|
||||||
x := rand.Float64() * float64(width)
|
x := rand.Float64() * float64(width)
|
||||||
y := rand.Float64() * float64(height)
|
y := rand.Float64() * float64(height)
|
||||||
|
|
||||||
for i := 0; i < numParticles; i++ {
|
for i := 0; i < numParticles; i++ {
|
||||||
p := Particle{
|
p := simulation.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},
|
||||||
@ -68,9 +67,9 @@ func InitialModel() model {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return model{system: &System{
|
return model{system: &simulation.System{
|
||||||
Particles: spawn(width, height),
|
Particles: spawn(width, height),
|
||||||
Frame: Frame{
|
Frame: simulation.Frame{
|
||||||
Width: width,
|
Width: width,
|
||||||
Height: height,
|
Height: height,
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package fireworks
|
package simulation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
Loading…
Reference in New Issue
Block a user