Files
aego/asset/builtin_particles.go
T
sanspie 5eb1832907
ci-platforms / darwin amd64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Failing after 15m28s
ci / release (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
ci / checks (push) Successful in 7m47s
Complete Stage 12 for v0.12.0
2026-11-05 11:46:53 +03:00

34 lines
834 B
Go

package asset
import (
"math"
"sync"
"aego/gpu"
"aego/render/texture"
)
var particlePuff = sync.OnceValue(func() *texture.Data { return particleMask(false) })
var particleStreak = sync.OnceValue(func() *texture.Data { return particleMask(true) })
func particleMask(streak bool) *texture.Data {
const n = 24
pixels := make([]byte, n*n*4)
for y := 0; y < n; y++ {
for x := 0; x < n; x++ {
dx, dy := (float64(x)+.5)*2/n-1, (float64(y)+.5)*2/n-1
if streak {
dx *= 5.5
} else {
dx += .07 * math.Cos(8*dy)
}
r := math.Sqrt(dx*dx + dy*dy)
v := min(max(1-r, 0)*1.5, 1.)
b := byte(255*v*v*(3-2*v) + .5)
i := 4 * (n*y + x)
pixels[i], pixels[i+1], pixels[i+2], pixels[i+3] = b, b, b, b
}
}
return &texture.Data{Width: n, Height: n, Format: gpu.TexRGBA8, Pixels: pixels, Premultiplied: true}
}