This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/artist/striped.go

38 lines
805 B
Go
Raw Normal View History

2023-01-20 23:39:08 +00:00
package artist
import "image/color"
// Striped is a pattern that produces stripes of two alternating colors.
type Striped struct {
2023-01-21 04:19:54 +00:00
First Stroke
Second Stroke
Orientation
2023-01-20 23:39:08 +00:00
}
// AtWhen satisfies the Pattern interface.
func (pattern Striped) AtWhen (x, y, width, height int) (c color.RGBA) {
position := 0
2023-01-21 04:19:54 +00:00
switch pattern.Orientation {
case OrientationVertical:
2023-01-20 23:39:08 +00:00
position = x
2023-01-21 04:19:54 +00:00
case OrientationDiagonalRight:
2023-01-20 23:39:08 +00:00
position = x + y
2023-01-21 04:19:54 +00:00
case OrientationHorizontal:
2023-01-20 23:39:08 +00:00
position = y
2023-01-21 04:19:54 +00:00
case OrientationDiagonalLeft:
2023-01-20 23:39:08 +00:00
position = x - y
}
phase := pattern.First.Weight + pattern.Second.Weight
position %= phase
2023-01-20 23:39:08 +00:00
if position < 0 {
position += phase
2023-01-20 23:39:08 +00:00
}
if position < pattern.First.Weight {
2023-01-21 04:19:54 +00:00
return pattern.First.AtWhen(x, y, width, height)
2023-01-20 23:39:08 +00:00
} else {
2023-01-21 04:19:54 +00:00
return pattern.Second.AtWhen(x, y, width, height)
2023-01-20 23:39:08 +00:00
}
}