mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
example/shape: Bug fix: The positions must be rounded (#97)
This commit is contained in:
parent
73bb576b0e
commit
d12477fb2a
@ -19,7 +19,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/exp/shape"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
//"math"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -36,8 +36,8 @@ func update(screen *ebiten.Image) error {
|
||||
screen.DrawLine(130, 0, 140, 100, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
||||
screen.DrawLine(140, 0, 150, 100, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
||||
|
||||
shape.DrawEllipse(screen, 0, 0, 100, 50, color.NRGBA{0x80, 0xff, 0x80, 0x80})
|
||||
shape.DrawArc(screen, 0, 0, 100, 50, 0, math.Pi/2, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
||||
shape.DrawEllipse(screen, 0, 0, 200, 200, color.NRGBA{0x80, 0xff, 0x80, 0x80})
|
||||
//shape.DrawArc(screen, 0, 0, 50, 50, 0, math.Pi/2, color.NRGBA{0xff, 0x80, 0x80, 0x80})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,10 @@ func (e *ellipsesLines) Len() int {
|
||||
return e.Rects.Len() * e.lineNum()
|
||||
}
|
||||
|
||||
func round(x float64) int {
|
||||
return int(x + 0.5)
|
||||
}
|
||||
|
||||
func (e *ellipsesLines) Points(i int) (x0, y0, x1, y1 int) {
|
||||
n := e.lineNum()
|
||||
x, y, w, h := e.Rects.Rect(i / n)
|
||||
@ -59,11 +63,13 @@ func (e *ellipsesLines) Points(i int) (x0, y0, x1, y1 int) {
|
||||
fy0, fx0 := math.Sincos(theta0)
|
||||
fy1, fx1 := math.Sincos(theta1)
|
||||
hw, hh := (float64(w)-1)/2, (float64(h)-1)/2
|
||||
fx0 = fx0*hw + float64(x) + hw
|
||||
fx1 = fx1*hw + float64(x) + hw
|
||||
fy0 = fy0*hh + float64(y) + hh
|
||||
fy1 = fy1*hh + float64(y) + hh
|
||||
return int(fx0), int(fy0), int(fx1), int(fy1)
|
||||
fx0 = fx0*hw + hw + float64(x)
|
||||
fx1 = fx1*hw + hw + float64(x)
|
||||
fy0 = fy0*hh + hh + float64(y)
|
||||
fy1 = fy1*hh + hh + float64(y)
|
||||
// TODO: The last fy1 may differ from first fy0 with very slightly difference,
|
||||
// which makes the lack of 1 pixel.
|
||||
return round(fx0), round(fy0), round(fx1), round(fy1)
|
||||
}
|
||||
|
||||
func (e *ellipsesLines) Color(i int) color.Color {
|
||||
|
Loading…
Reference in New Issue
Block a user