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"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/maaslalani/confetty/pkg/array"
|
||||||
"github.com/maaslalani/confetty/pkg/physics"
|
"github.com/maaslalani/confetty/pkg/physics"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/viewport"
|
"github.com/charmbracelet/bubbles/viewport"
|
||||||
@ -14,17 +15,12 @@ import (
|
|||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const fps = 60.0
|
||||||
fps = 60.0
|
|
||||||
)
|
|
||||||
|
|
||||||
var colors = []lipgloss.Color{
|
var (
|
||||||
lipgloss.Color("#a864fd"),
|
colors = []string{"#a864fd", "#29cdff", "#78ff44", "#ff718d", "#fdff6a"}
|
||||||
lipgloss.Color("#29cdff"),
|
characters = []string{"▄", "▀", "█"} // "▓", "▒", "░"}
|
||||||
lipgloss.Color("#78ff44"),
|
)
|
||||||
lipgloss.Color("#ff718d"),
|
|
||||||
lipgloss.Color("#fdff6a"),
|
|
||||||
}
|
|
||||||
|
|
||||||
type frameMsg time.Time
|
type frameMsg time.Time
|
||||||
|
|
||||||
@ -52,8 +48,6 @@ type Particle struct {
|
|||||||
color lipgloss.Color
|
color lipgloss.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
var characters = []string{"▄", "▀", "█"} // "▓", "▒", "░"}
|
|
||||||
|
|
||||||
func InitialModel() model {
|
func InitialModel() model {
|
||||||
particles := []*Particle{}
|
particles := []*Particle{}
|
||||||
|
|
||||||
@ -67,14 +61,17 @@ func InitialModel() model {
|
|||||||
y := float64(height / 2)
|
y := float64(height / 2)
|
||||||
|
|
||||||
p := &Particle{
|
p := &Particle{
|
||||||
char: lipgloss.NewStyle().Foreground(colors[rand.Intn(len(colors))]).Render(characters[rand.Intn(len(characters))]),
|
|
||||||
physics: physics.New(
|
physics: physics.New(
|
||||||
physics.Vector{X: x, Y: y},
|
physics.Vector{X: x, Y: y},
|
||||||
physics.Vector{X: (rand.Float64() - 0.5) * 100, Y: (rand.Float64() - 0.5) * 100},
|
physics.Vector{X: (rand.Float64() - 0.5) * 100, Y: (rand.Float64() - 0.5) * 100},
|
||||||
physics.Vector(physics.Gravity),
|
physics.Vector(physics.Gravity),
|
||||||
fps,
|
fps,
|
||||||
),
|
),
|
||||||
|
char: lipgloss.NewStyle().
|
||||||
|
Foreground(lipgloss.Color(array.Sample(colors))).
|
||||||
|
Render(array.Sample(characters)),
|
||||||
}
|
}
|
||||||
|
|
||||||
particles = append(particles, p)
|
particles = append(particles, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user