Ellipses now draw properly

This commit is contained in:
Sasha Koshka 2023-01-20 22:13:14 -05:00
parent 39ce5f9ee2
commit a273178a8e
2 changed files with 18 additions and 8 deletions

View File

@ -23,8 +23,8 @@ func FillEllipse (
width, height := bounds.Dx(), bounds.Dy()
for y := 0; y < height; y ++ {
for x := 0; x < width; x ++ {
xf := float64(x) / float64(realWidth) - 0.5
yf := float64(y) / float64(realHeight) - 0.5
xf := (float64(x) + 0.5) / float64(realWidth) - 0.5
yf := (float64(y) + 0.5) / float64(realHeight) - 0.5
if math.Sqrt(xf * xf + yf * yf) <= 0.5 {
data[x + bounds.Min.X + (y + bounds.Min.Y) * stride] =
source.AtWhen(x, y, realWidth, realHeight)
@ -44,11 +44,7 @@ func StrokeEllipse (
if weight < 1 { return }
data, stride := destination.Buffer()
bounds = bounds.Canon().Inset(weight)
radii := image.Pt (
bounds.Dx() / 2,
bounds.Dy() / 2)
center := bounds.Min.Add(radii)
bounds = bounds.Canon().Inset(weight - 1)
width, height := bounds.Dx(), bounds.Dy()
context := ellipsePlottingContext {
@ -60,6 +56,14 @@ func StrokeEllipse (
weight: weight,
bounds: bounds,
}
bounds.Max.X -= 1
bounds.Max.Y -= 1
radii := image.Pt (
bounds.Dx() / 2,
bounds.Dy() / 2)
center := bounds.Min.Add(radii)
x := float64(0)
y := float64(radii.Y)

View File

@ -87,10 +87,16 @@ func (element *Artist) Resize (width, height int) {
}
// 0, 3
artist.StrokeRectangle (
element,uhex(0x888888FF), 1,
element.cellAt(0, 3))
artist.FillEllipse(element, uhex(0x00FF00FF), element.cellAt(0, 3))
// 1, 3
// 1, 3 - 3, 3
for x := 1; x < 4; x ++ {
artist.StrokeRectangle (
element,uhex(0x888888FF), 1,
element.cellAt(x, 3))
artist.StrokeEllipse (
element,
[]artist.Pattern {