func newBall() *Ball { b := &Ball{ Graphics: pixi.NewGraphics(), x: 0, y: 0, } b.LineStyle(3, 0xff9387*rand.Float64(), 1) bs = append(bs, b) return b }
func getParticle(x, y float64) *Particle { var p *Particle if len(ps) >= MAX_PARTICLES { pool = append(pool, ps[0]) ps = ps[1:] } if len(pool) > 0 { p = pool[0] pool = pool[1:] } else { p = &Particle{ Graphics: pixi.NewGraphics(), } } p.init(x, y) return p }
"github.com/Archs/js/dom" "github.com/Archs/js/raf" "github.com/Archs/pixi" "math" // "math" "math/rand" ) const ( MAX_PARTICLES = 280 ) var ( stage = pixi.NewContainer() renderer *pixi.Renderer ctx = pixi.NewGraphics() COLOURS = []float64{0x69D2E7, 0xA7DBD8, 0xE0E4CC, 0xF38630, 0xFA6900, 0xFF4E50, 0xF9D423} ps = []*Particle{} pool = []*Particle{} counter = 0 ) type Particle struct { *pixi.Graphics x, y float64 vx, vy float64 radius float64 theta float64 force float64 damping float64 color float64