This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/artist/noise.go
2023-01-24 18:15:46 -05:00

23 lines
600 B
Go

package artist
import "image/color"
// Noisy is a pattern that randomly interpolates between two patterns in a
// deterministic fashion.
type Noisy struct {
Low Pattern
High Pattern
Seed uint32
}
// AtWhen satisfies the pattern interface.
func (pattern Noisy) AtWhen (x, y, width, height int) (c color.RGBA) {
special := uint32(x + y * 348905)
special += (pattern.Seed + 1) * 15485863
random := (special * special * special % 2038074743)
fac := float64(random) / 2038074743.0
return LerpRGBA (
pattern.Low.AtWhen(x, y, width, height),
pattern.High.AtWhen(x, y, width, height), fac)
}