mirror of
https://github.com/maaslalani/confetty.git
synced 2024-11-25 00:56:40 +00:00
array sample refactor
This commit is contained in:
parent
15dbe41db2
commit
ebb2591f66
9
pkg/array/array.go
Normal file
9
pkg/array/array.go
Normal file
@ -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))]
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user