Created the split pattern
This commit is contained in:
parent
4c1bf070fe
commit
83d5064803
43
artist/split.go
Normal file
43
artist/split.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package artist
|
||||||
|
|
||||||
|
import "image/color"
|
||||||
|
|
||||||
|
// Orientation specifies an eight-way pattern orientation.
|
||||||
|
type Orientation int
|
||||||
|
|
||||||
|
const (
|
||||||
|
OrientationVertical Orientation = iota
|
||||||
|
OrientationDiagonalRight
|
||||||
|
OrientationHorizontal
|
||||||
|
OrientationDiagonalLeft
|
||||||
|
)
|
||||||
|
|
||||||
|
// Split is a pattern that is divided in half between two sub-patterns.
|
||||||
|
type Split struct {
|
||||||
|
First Pattern
|
||||||
|
Second Pattern
|
||||||
|
Orientation
|
||||||
|
}
|
||||||
|
|
||||||
|
// AtWhen satisfies the Pattern interface.
|
||||||
|
func (pattern Split) AtWhen (x, y, width, height int) (c color.RGBA) {
|
||||||
|
var first bool
|
||||||
|
switch pattern.Orientation {
|
||||||
|
case OrientationVertical:
|
||||||
|
first = x < width / 2
|
||||||
|
case OrientationDiagonalRight:
|
||||||
|
first = float64(x) / float64(width) +
|
||||||
|
float64(y) / float64(height) < 1
|
||||||
|
case OrientationHorizontal:
|
||||||
|
first = y < height / 2
|
||||||
|
case OrientationDiagonalLeft:
|
||||||
|
first = float64(width - x) / float64(width) +
|
||||||
|
float64(y) / float64(height) < 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if first {
|
||||||
|
return pattern.First.AtWhen(x, y, width, height)
|
||||||
|
} else {
|
||||||
|
return pattern.Second.AtWhen(x, y, width, height)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,34 +2,24 @@ package artist
|
|||||||
|
|
||||||
import "image/color"
|
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.
|
// Striped is a pattern that produces stripes of two alternating colors.
|
||||||
type Striped struct {
|
type Striped struct {
|
||||||
First Stroke
|
First Stroke
|
||||||
Second Stroke
|
Second Stroke
|
||||||
Direction StripeDirection
|
Orientation
|
||||||
}
|
}
|
||||||
|
|
||||||
// AtWhen satisfies the Pattern interface.
|
// AtWhen satisfies the Pattern interface.
|
||||||
func (pattern Striped) AtWhen (x, y, width, height int) (c color.RGBA) {
|
func (pattern Striped) AtWhen (x, y, width, height int) (c color.RGBA) {
|
||||||
position := 0
|
position := 0
|
||||||
switch pattern.Direction {
|
switch pattern.Orientation {
|
||||||
case StripeDirectionVertical:
|
case OrientationVertical:
|
||||||
position = x
|
position = x
|
||||||
case StripeDirectionDiagonalRight:
|
case OrientationDiagonalRight:
|
||||||
position = x + y
|
position = x + y
|
||||||
case StripeDirectionHorizontal:
|
case OrientationHorizontal:
|
||||||
position = y
|
position = y
|
||||||
case StripeDirectionDiagonalLeft:
|
case OrientationDiagonalLeft:
|
||||||
position = x - y
|
position = x - y
|
||||||
}
|
}
|
||||||
|
|
||||||