It is now possible to draw a filled ellipse

This commit is contained in:
2023-01-20 20:52:06 -05:00
parent 6967c40143
commit 775e7bd4ca
4 changed files with 40 additions and 7 deletions

34
artist/ellipse.go Normal file
View File

@@ -0,0 +1,34 @@
package artist
import "math"
import "image"
import "git.tebibyte.media/sashakoshka/tomo"
// FillEllipse draws a filled ellipse with the specified pattern.
func FillEllipse (
destination tomo.Canvas,
source Pattern,
bounds image.Rectangle,
) (
updatedRegion image.Rectangle,
) {
data, stride := destination.Buffer()
realWidth, realHeight := bounds.Dx(), bounds.Dy()
bounds = bounds.Canon().Intersect(destination.Bounds()).Canon()
if bounds.Empty() { return }
updatedRegion = bounds
width, height := bounds.Dx(), bounds.Dy()
for y := 0; y < height; y ++ {
for x := 0; x < width; x ++ {
xf := float64(x) / float64(width) - 0.5
yf := float64(y) / float64(height) - 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)
}
}}
return
}
// TODO: StrokeEllipse

View File

@@ -129,8 +129,8 @@ func squareAround (
source Pattern,
x, y, patternWidth, patternHeight, diameter int,
) {
minY := y - diameter
minX := x - diameter
minY := y - diameter + 1
minX := x - diameter + 1
maxY := y + diameter
maxX := x + diameter
for y = minY; y < maxY; y ++ {

View File

@@ -88,7 +88,3 @@ func StrokeRectangle (
insetBounds.Max.X, insetBounds.Min.Y,
bounds.Max.X, insetBounds.Max.Y))
}
// TODO: FillEllipse
// TODO: StrokeEllipse