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 // Noisy is a pattern that randomly interpolates between two patterns in a
// deterministic fashion. // deterministic fashion.
type Noisy struct { type Noisy struct {
Low Pattern Low Pattern
High Pattern High Pattern
Seed uint32 Seed uint32
Harsh bool
} }
// AtWhen satisfies the pattern interface. // AtWhen satisfies the pattern interface.
func (pattern Noisy) AtWhen (x, y, width, height int) (c color.RGBA) { func (pattern Noisy) AtWhen (x, y, width, height int) (c color.RGBA) {
// FIXME: this will occasionally generate "clumps"
special := uint32(x + y * 348905) special := uint32(x + y * 348905)
special += (pattern.Seed + 1) * 15485863 special += (pattern.Seed + 1) * 15485863
random := (special * special * special % 2038074743) random := (special * special * special % 2038074743)
fac := float64(random) / 2038074743.0 fac := float64(random) / 2038074743.0
return LerpRGBA (
pattern.Low.AtWhen(x, y, width, height), if pattern.Harsh {
pattern.High.AtWhen(x, y, width, height), fac) 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)
}
} }

View File

@ -112,8 +112,8 @@ func (element *Artist) Resize (width, height int) {
artist.FillEllipse ( artist.FillEllipse (
element, element,
artist.Split { artist.Split {
First: artist.NewUniform(hex(0xFF0000FF)), First: uhex(0xFF0000FF),
Second: artist.NewUniform(hex(0x0000FFFF)), Second: uhex(0x0000FFFF),
Orientation: artist.Orientation(x), Orientation: artist.Orientation(x),
}, },
element.cellAt(x, 4)) element.cellAt(x, 4))
@ -133,10 +133,10 @@ func (element *Artist) Resize (width, height int) {
artist.FillRectangle ( artist.FillRectangle (
element, element,
artist.QuadBeveled { artist.QuadBeveled {
artist.NewUniform(hex(0x880000FF)), uhex(0x880000FF),
artist.NewUniform(hex(0x00FF00FF)), uhex(0x00FF00FF),
artist.NewUniform(hex(0x0000FFFF)), uhex(0x0000FFFF),
artist.NewUniform(hex(0xFF00FFFF)), uhex(0xFF00FFFF),
}, },
element.cellAt(0, 5)) element.cellAt(0, 5))
@ -145,10 +145,10 @@ func (element *Artist) Resize (width, height int) {
element, element,
artist.Checkered { artist.Checkered {
First: artist.QuadBeveled { First: artist.QuadBeveled {
artist.NewUniform(hex(0x880000FF)), uhex(0x880000FF),
artist.NewUniform(hex(0x00FF00FF)), uhex(0x00FF00FF),
artist.NewUniform(hex(0x0000FFFF)), uhex(0x0000FFFF),
artist.NewUniform(hex(0xFF00FFFF)), uhex(0xFF00FFFF),
}, },
Second: artist.Striped { Second: artist.Striped {
First: artist.Stroke { Pattern: uhex(0xFF8800FF), Weight: 1 }, First: artist.Stroke { Pattern: uhex(0xFF8800FF), Weight: 1 },
@ -181,10 +181,10 @@ func (element *Artist) Resize (width, height int) {
element, element,
artist.Tiled { artist.Tiled {
Pattern: artist.QuadBeveled { Pattern: artist.QuadBeveled {
artist.NewUniform(hex(0x880000FF)), uhex(0x880000FF),
artist.NewUniform(hex(0x00FF00FF)), uhex(0x00FF00FF),
artist.NewUniform(hex(0x0000FFFF)), uhex(0x0000FFFF),
artist.NewUniform(hex(0xFF00FFFF)), uhex(0xFF00FFFF),
}, },
CellWidth: 17, CellWidth: 17,
CellHeight: 23, CellHeight: 23,
@ -196,8 +196,8 @@ func (element *Artist) Resize (width, height int) {
artist.FillRectangle ( artist.FillRectangle (
element, element,
artist.Gradient { artist.Gradient {
First: artist.NewUniform(hex(0xFF0000FF)), First: uhex(0xFF0000FF),
Second: artist.NewUniform(hex(0x0000FFFF)), Second: uhex(0x0000FFFF),
Orientation: artist.Orientation(x), Orientation: artist.Orientation(x),
}, },
element.cellAt(x, 6)) element.cellAt(x, 6))
@ -208,8 +208,8 @@ func (element *Artist) Resize (width, height int) {
element, element,
artist.EllipticallyBordered { artist.EllipticallyBordered {
Fill: artist.Gradient { Fill: artist.Gradient {
First: artist.NewUniform(hex(0x00FF00FF)), First: uhex(0x00FF00FF),
Second: artist.NewUniform(hex(0x0000FFFF)), Second: uhex(0x0000FFFF),
Orientation: artist.OrientationVertical, Orientation: artist.OrientationVertical,
}, },
Stroke: artist.Stroke { Pattern: uhex(0x00FF00), Weight: 5 }, Stroke: artist.Stroke { Pattern: uhex(0x00FF00), Weight: 5 },
@ -226,6 +226,33 @@ func (element *Artist) Resize (width, height int) {
}, },
element.cellAt(1, 7), 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) { func (element *Artist) lines (weight int, bounds image.Rectangle) {