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)
}
}

View File

@ -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) {