From 912f939f2e6e4d9ffbebfe9b08414b5dabd3b248 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 24 Jan 2023 18:27:36 -0500 Subject: [PATCH] The noise pattern can now be harsh --- artist/noise.go | 23 ++++++++++---- elements/testing/artist.go | 63 +++++++++++++++++++++++++++----------- 2 files changed, 62 insertions(+), 24 deletions(-) diff --git a/artist/noise.go b/artist/noise.go index cfd6d3d..aa31126 100644 --- a/artist/noise.go +++ b/artist/noise.go @@ -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) + } } diff --git a/elements/testing/artist.go b/elements/testing/artist.go index decc2aa..1a919b2 100644 --- a/elements/testing/artist.go +++ b/elements/testing/artist.go @@ -112,8 +112,8 @@ func (element *Artist) Resize (width, height int) { artist.FillEllipse ( element, artist.Split { - First: artist.NewUniform(hex(0xFF0000FF)), - Second: artist.NewUniform(hex(0x0000FFFF)), + First: uhex(0xFF0000FF), + Second: uhex(0x0000FFFF), Orientation: artist.Orientation(x), }, element.cellAt(x, 4)) @@ -133,10 +133,10 @@ func (element *Artist) Resize (width, height int) { artist.FillRectangle ( element, artist.QuadBeveled { - artist.NewUniform(hex(0x880000FF)), - artist.NewUniform(hex(0x00FF00FF)), - artist.NewUniform(hex(0x0000FFFF)), - artist.NewUniform(hex(0xFF00FFFF)), + uhex(0x880000FF), + uhex(0x00FF00FF), + uhex(0x0000FFFF), + uhex(0xFF00FFFF), }, element.cellAt(0, 5)) @@ -145,10 +145,10 @@ func (element *Artist) Resize (width, height int) { element, artist.Checkered { First: artist.QuadBeveled { - artist.NewUniform(hex(0x880000FF)), - artist.NewUniform(hex(0x00FF00FF)), - artist.NewUniform(hex(0x0000FFFF)), - artist.NewUniform(hex(0xFF00FFFF)), + uhex(0x880000FF), + uhex(0x00FF00FF), + uhex(0x0000FFFF), + uhex(0xFF00FFFF), }, Second: artist.Striped { First: artist.Stroke { Pattern: uhex(0xFF8800FF), Weight: 1 }, @@ -181,10 +181,10 @@ func (element *Artist) Resize (width, height int) { element, artist.Tiled { Pattern: artist.QuadBeveled { - artist.NewUniform(hex(0x880000FF)), - artist.NewUniform(hex(0x00FF00FF)), - artist.NewUniform(hex(0x0000FFFF)), - artist.NewUniform(hex(0xFF00FFFF)), + uhex(0x880000FF), + uhex(0x00FF00FF), + uhex(0x0000FFFF), + uhex(0xFF00FFFF), }, CellWidth: 17, CellHeight: 23, @@ -196,8 +196,8 @@ func (element *Artist) Resize (width, height int) { artist.FillRectangle ( element, artist.Gradient { - First: artist.NewUniform(hex(0xFF0000FF)), - Second: artist.NewUniform(hex(0x0000FFFF)), + First: uhex(0xFF0000FF), + Second: uhex(0x0000FFFF), Orientation: artist.Orientation(x), }, element.cellAt(x, 6)) @@ -208,8 +208,8 @@ func (element *Artist) Resize (width, height int) { element, artist.EllipticallyBordered { Fill: artist.Gradient { - First: artist.NewUniform(hex(0x00FF00FF)), - Second: artist.NewUniform(hex(0x0000FFFF)), + First: uhex(0x00FF00FF), + Second: uhex(0x0000FFFF), Orientation: artist.OrientationVertical, }, Stroke: artist.Stroke { Pattern: uhex(0x00FF00), Weight: 5 }, @@ -226,6 +226,33 @@ func (element *Artist) Resize (width, height int) { }, element.cellAt(1, 7), ) + + // 2, 7 + artist.FillRectangle ( + element, + artist.Noisy { + Low: uhex(0x000000FF), + High: artist.Gradient { + First: uhex(0x000000FF), + Second: uhex(0xFFFFFFFF), + Orientation: artist.OrientationVertical, + }, + Seed: 0, + }, + element.cellAt(2, 7), + ) + + // 3, 7 + artist.FillRectangle ( + element, + artist.Noisy { + Low: uhex(0x000000FF), + High: uhex(0xFFFFFFFF), + Seed: 0, + Harsh: true, + }, + element.cellAt(3, 7), + ) } func (element *Artist) lines (weight int, bounds image.Rectangle) {