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.
type Striped struct {
First Pattern
Second Pattern
First Border
Second Border
Direction StripeDirection
Weight int
}
// 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 %= pattern.Weight * 2
phase := pattern.First.Weight + pattern.Second.Weight
position %= phase
if position < 0 {
position += pattern.Weight * 2
position += phase
}
if position < pattern.Weight {
return pattern.First.AtWhen(x, y, width, height)
if position < pattern.First.Weight {
return pattern.First.Stroke.AtWhen(x, y, width, height)
} 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 (
element,
artist.Striped {
First: uhex(0xFF8800FF),
Second: uhex(0x0088FFFF),
First: artist.Border { Stroke: uhex(0xFF8800FF), Weight: 7 },
Second: artist.Border { Stroke: uhex(0x0088FFFF), Weight: 2 },
Direction: artist.StripeDirection(x),
Weight: 3,
},
element.cellAt(x, 1))