forked from rocketlaunchr/showerglass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ellipse.go
43 lines (37 loc) · 850 Bytes
/
ellipse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2022 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved.
package showerglass
import (
"image"
"image/color"
)
type ellipse struct {
cx int // center x
cy int // center y
rx int // semi-minor axis x
ry int // semi-major axis y
}
func (e *ellipse) ColorModel() color.Model {
return color.AlphaModel
}
func (e *ellipse) Bounds() image.Rectangle {
min := image.Point{
X: e.cx - e.rx,
Y: e.cy - e.ry,
}
max := image.Point{
X: e.cx + e.rx,
Y: e.cy + e.ry,
}
return image.Rectangle{Min: min, Max: max} // size of just mask
}
func (e *ellipse) At(x, y int) color.Color {
// Equation of ellipse
p1 := float64((x-e.cx)*(x-e.cx)) / float64(e.rx*e.rx)
p2 := float64((y-e.cy)*(y-e.cy)) / float64(e.ry*e.ry)
eqn := p1 + p2
if eqn <= 1 {
// inside
return color.Alpha{255}
}
return color.Alpha{0}
}