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"
|
||||
|
||||
// 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
|
||||
Direction StripeDirection
|
||||
First Stroke
|
||||
Second Stroke
|
||||
Orientation
|
||||
}
|
||||
|
||||
// AtWhen satisfies the Pattern interface.
|
||||
func (pattern Striped) AtWhen (x, y, width, height int) (c color.RGBA) {
|
||||
position := 0
|
||||
switch pattern.Direction {
|
||||
case StripeDirectionVertical:
|
||||
switch pattern.Orientation {
|
||||
case OrientationVertical:
|
||||
position = x
|
||||
case StripeDirectionDiagonalRight:
|
||||
case OrientationDiagonalRight:
|
||||
position = x + y
|
||||
case StripeDirectionHorizontal:
|
||||
case OrientationHorizontal:
|
||||
position = y
|
||||
case StripeDirectionDiagonalLeft:
|
||||
case OrientationDiagonalLeft:
|
||||
position = x - y
|
||||
}
|
||||
|
||||
@ -40,8 +30,8 @@ func (pattern Striped) AtWhen (x, y, width, height int) (c color.RGBA) {
|
||||
}
|
||||
|
||||
if position < pattern.First.Weight {
|
||||
return pattern.First.Pattern.AtWhen(x, y, width, height)
|
||||
return pattern.First.AtWhen(x, y, width, height)
|
||||
} else {
|
||||
return pattern.Second.Pattern.AtWhen(x, y, width, height)
|
||||
return pattern.Second.AtWhen(x, y, width, height)
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func (element *Artist) Resize (width, height int) {
|
||||
artist.Striped {
|
||||
First: artist.Stroke { Pattern: uhex(0xFF8800FF), Weight: 7 },
|
||||
Second: artist.Stroke { Pattern: uhex(0x0088FFFF), Weight: 2 },
|
||||
Direction: artist.StripeDirection(x),
|
||||
Orientation: artist.Orientation(x),
|
||||
|
||||
},
|
||||
element.cellAt(x, 1))
|
||||
@ -107,14 +107,17 @@ func (element *Artist) Resize (width, height int) {
|
||||
x, element.cellAt(x, 3))
|
||||
}
|
||||
|
||||
// 0, 4
|
||||
artist.FillEllipse (
|
||||
element,
|
||||
artist.Beveled {
|
||||
Highlight: artist.NewUniform(hex(0xFF0000FF)),
|
||||
Shadow: artist.NewUniform(hex(0x0000FFFF)),
|
||||
},
|
||||
element.cellAt(0, 4))
|
||||
// 0, 4 - 3, 4
|
||||
for x := 0; x < 4; x ++ {
|
||||
artist.FillEllipse (
|
||||
element,
|
||||
artist.Split {
|
||||
First: artist.NewUniform(hex(0xFF0000FF)),
|
||||
Second: artist.NewUniform(hex(0x0000FFFF)),
|
||||
Orientation: artist.Orientation(x),
|
||||
},
|
||||
element.cellAt(x, 4))
|
||||
}
|
||||
|
||||
// how long did that take to render?
|
||||
drawTime := time.Since(drawStart)
|
||||
|
Reference in New Issue
Block a user