mirror of
https://github.com/maaslalani/confetty.git
synced 2024-11-25 17:16:40 +00:00
unlimited confetti
This commit is contained in:
parent
eb18e9536b
commit
9c99591a2b
@ -22,7 +22,8 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
colors = []string{"#a864fd", "#29cdff", "#78ff44", "#ff718d", "#fdff6a"}
|
colors = []string{"#a864fd", "#29cdff", "#78ff44", "#ff718d", "#fdff6a"}
|
||||||
characters = []string{"▄", "▀"} // "█", "▓", "▒", "░"}
|
characters = []string{"█", "▓", "▒", "░", "▄", "▀"}
|
||||||
|
// characters = []string{"▄", "▀"}
|
||||||
)
|
)
|
||||||
|
|
||||||
type frameMsg time.Time
|
type frameMsg time.Time
|
||||||
@ -125,7 +126,14 @@ func (m model) View() string {
|
|||||||
y := p.physics.PosY()
|
y := p.physics.PosY()
|
||||||
x := p.physics.PosX()
|
x := p.physics.PosX()
|
||||||
|
|
||||||
if y < 0 || y >= m.viewport.Height-1 || x < 0 || x >= m.viewport.Width-1 {
|
if y < 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Particle is out of view
|
||||||
|
if y >= m.viewport.Height-1 || x < 0 || x >= m.viewport.Width-1 {
|
||||||
|
// loop motion
|
||||||
|
p.physics.Reset()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package physics
|
package physics
|
||||||
|
|
||||||
import "math"
|
import (
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
type Position Vector
|
type Position Vector
|
||||||
type Velocity Vector
|
type Velocity Vector
|
||||||
@ -11,10 +13,15 @@ var Gravity = Acceleration{
|
|||||||
Y: 9.81,
|
Y: 9.81,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Physics struct {
|
type Motion struct {
|
||||||
pos Position
|
pos Position
|
||||||
vel Velocity
|
vel Velocity
|
||||||
acc Acceleration
|
acc Acceleration
|
||||||
|
}
|
||||||
|
|
||||||
|
type Physics struct {
|
||||||
|
current Motion
|
||||||
|
initial Motion
|
||||||
fps float64
|
fps float64
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,23 +31,31 @@ type Vector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(pos, vel, acc Vector, fps float64) *Physics {
|
func New(pos, vel, acc Vector, fps float64) *Physics {
|
||||||
return &Physics{
|
motion := Motion{
|
||||||
pos: Position(pos),
|
pos: Position(pos),
|
||||||
vel: Velocity(vel),
|
vel: Velocity(vel),
|
||||||
acc: Acceleration(acc),
|
acc: Acceleration(acc),
|
||||||
|
}
|
||||||
|
return &Physics{
|
||||||
|
initial: motion,
|
||||||
|
current: motion,
|
||||||
fps: fps,
|
fps: fps,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Physics) Reset() {
|
||||||
|
p.current = p.initial
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Physics) Update() {
|
func (p *Physics) Update() {
|
||||||
p.pos.Y, p.vel.Y = p.pos.Y+p.vel.Y/p.fps, p.vel.Y+p.acc.Y/p.fps
|
p.current.pos.Y, p.current.vel.Y = p.current.pos.Y+p.current.vel.Y/p.fps, p.current.vel.Y+p.current.acc.Y/p.fps
|
||||||
p.pos.X, p.vel.X = p.pos.X+p.vel.X/p.fps, p.vel.X+p.acc.X/p.fps
|
p.current.pos.X, p.current.vel.X = p.current.pos.X+p.current.vel.X/p.fps, p.current.vel.X+p.current.acc.X/p.fps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Physics) PosX() int {
|
func (p Physics) PosX() int {
|
||||||
return int(math.Round(p.pos.X))
|
return int(math.Round(p.current.pos.X))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Physics) PosY() int {
|
func (p Physics) PosY() int {
|
||||||
return int(math.Round(p.pos.Y))
|
return int(math.Round(p.current.pos.Y))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user