diff --git a/algs4/src/go/algs4/canvas.go b/algs4/src/go/algs4/canvas.go index f79d93f..48cfd33 100644 --- a/algs4/src/go/algs4/canvas.go +++ b/algs4/src/go/algs4/canvas.go @@ -86,7 +86,8 @@ func (me *Canvas) Rectangle(x, y, halfWidth, halfHeight float64) error { hs := me.factorY(f2 * halfHeight) if ws <= 1 && hs <= 1 { - return me.Pixel(x, y) + me.Pixel(x, y) + return nil } draw.Draw(me.img, image.Rect(int(xs-ws/f2), int(ys-hs/f2), int(ws), int(hs)), @@ -95,8 +96,11 @@ func (me *Canvas) Rectangle(x, y, halfWidth, halfHeight float64) error { return nil } -func (me *Canvas) Pixel(x, y float64) error { - return nil +func (me *Canvas) Pixel(x, y float64) { + originX, originY := int(me.scaleX(x)), int(me.scaleY(y)) + draw.Draw(me.img, image.Rect(originX, originY, originX+1, originY+1), + &image.Uniform{image.White}, image.ZP, draw.Src) + me.window.FlushImage() } func (me *Canvas) Draw() error { diff --git a/algs4/src/go/algs4/point2d.go b/algs4/src/go/algs4/point2d.go index fb1d217..81d1c43 100644 --- a/algs4/src/go/algs4/point2d.go +++ b/algs4/src/go/algs4/point2d.go @@ -1,9 +1,10 @@ package algs4 type Point2D struct { - X float64 - Y float64 - Canvas *Canvas + X float64 + Y float64 + + canvas *Canvas } func NewPoint2D(x, y float64, canvas *Canvas) *Point2D { @@ -12,12 +13,13 @@ func NewPoint2D(x, y float64, canvas *Canvas) *Point2D { } return &Point2D{ - X: x, - Y: y, - Canvas: canvas, + X: x, + Y: y, + + canvas: canvas, } } func (me *Point2D) Draw() { - return + me.canvas.Pixel(me.X, me.Y) }