It is now possible to draw a filled ellipse
This commit is contained in:
parent
6967c40143
commit
775e7bd4ca
34
artist/ellipse.go
Normal file
34
artist/ellipse.go
Normal 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
|
@ -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 ++ {
|
||||
|
@ -88,7 +88,3 @@ func StrokeRectangle (
|
||||
insetBounds.Max.X, insetBounds.Min.Y,
|
||||
bounds.Max.X, insetBounds.Max.Y))
|
||||
}
|
||||
|
||||
// TODO: FillEllipse
|
||||
|
||||
// TODO: StrokeEllipse
|
||||
|
@ -28,7 +28,7 @@ func (element *Artist) Resize (width, height int) {
|
||||
element.core.AllocateCanvas(width, height)
|
||||
bounds := element.Bounds()
|
||||
element.cellBounds.Max.X = bounds.Dx() / 4
|
||||
element.cellBounds.Max.Y = (bounds.Dy() - 64) / 4
|
||||
element.cellBounds.Max.Y = (bounds.Dy() - 48) / 4
|
||||
|
||||
drawStart := time.Now()
|
||||
|
||||
@ -86,6 +86,9 @@ func (element *Artist) Resize (width, height int) {
|
||||
element.lines(x + 1, element.cellAt(x, 2))
|
||||
}
|
||||
|
||||
// 0, 3
|
||||
artist.FillEllipse(element, uhex(0x00FF00FF), element.cellAt(0, 3))
|
||||
|
||||
drawTime := time.Since(drawStart)
|
||||
textDrawer := artist.TextDrawer { }
|
||||
textDrawer.SetFace(defaultfont.FaceRegular)
|
||||
|
Reference in New Issue
Block a user