The noise pattern can now be harsh

This commit is contained in:
Sasha Koshka
2023-01-24 18:27:36 -05:00
parent c9c5f1d251
commit 912f939f2e
2 changed files with 62 additions and 24 deletions

View File

@@ -5,18 +5,29 @@ 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
Low Pattern
High Pattern
Seed uint32
Harsh bool
}
// AtWhen satisfies the pattern interface.
func (pattern Noisy) AtWhen (x, y, width, height int) (c color.RGBA) {
// FIXME: this will occasionally generate "clumps"
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)
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)
}
}