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

34 lines
837 B
Go
Raw Normal View History

2023-01-24 16:15:46 -07:00
package artist
import "image/color"
// Noisy is a pattern that randomly interpolates between two patterns in a
// deterministic fashion.
type Noisy struct {
2023-01-24 16:27:36 -07:00
Low Pattern
High Pattern
Seed uint32
Harsh bool
2023-01-24 16:15:46 -07:00
}
// AtWhen satisfies the pattern interface.
func (pattern Noisy) AtWhen (x, y, width, height int) (c color.RGBA) {
2023-01-24 16:27:36 -07:00
// FIXME: this will occasionally generate "clumps"
2023-01-24 16:15:46 -07:00
special := uint32(x + y * 348905)
special += (pattern.Seed + 1) * 15485863
random := (special * special * special % 2038074743)
fac := float64(random) / 2038074743.0
2023-01-24 16:27:36 -07:00
if pattern.Harsh {
if fac > 0.5 {
return pattern.High.AtWhen(x, y, width, height)
} else {
return pattern.Low.AtWhen(x, y, width, height)
}
} else {
return LerpRGBA (
pattern.Low.AtWhen(x, y, width, height),
pattern.High.AtWhen(x, y, width, height), fac)
}
2023-01-24 16:15:46 -07:00
}