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

48 lines
1.1 KiB
Go
Raw Normal View History

2023-01-20 16:39:08 -07:00
package artist
import "image/color"
// StripeDirection specifies the direction of stripes.
type StripeDirection int
const (
StripeDirectionVertical StripeDirection = iota
StripeDirectionDiagonalRight
StripeDirectionHorizontal
StripeDirectionDiagonalLeft
)
// Striped is a pattern that produces stripes of two alternating colors.
type Striped struct {
First Stroke
Second Stroke
2023-01-20 16:39:08 -07:00
Direction StripeDirection
}
// AtWhen satisfies the Pattern interface.
func (pattern Striped) AtWhen (x, y, width, height int) (c color.RGBA) {
position := 0
switch pattern.Direction {
case StripeDirectionVertical:
position = x
case StripeDirectionDiagonalRight:
position = x + y
case StripeDirectionHorizontal:
position = y
case StripeDirectionDiagonalLeft:
position = x - y
}
phase := pattern.First.Weight + pattern.Second.Weight
position %= phase
2023-01-20 16:39:08 -07:00
if position < 0 {
position += phase
2023-01-20 16:39:08 -07:00
}
if position < pattern.First.Weight {
return pattern.First.Pattern.AtWhen(x, y, width, height)
2023-01-20 16:39:08 -07:00
} else {
return pattern.Second.Pattern.AtWhen(x, y, width, height)
2023-01-20 16:39:08 -07:00
}
}