diff --git a/examples/lights/main.go b/examples/lights/main.go index dd41386..b3d4f9d 100644 --- a/examples/lights/main.go +++ b/examples/lights/main.go @@ -43,9 +43,9 @@ func (cl *colorlight) apply(dst pixel.ComposeTarget, center pixel.Vec, src, nois // create the light arc if not created already if cl.imd == nil { imd := imdraw.New(nil) - imd.Color(pixel.Alpha(1)) + imd.Color = pixel.Alpha(1) imd.Push(0) - imd.Color(pixel.Alpha(0)) + imd.Color = pixel.Alpha(0) for angle := -cl.spread / 2; angle <= cl.spread/2; angle += cl.spread / 64 { imd.Push(pixel.X(1).Rotated(angle)) } diff --git a/examples/platformer/main.go b/examples/platformer/main.go index dab3628..09253b3 100644 --- a/examples/platformer/main.go +++ b/examples/platformer/main.go @@ -86,7 +86,7 @@ type platform struct { } func (p *platform) draw(imd *imdraw.IMDraw) { - imd.Color(p.color) + imd.Color = p.color imd.Push(p.rect.Min, p.rect.Max) imd.Rectangle(0) } @@ -247,7 +247,7 @@ func (g *goal) update(dt float64) { func (g *goal) draw(imd *imdraw.IMDraw) { for i := len(g.cols) - 1; i >= 0; i-- { - imd.Color(g.cols[i]) + imd.Color = g.cols[i] imd.Push(g.pos) imd.Circle(float64(i+1)*g.radius/float64(len(g.cols)), 0) } @@ -324,7 +324,7 @@ func run() { canvas := pixelgl.NewCanvas(pixel.R(-160/2, -120/2, 160/2, 120/2)) imd := imdraw.New(sheet) - imd.Precision(32) + imd.Precision = 32 camPos := pixel.V(0, 0) diff --git a/examples/xor/main.go b/examples/xor/main.go index a062de4..94c2c09 100644 --- a/examples/xor/main.go +++ b/examples/xor/main.go @@ -39,28 +39,28 @@ func run() { // red circle imd.Clear() - imd.Color(pixel.RGB(1, 0, 0)) + imd.Color = pixel.RGB(1, 0, 0) imd.Push(win.Bounds().Center() - pixel.X(offset)) imd.Circle(200, 0) imd.Draw(canvas) // blue circle imd.Clear() - imd.Color(pixel.RGB(0, 0, 1)) + imd.Color = pixel.RGB(0, 0, 1) imd.Push(win.Bounds().Center() + pixel.X(offset)) imd.Circle(150, 0) imd.Draw(canvas) // yellow circle imd.Clear() - imd.Color(pixel.RGB(1, 1, 0)) + imd.Color = pixel.RGB(1, 1, 0) imd.Push(win.Bounds().Center() - pixel.Y(offset)) imd.Circle(100, 0) imd.Draw(canvas) // magenta circle imd.Clear() - imd.Color(pixel.RGB(1, 0, 1)) + imd.Color=pixel.RGB(1, 0, 1) imd.Push(win.Bounds().Center() + pixel.Y(offset)) imd.Circle(50, 0) imd.Draw(canvas) diff --git a/imdraw/imdraw.go b/imdraw/imdraw.go index d77e4cd..3664459 100644 --- a/imdraw/imdraw.go +++ b/imdraw/imdraw.go @@ -23,9 +23,9 @@ import ( // // imd.Line(20) // draws a 20 units thick line // -// Use various methods to change properties of Pushed points: +// Set exported fields to change properties of Pushed points: // -// imd.Color(pixel.RGB(1, 0, 0)) +// imd.Color = pixel.RGB(1, 0, 0) // imd.Push(pixel.V(200, 200)) // imd.Circle(400, 0) // @@ -45,8 +45,13 @@ import ( // - Ellipse // - Ellipse arc type IMDraw struct { + Color color.Color + Picture pixel.Vec + Intensity float64 + Precision int + EndShape EndShape + points []point - opts point matrix pixel.Matrix mask pixel.RGBA @@ -105,9 +110,11 @@ func (imd *IMDraw) Clear() { // This does not affect matrix and color mask set by SetMatrix and SetColorMask. func (imd *IMDraw) Reset() { imd.points = nil - imd.opts = point{} - imd.Color(pixel.Alpha(1)) - imd.Precision(64) + imd.Color = pixel.Alpha(1) + imd.Picture = 0 + imd.Intensity = 0 + imd.Precision = 64 + imd.EndShape = NoEndShape } // Draw draws all currently drawn shapes inside the IM onto another Target. @@ -120,8 +127,16 @@ func (imd *IMDraw) Draw(t pixel.Target) { // Push adds some points to the IM queue. All Pushed points will have the same properties except for // the position. func (imd *IMDraw) Push(pts ...pixel.Vec) { + imd.Color = pixel.ToRGBA(imd.Color) + opts := point{ + col: imd.Color.(pixel.RGBA), + pic: imd.Picture, + in: imd.Intensity, + precision: imd.Precision, + endshape: imd.EndShape, + } for _, pt := range pts { - imd.pushPt(pt, imd.opts) + imd.pushPt(pt, opts) } } @@ -130,33 +145,6 @@ func (imd *IMDraw) pushPt(pos pixel.Vec, pt point) { imd.points = append(imd.points, pt) } -// Color sets the color of the next Pushed points. -func (imd *IMDraw) Color(color color.Color) { - imd.opts.col = pixel.ToRGBA(color) -} - -// Picture sets the Picture coordinates of the next Pushed points. -func (imd *IMDraw) Picture(pic pixel.Vec) { - imd.opts.pic = pic -} - -// Intensity sets the picture Intensity of the next Pushed points. -func (imd *IMDraw) Intensity(in float64) { - imd.opts.in = in -} - -// Precision sets the curve/circle drawing precision of the next Pushed points. -// -// It is the number of segments per 360 degrees. -func (imd *IMDraw) Precision(p int) { - imd.opts.precision = p -} - -// EndShape sets the endshape of the next Pushed points. -func (imd *IMDraw) EndShape(es EndShape) { - imd.opts.endshape = es -} - // SetMatrix sets a Matrix that all further points will be transformed by. func (imd *IMDraw) SetMatrix(m pixel.Matrix) { imd.matrix = m