Added striped patterns
This commit is contained in:
parent
206f068a1f
commit
740999295e
@ -10,14 +10,9 @@ type Chiseled struct {
|
||||
|
||||
// AtWhen satisfies the Pattern interface.
|
||||
func (chiseled Chiseled) AtWhen (x, y, width, height int) (c color.RGBA) {
|
||||
var highlighted bool
|
||||
// FIXME: this doesn't work quite right, the
|
||||
// slope of the line is somewhat off.
|
||||
// bottomCorner :=
|
||||
// float64(x) < float64(y) *
|
||||
// (float64(width) / float64(height))
|
||||
bottomCorner := false
|
||||
|
||||
var highlighted bool
|
||||
var bottomCorner bool
|
||||
|
||||
if width > height {
|
||||
bottomCorner = y > height / 2
|
||||
} else {
|
||||
|
47
artist/striped.go
Normal file
47
artist/striped.go
Normal file
@ -0,0 +1,47 @@
|
||||
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 Pattern
|
||||
Second Pattern
|
||||
Direction StripeDirection
|
||||
Weight int
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
position %= pattern.Weight * 2
|
||||
if position < 0 {
|
||||
position += pattern.Weight * 2
|
||||
}
|
||||
|
||||
if position < pattern.Weight {
|
||||
return pattern.First.AtWhen(x, y, width, height)
|
||||
} else {
|
||||
return pattern.Second.AtWhen(x, y, width, height)
|
||||
}
|
||||
}
|
@ -53,6 +53,20 @@ func (element *Artist) Resize (width, height int) {
|
||||
artist.Border { Stroke: uhex(0x0000FFFF), Weight: 5 },
|
||||
),
|
||||
element.cellAt(2, 0))
|
||||
|
||||
// 0, 1 - 0, 3
|
||||
for x := 0; x < 4; x ++ {
|
||||
artist.FillRectangle (
|
||||
element,
|
||||
artist.Striped {
|
||||
First: uhex(0xFF8800FF),
|
||||
Second: uhex(0x0088FFFF),
|
||||
Direction: artist.StripeDirection(x),
|
||||
Weight: 3,
|
||||
|
||||
},
|
||||
element.cellAt(x, 1))
|
||||
}
|
||||
}
|
||||
|
||||
func (element *Artist) cellAt (x, y int) (image.Rectangle) {
|
||||
|
Reference in New Issue
Block a user