diff --git a/pkg/array/array.go b/pkg/array/array.go new file mode 100644 index 0000000..365c261 --- /dev/null +++ b/pkg/array/array.go @@ -0,0 +1,9 @@ +package array + +import "math/rand" + +// Sample returns a random element from an array +// (can't wait for generics!) +func Sample(s []string) string { + return s[rand.Intn(len(s))] +} diff --git a/pkg/confetty/confetty.go b/pkg/confetty/confetty.go index c01306d..1f7c9f1 100644 --- a/pkg/confetty/confetty.go +++ b/pkg/confetty/confetty.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/maaslalani/confetty/pkg/array" "github.com/maaslalani/confetty/pkg/physics" "github.com/charmbracelet/bubbles/viewport" @@ -14,17 +15,12 @@ import ( "golang.org/x/term" ) -const ( - fps = 60.0 -) +const fps = 60.0 -var colors = []lipgloss.Color{ - lipgloss.Color("#a864fd"), - lipgloss.Color("#29cdff"), - lipgloss.Color("#78ff44"), - lipgloss.Color("#ff718d"), - lipgloss.Color("#fdff6a"), -} +var ( + colors = []string{"#a864fd", "#29cdff", "#78ff44", "#ff718d", "#fdff6a"} + characters = []string{"▄", "▀", "█"} // "▓", "▒", "░"} +) type frameMsg time.Time @@ -52,8 +48,6 @@ type Particle struct { color lipgloss.Color } -var characters = []string{"▄", "▀", "█"} // "▓", "▒", "░"} - func InitialModel() model { particles := []*Particle{} @@ -67,14 +61,17 @@ func InitialModel() model { y := float64(height / 2) p := &Particle{ - char: lipgloss.NewStyle().Foreground(colors[rand.Intn(len(colors))]).Render(characters[rand.Intn(len(characters))]), physics: physics.New( physics.Vector{X: x, Y: y}, physics.Vector{X: (rand.Float64() - 0.5) * 100, Y: (rand.Float64() - 0.5) * 100}, physics.Vector(physics.Gravity), fps, ), + char: lipgloss.NewStyle(). + Foreground(lipgloss.Color(array.Sample(colors))). + Render(array.Sample(characters)), } + particles = append(particles, p) }