Striped patterns can have alternating weights

This commit is contained in:
Sasha Koshka 2023-01-20 18:57:02 -05:00
parent 740999295e
commit 8c0956b998
2 changed files with 10 additions and 11 deletions

View File

@ -14,10 +14,9 @@ const (
// Striped is a pattern that produces stripes of two alternating colors. // Striped is a pattern that produces stripes of two alternating colors.
type Striped struct { type Striped struct {
First Pattern First Border
Second Pattern Second Border
Direction StripeDirection Direction StripeDirection
Weight int
} }
// AtWhen satisfies the Pattern interface. // AtWhen satisfies the Pattern interface.
@ -34,14 +33,15 @@ func (pattern Striped) AtWhen (x, y, width, height int) (c color.RGBA) {
position = x - y position = x - y
} }
position %= pattern.Weight * 2 phase := pattern.First.Weight + pattern.Second.Weight
position %= phase
if position < 0 { if position < 0 {
position += pattern.Weight * 2 position += phase
} }
if position < pattern.Weight { if position < pattern.First.Weight {
return pattern.First.AtWhen(x, y, width, height) return pattern.First.Stroke.AtWhen(x, y, width, height)
} else { } else {
return pattern.Second.AtWhen(x, y, width, height) return pattern.Second.Stroke.AtWhen(x, y, width, height)
} }
} }

View File

@ -59,10 +59,9 @@ func (element *Artist) Resize (width, height int) {
artist.FillRectangle ( artist.FillRectangle (
element, element,
artist.Striped { artist.Striped {
First: uhex(0xFF8800FF), First: artist.Border { Stroke: uhex(0xFF8800FF), Weight: 7 },
Second: uhex(0x0088FFFF), Second: artist.Border { Stroke: uhex(0x0088FFFF), Weight: 2 },
Direction: artist.StripeDirection(x), Direction: artist.StripeDirection(x),
Weight: 3,
}, },
element.cellAt(x, 1)) element.cellAt(x, 1))