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/chisel.go

64 lines
1.4 KiB
Go
Raw Normal View History

2023-01-09 06:03:19 +00:00
package artist
import "image/color"
2023-01-21 04:00:26 +00:00
// Beveled is a pattern that has a highlight section and a shadow section.
type Beveled struct {
Highlight Pattern
Shadow Pattern
2023-01-09 06:03:19 +00:00
}
// AtWhen satisfies the Pattern interface.
2023-01-21 04:00:26 +00:00
func (pattern Beveled) AtWhen (x, y, width, height int) (c color.RGBA) {
2023-01-20 23:39:08 +00:00
var highlighted bool
var bottomCorner bool
2023-01-20 23:08:20 +00:00
if width > height {
bottomCorner = y > height / 2
} else {
bottomCorner = x < width / 2
}
if bottomCorner {
highlighted = float64(x) < float64(height) - float64(y)
} else {
highlighted = float64(width) - float64(x) > float64(y)
}
if highlighted {
2023-01-21 04:00:26 +00:00
return pattern.Highlight.AtWhen(x, y, width, height)
} else {
2023-01-21 04:00:26 +00:00
return pattern.Shadow.AtWhen(x, y, width, height)
2023-01-09 06:03:19 +00:00
}
}
2023-01-24 04:40:55 +00:00
// QuadBeveled is like Beveled, but with four sides. A pattern can be specified
// for each one.
type QuadBeveled [4]Pattern
// AtWhen satisfies the Pattern interface.
func (pattern QuadBeveled) AtWhen (x, y, width, height int) (c color.RGBA) {
bottom := y > height / 2
right := x > width / 2
top := !bottom
left := !right
side := 0
switch {
case top && left:
if x > y { side = 0 } else { side = 3 }
case top && right:
if width - x < y { side = 1 } else { side = 0 }
case bottom && left:
if x > height - y { side = 2 } else { side = 3 }
case bottom && right:
if width - x < height - y { side = 1 } else { side = 2 }
}
return pattern[side].AtWhen(x, y, width, height)
}