Added a pseudorandom noise pattern

This commit is contained in:
Sasha Koshka 2023-01-24 18:15:46 -05:00
parent 5edfbf8110
commit c9c5f1d251
2 changed files with 33 additions and 0 deletions

22
artist/noise.go Normal file
View File

@ -0,0 +1,22 @@
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)
}

View File

@ -215,6 +215,17 @@ func (element *Artist) Resize (width, height int) {
Stroke: artist.Stroke { Pattern: uhex(0x00FF00), Weight: 5 },
},
element.cellAt(0, 7))
// 1, 7
artist.FillRectangle (
element,
artist.Noisy {
Low: uhex(0x000000FF),
High: uhex(0xFFFFFFFF),
Seed: 0,
},
element.cellAt(1, 7),
)
}
func (element *Artist) lines (weight int, bounds image.Rectangle) {