refactor
This commit is contained in:
@@ -9,6 +9,7 @@ const side = 16
|
||||
|
||||
type grid struct {
|
||||
color.Gray
|
||||
Factor float64
|
||||
}
|
||||
|
||||
func (_ grid) ColorModel() color.Model {
|
||||
@@ -20,7 +21,7 @@ func (_ grid) Bounds() image.Rectangle {
|
||||
}
|
||||
|
||||
func (g grid) At(x, y int) color.Color {
|
||||
n := uint8(g.Gray.Y * 10)
|
||||
n := uint8(float64(g.Gray.Y) * g.Factor)
|
||||
|
||||
if n == 0 {
|
||||
return color.Black
|
||||
@@ -52,12 +53,13 @@ func (g uniformGrid) At(x, y int) color.Color {
|
||||
|
||||
type Dithering struct {
|
||||
image.Image
|
||||
Factor float64
|
||||
}
|
||||
|
||||
func (d Dithering) ColorModel() color.Model { return color.GrayModel }
|
||||
func (d Dithering) Bounds() image.Rectangle { return d.Image.Bounds() }
|
||||
func (d Dithering) At(x, y int) color.Color {
|
||||
c := color.GrayModel.Convert(d.Image.At(x, y))
|
||||
return uniformGrid{grid{c.(color.Gray)}}.
|
||||
return uniformGrid{grid{c.(color.Gray), d.Factor}}.
|
||||
At(x, y)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user