diff --git a/artist/noise.go b/artist/noise.go new file mode 100644 index 0000000..cfd6d3d --- /dev/null +++ b/artist/noise.go @@ -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) +} diff --git a/elements/testing/artist.go b/elements/testing/artist.go index f319ab7..decc2aa 100644 --- a/elements/testing/artist.go +++ b/elements/testing/artist.go @@ -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) {