Created an elliptical border pattern

This commit is contained in:
Sasha Koshka 2023-01-24 15:35:00 -05:00
parent 0281b1a203
commit d5cb1b27fe
2 changed files with 44 additions and 2 deletions

33
artist/circlebordered.go Normal file
View File

@ -0,0 +1,33 @@
package artist
import "math"
import "image/color"
// EllipticallyBordered is a pattern with a border and a fill that is elliptical
// in shape.
type EllipticallyBordered struct {
Fill Pattern
Stroke
}
// AtWhen satisfies the Pattern interface.
func (pattern EllipticallyBordered) AtWhen (x, y, width, height int) (c color.RGBA) {
xf := (float64(x) + 0.5) / float64(width ) * 2 - 1
yf := (float64(y) + 0.5) / float64(height) * 2 - 1
distance := math.Sqrt(xf * xf + yf * yf)
var radius float64
if width < height {
// vertical
radius = 1 - float64(pattern.Weight * 2) / float64(width)
} else {
// horizontal
radius = 1 - float64(pattern.Weight * 2) / float64(height)
}
if distance < radius {
return pattern.Fill.AtWhen(x, y, width, height)
} else {
return pattern.Stroke.AtWhen(x, y, width, height)
}
}

View File

@ -20,7 +20,7 @@ type Artist struct {
func NewArtist () (element *Artist) { func NewArtist () (element *Artist) {
element = &Artist { } element = &Artist { }
element.Core, element.core = core.NewCore(element) element.Core, element.core = core.NewCore(element)
element.core.SetMinimumSize(400, 512) element.core.SetMinimumSize(400, 600)
return return
} }
@ -28,7 +28,7 @@ func (element *Artist) Resize (width, height int) {
element.core.AllocateCanvas(width, height) element.core.AllocateCanvas(width, height)
bounds := element.Bounds() bounds := element.Bounds()
element.cellBounds.Max.X = bounds.Dx() / 4 element.cellBounds.Max.X = bounds.Dx() / 4
element.cellBounds.Max.Y = (bounds.Dy() - 48) / 7 element.cellBounds.Max.Y = (bounds.Dy() - 48) / 8
drawStart := time.Now() drawStart := time.Now()
@ -202,6 +202,15 @@ func (element *Artist) Resize (width, height int) {
}, },
element.cellAt(x, 6)) element.cellAt(x, 6))
} }
// 0, 7
artist.FillEllipse (
element,
artist.EllipticallyBordered {
Fill: uhex(0xFF0000FF),
Stroke: artist.Stroke { Pattern: uhex(0x00FF00), Weight: 5 },
},
element.cellAt(0, 7))
} }
func (element *Artist) lines (weight int, bounds image.Rectangle) { func (element *Artist) lines (weight int, bounds image.Rectangle) {